prpm 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/init.js +17 -40
- package/dist/commands/install.js +30 -11
- package/dist/commands/list.js +28 -18
- package/dist/commands/publish.js +211 -52
- package/dist/commands/search.js +3 -7
- package/dist/commands/uninstall.js +59 -21
- package/dist/core/filesystem.js +2 -2
- package/dist/core/marketplace-converter.js +28 -7
- package/dist/core/registry-client.js +31 -4
- package/dist/types/registry.js +7 -0
- package/dist/types.js +30 -0
- package/dist/utils/license-extractor.js +122 -0
- package/dist/utils/multi-package.js +117 -0
- package/dist/utils/parallel-publisher.js +144 -0
- package/dist/utils/snippet-extractor.js +70 -0
- package/package.json +3 -3
- package/schemas/prpm-manifest.schema.json +30 -0
|
@@ -24,31 +24,69 @@ async function handleUninstall(name) {
|
|
|
24
24
|
// Get destination directory using format and subtype
|
|
25
25
|
const format = pkg.format || 'generic';
|
|
26
26
|
const subtype = pkg.subtype || 'rule';
|
|
27
|
-
const destDir = (0, filesystem_1.getDestinationDir)(format, subtype);
|
|
28
|
-
const fileExtension = pkg.format === 'cursor' ? 'mdc' : 'md';
|
|
29
|
-
// Strip author namespace to get just the package name
|
|
30
27
|
const packageName = (0, filesystem_1.stripAuthorNamespace)(name);
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
const destDir = (0, filesystem_1.getDestinationDir)(format, subtype, packageName);
|
|
29
|
+
const fileExtension = pkg.format === 'cursor' ? 'mdc' : 'md';
|
|
30
|
+
// For Claude skills, check the directory structure first (since they use SKILL.md)
|
|
31
|
+
if (format === 'claude' && subtype === 'skill') {
|
|
32
|
+
// Claude skills are in .claude/skills/${packageName}/ with SKILL.md file
|
|
33
|
+
const skillPath = `${destDir}/SKILL.md`;
|
|
34
|
+
if (await (0, filesystem_1.fileExists)(skillPath)) {
|
|
35
|
+
// Delete the SKILL.md file
|
|
36
|
+
await (0, filesystem_1.deleteFile)(skillPath);
|
|
37
|
+
console.log(` 🗑️ Deleted file: ${skillPath}`);
|
|
38
|
+
// If the directory is empty or only contains SKILL.md, delete the directory too
|
|
39
|
+
try {
|
|
40
|
+
const dirContents = await fs_1.promises.readdir(destDir);
|
|
41
|
+
if (dirContents.length === 0) {
|
|
42
|
+
await fs_1.promises.rmdir(destDir);
|
|
43
|
+
console.log(` 🗑️ Deleted empty directory: ${destDir}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// Directory doesn't exist or can't be deleted, that's okay
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// Try the whole directory
|
|
52
|
+
try {
|
|
53
|
+
const stats = await fs_1.promises.stat(destDir);
|
|
54
|
+
if (stats.isDirectory()) {
|
|
55
|
+
await fs_1.promises.rm(destDir, { recursive: true, force: true });
|
|
56
|
+
console.log(` 🗑️ Deleted directory: ${destDir}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const err = error;
|
|
61
|
+
if (err.code !== 'ENOENT') {
|
|
62
|
+
console.warn(` ⚠️ Could not delete package files: ${err.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
37
66
|
}
|
|
38
67
|
else {
|
|
39
|
-
//
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(` 🗑️ Deleted directory: ${packageDir}`);
|
|
46
|
-
}
|
|
68
|
+
// For other formats, try single file first
|
|
69
|
+
const singleFilePath = `${destDir}/${packageName}.${fileExtension}`;
|
|
70
|
+
if (await (0, filesystem_1.fileExists)(singleFilePath)) {
|
|
71
|
+
// Single file package
|
|
72
|
+
await (0, filesystem_1.deleteFile)(singleFilePath);
|
|
73
|
+
console.log(` 🗑️ Deleted file: ${singleFilePath}`);
|
|
47
74
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
75
|
+
else {
|
|
76
|
+
// Try multi-file package directory
|
|
77
|
+
const packageDir = `${destDir}/${packageName}`;
|
|
78
|
+
try {
|
|
79
|
+
const stats = await fs_1.promises.stat(packageDir);
|
|
80
|
+
if (stats.isDirectory()) {
|
|
81
|
+
await fs_1.promises.rm(packageDir, { recursive: true, force: true });
|
|
82
|
+
console.log(` 🗑️ Deleted directory: ${packageDir}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const err = error;
|
|
87
|
+
if (err.code !== 'ENOENT') {
|
|
88
|
+
console.warn(` ⚠️ Could not delete package files: ${err.message}`);
|
|
89
|
+
}
|
|
52
90
|
}
|
|
53
91
|
}
|
|
54
92
|
}
|
package/dist/core/filesystem.js
CHANGED
|
@@ -18,7 +18,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
18
18
|
/**
|
|
19
19
|
* Get the destination directory for a package based on format and subtype
|
|
20
20
|
*/
|
|
21
|
-
function getDestinationDir(format, subtype) {
|
|
21
|
+
function getDestinationDir(format, subtype, name) {
|
|
22
22
|
switch (format) {
|
|
23
23
|
case 'cursor':
|
|
24
24
|
if (subtype === 'agent')
|
|
@@ -28,7 +28,7 @@ function getDestinationDir(format, subtype) {
|
|
|
28
28
|
return '.cursor/rules';
|
|
29
29
|
case 'claude':
|
|
30
30
|
if (subtype === 'skill')
|
|
31
|
-
return
|
|
31
|
+
return `.claude/skills/${name}`;
|
|
32
32
|
if (subtype === 'slash-command')
|
|
33
33
|
return '.claude/commands';
|
|
34
34
|
if (subtype === 'agent')
|
|
@@ -42,7 +42,8 @@ function marketplaceToManifest(marketplace, pluginIndex = 0) {
|
|
|
42
42
|
}
|
|
43
43
|
// Generate package name from plugin name
|
|
44
44
|
// Format: @owner/plugin-name
|
|
45
|
-
const
|
|
45
|
+
const ownerName = typeof marketplace.owner === 'string' ? marketplace.owner : marketplace.owner.name;
|
|
46
|
+
const packageName = generatePackageName(ownerName, plugin.name);
|
|
46
47
|
// Collect all files that should be included
|
|
47
48
|
const files = collectFiles(plugin);
|
|
48
49
|
// Determine the main file
|
|
@@ -54,13 +55,25 @@ function marketplaceToManifest(marketplace, pluginIndex = 0) {
|
|
|
54
55
|
].slice(0, 20); // Max 20 keywords
|
|
55
56
|
// Extract tags from keywords (first 10)
|
|
56
57
|
const tags = keywords.slice(0, 10);
|
|
58
|
+
// Get description from plugin, metadata, or root
|
|
59
|
+
const description = plugin.description ||
|
|
60
|
+
marketplace.metadata?.description ||
|
|
61
|
+
marketplace.description ||
|
|
62
|
+
'';
|
|
63
|
+
// Get version from plugin, metadata, or root
|
|
64
|
+
const version = plugin.version ||
|
|
65
|
+
marketplace.metadata?.version ||
|
|
66
|
+
marketplace.version ||
|
|
67
|
+
'1.0.0';
|
|
68
|
+
// Get author - prefer plugin.author, fallback to owner name
|
|
69
|
+
const author = plugin.author || ownerName;
|
|
57
70
|
const manifest = {
|
|
58
71
|
name: packageName,
|
|
59
|
-
version
|
|
60
|
-
description
|
|
72
|
+
version,
|
|
73
|
+
description,
|
|
61
74
|
format,
|
|
62
75
|
subtype,
|
|
63
|
-
author
|
|
76
|
+
author,
|
|
64
77
|
files,
|
|
65
78
|
tags,
|
|
66
79
|
keywords,
|
|
@@ -126,7 +139,7 @@ function collectFiles(plugin) {
|
|
|
126
139
|
}
|
|
127
140
|
}
|
|
128
141
|
// Add standard files if they're not already included
|
|
129
|
-
const standardFiles = ['README.md', 'LICENSE', '.claude/marketplace.json'];
|
|
142
|
+
const standardFiles = ['README.md', 'LICENSE', '.claude/marketplace.json', '.claude-plugin/marketplace.json'];
|
|
130
143
|
for (const file of standardFiles) {
|
|
131
144
|
files.add(file);
|
|
132
145
|
}
|
|
@@ -185,10 +198,18 @@ function validateMarketplaceJson(data) {
|
|
|
185
198
|
if (!marketplace.name || typeof marketplace.name !== 'string') {
|
|
186
199
|
return false;
|
|
187
200
|
}
|
|
188
|
-
|
|
201
|
+
// owner can be either string or object with name property
|
|
202
|
+
if (!marketplace.owner) {
|
|
189
203
|
return false;
|
|
190
204
|
}
|
|
191
|
-
if (
|
|
205
|
+
if (typeof marketplace.owner !== 'string' &&
|
|
206
|
+
(typeof marketplace.owner !== 'object' || !marketplace.owner.name)) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
// description can be at root or in metadata
|
|
210
|
+
const hasDescription = (marketplace.description && typeof marketplace.description === 'string') ||
|
|
211
|
+
(marketplace.metadata?.description && typeof marketplace.metadata.description === 'string');
|
|
212
|
+
if (!hasDescription) {
|
|
192
213
|
return false;
|
|
193
214
|
}
|
|
194
215
|
if (!Array.isArray(marketplace.plugins) || marketplace.plugins.length === 0) {
|
|
@@ -115,13 +115,17 @@ class RegistryClient {
|
|
|
115
115
|
/**
|
|
116
116
|
* Publish a package (requires authentication)
|
|
117
117
|
*/
|
|
118
|
-
async publish(manifest, tarball) {
|
|
118
|
+
async publish(manifest, tarball, options) {
|
|
119
119
|
if (!this.token) {
|
|
120
120
|
throw new Error('Authentication required. Run `prpm login` first.');
|
|
121
121
|
}
|
|
122
122
|
const formData = new FormData();
|
|
123
123
|
formData.append('manifest', JSON.stringify(manifest));
|
|
124
124
|
formData.append('tarball', new Blob([tarball]), 'package.tar.gz');
|
|
125
|
+
// Add org_id if provided
|
|
126
|
+
if (options?.orgId) {
|
|
127
|
+
formData.append('org_id', options.orgId);
|
|
128
|
+
}
|
|
125
129
|
const response = await this.fetch('/api/v1/packages', {
|
|
126
130
|
method: 'POST',
|
|
127
131
|
body: formData,
|
|
@@ -205,6 +209,12 @@ class RegistryClient {
|
|
|
205
209
|
*/
|
|
206
210
|
async fetch(path, options = {}, retries = 3) {
|
|
207
211
|
const url = `${this.baseUrl}${path}`;
|
|
212
|
+
// Debug logging
|
|
213
|
+
if (process.env.DEBUG || process.env.PRPM_DEBUG) {
|
|
214
|
+
console.error(`[DEBUG] Fetching: ${url}`);
|
|
215
|
+
console.error(`[DEBUG] Method: ${options.method || 'GET'}`);
|
|
216
|
+
console.error(`[DEBUG] Has token: ${!!this.token}`);
|
|
217
|
+
}
|
|
208
218
|
const headers = {
|
|
209
219
|
'Content-Type': 'application/json',
|
|
210
220
|
...options.headers,
|
|
@@ -215,6 +225,9 @@ class RegistryClient {
|
|
|
215
225
|
let lastError = null;
|
|
216
226
|
for (let attempt = 0; attempt < retries; attempt++) {
|
|
217
227
|
try {
|
|
228
|
+
if (process.env.DEBUG || process.env.PRPM_DEBUG) {
|
|
229
|
+
console.error(`[DEBUG] Attempt ${attempt + 1}/${retries}`);
|
|
230
|
+
}
|
|
218
231
|
const response = await fetch(url, {
|
|
219
232
|
...options,
|
|
220
233
|
headers,
|
|
@@ -242,21 +255,35 @@ class RegistryClient {
|
|
|
242
255
|
}
|
|
243
256
|
catch (error) {
|
|
244
257
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
258
|
+
if (process.env.DEBUG || process.env.PRPM_DEBUG) {
|
|
259
|
+
console.error(`[DEBUG] Error on attempt ${attempt + 1}:`, lastError.message);
|
|
260
|
+
console.error(`[DEBUG] Error type:`, lastError.constructor.name);
|
|
261
|
+
console.error(`[DEBUG] Full error:`, lastError);
|
|
262
|
+
}
|
|
245
263
|
// Network errors - retry with exponential backoff
|
|
246
264
|
if (attempt < retries - 1 && (lastError.message.includes('fetch failed') ||
|
|
247
265
|
lastError.message.includes('ECONNREFUSED') ||
|
|
248
266
|
lastError.message.includes('ETIMEDOUT'))) {
|
|
249
267
|
const waitTime = Math.pow(2, attempt) * 1000;
|
|
268
|
+
if (process.env.DEBUG || process.env.PRPM_DEBUG) {
|
|
269
|
+
console.error(`[DEBUG] Retrying after ${waitTime}ms...`);
|
|
270
|
+
}
|
|
250
271
|
await new Promise(resolve => setTimeout(resolve, waitTime));
|
|
251
272
|
continue;
|
|
252
273
|
}
|
|
253
|
-
// If it's not a retryable error or we're out of retries, throw
|
|
274
|
+
// If it's not a retryable error or we're out of retries, throw with more context
|
|
254
275
|
if (attempt === retries - 1) {
|
|
255
|
-
|
|
276
|
+
const enhancedError = new Error(`Failed to connect to registry at ${url}\n` +
|
|
277
|
+
`Original error: ${lastError.message}\n\n` +
|
|
278
|
+
`💡 Possible causes:\n` +
|
|
279
|
+
` - Registry server is not running\n` +
|
|
280
|
+
` - Network connection issue\n` +
|
|
281
|
+
` - Incorrect PRPM_REGISTRY_URL (currently: ${this.baseUrl})`);
|
|
282
|
+
throw enhancedError;
|
|
256
283
|
}
|
|
257
284
|
}
|
|
258
285
|
}
|
|
259
|
-
throw lastError || new Error(
|
|
286
|
+
throw lastError || new Error(`Request failed after ${retries} retries to ${url}`);
|
|
260
287
|
}
|
|
261
288
|
}
|
|
262
289
|
exports.RegistryClient = RegistryClient;
|
package/dist/types/registry.js
CHANGED
|
@@ -3,3 +3,10 @@
|
|
|
3
3
|
* Registry API types for CLI
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isMultiPackageManifest = isMultiPackageManifest;
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if manifest is multi-package
|
|
9
|
+
*/
|
|
10
|
+
function isMultiPackageManifest(manifest) {
|
|
11
|
+
return 'packages' in manifest && Array.isArray(manifest.packages);
|
|
12
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -3,3 +3,33 @@
|
|
|
3
3
|
* Core types for the Prompt Package Manager
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SUBTYPES = exports.FORMATS = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Available formats as a constant array
|
|
9
|
+
* Useful for CLI prompts, validation, etc.
|
|
10
|
+
*/
|
|
11
|
+
exports.FORMATS = [
|
|
12
|
+
'cursor',
|
|
13
|
+
'claude',
|
|
14
|
+
'continue',
|
|
15
|
+
'windsurf',
|
|
16
|
+
'copilot',
|
|
17
|
+
'kiro',
|
|
18
|
+
'agents.md',
|
|
19
|
+
'generic',
|
|
20
|
+
'mcp',
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Available subtypes as a constant array
|
|
24
|
+
* Useful for CLI prompts, validation, etc.
|
|
25
|
+
*/
|
|
26
|
+
exports.SUBTYPES = [
|
|
27
|
+
'rule',
|
|
28
|
+
'agent',
|
|
29
|
+
'skill',
|
|
30
|
+
'slash-command',
|
|
31
|
+
'prompt',
|
|
32
|
+
'collection',
|
|
33
|
+
'chatmode',
|
|
34
|
+
'tool',
|
|
35
|
+
];
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* License extraction utilities
|
|
4
|
+
* Extracts license information from LICENSE files for proper attribution
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.extractLicenseInfo = extractLicenseInfo;
|
|
8
|
+
exports.validateLicenseInfo = validateLicenseInfo;
|
|
9
|
+
const promises_1 = require("fs/promises");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
/**
|
|
13
|
+
* Common license file names to search for
|
|
14
|
+
*/
|
|
15
|
+
const LICENSE_FILE_PATTERNS = [
|
|
16
|
+
'LICENSE',
|
|
17
|
+
'LICENSE.md',
|
|
18
|
+
'LICENSE.txt',
|
|
19
|
+
'LICENCE',
|
|
20
|
+
'LICENCE.md',
|
|
21
|
+
'LICENCE.txt',
|
|
22
|
+
'LICENSE-MIT',
|
|
23
|
+
'LICENSE-APACHE',
|
|
24
|
+
'COPYING',
|
|
25
|
+
'COPYING.txt',
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* License type detection patterns
|
|
29
|
+
* Ordered by specificity - more specific patterns first
|
|
30
|
+
*/
|
|
31
|
+
const LICENSE_PATTERNS = [
|
|
32
|
+
{ pattern: /MIT License/i, type: 'MIT' },
|
|
33
|
+
{ pattern: /Apache License[\s\S]*Version 2\.0/i, type: 'Apache-2.0' },
|
|
34
|
+
{ pattern: /GNU GENERAL PUBLIC LICENSE[\s\S]*Version 3/i, type: 'GPL-3.0' },
|
|
35
|
+
{ pattern: /GNU GENERAL PUBLIC LICENSE[\s\S]*Version 2/i, type: 'GPL-2.0' },
|
|
36
|
+
{ pattern: /GNU LESSER GENERAL PUBLIC LICENSE[\s\S]*Version 3/i, type: 'LGPL-3.0' },
|
|
37
|
+
{ pattern: /GNU LESSER GENERAL PUBLIC LICENSE[\s\S]*Version 2/i, type: 'LGPL-2.1' },
|
|
38
|
+
{ pattern: /BSD 3-Clause License/i, type: 'BSD-3-Clause' },
|
|
39
|
+
{ pattern: /BSD 2-Clause License/i, type: 'BSD-2-Clause' },
|
|
40
|
+
{ pattern: /Mozilla Public License[\s\S]*Version 2\.0/i, type: 'MPL-2.0' },
|
|
41
|
+
{ pattern: /ISC License/i, type: 'ISC' },
|
|
42
|
+
{ pattern: /The Unlicense/i, type: 'Unlicense' },
|
|
43
|
+
{ pattern: /Creative Commons Zero[\s\S]*1\.0/i, type: 'CC0-1.0' },
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Detect license type from license text
|
|
47
|
+
*/
|
|
48
|
+
function detectLicenseType(text) {
|
|
49
|
+
for (const { pattern, type } of LICENSE_PATTERNS) {
|
|
50
|
+
if (pattern.test(text)) {
|
|
51
|
+
return type;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generate GitHub raw URL for license file
|
|
58
|
+
*/
|
|
59
|
+
function generateLicenseUrl(repositoryUrl, fileName) {
|
|
60
|
+
if (!repositoryUrl) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
// Extract owner/repo from GitHub URL
|
|
64
|
+
const githubMatch = repositoryUrl.match(/github\.com[/:]([\w-]+)\/([\w-]+)/);
|
|
65
|
+
if (!githubMatch) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const [, owner, repo] = githubMatch;
|
|
69
|
+
// Use raw.githubusercontent.com for direct file access
|
|
70
|
+
return `https://raw.githubusercontent.com/${owner}/${repo}/main/${fileName}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Find and extract license information from the current directory
|
|
74
|
+
*/
|
|
75
|
+
async function extractLicenseInfo(repositoryUrl) {
|
|
76
|
+
const cwd = process.cwd();
|
|
77
|
+
// Try each license file pattern
|
|
78
|
+
for (const fileName of LICENSE_FILE_PATTERNS) {
|
|
79
|
+
const filePath = (0, path_1.join)(cwd, fileName);
|
|
80
|
+
try {
|
|
81
|
+
// Check if file exists
|
|
82
|
+
await (0, promises_1.access)(filePath, fs_1.constants.R_OK);
|
|
83
|
+
// Read license file
|
|
84
|
+
const text = await (0, promises_1.readFile)(filePath, 'utf-8');
|
|
85
|
+
// Detect license type
|
|
86
|
+
const type = detectLicenseType(text);
|
|
87
|
+
// Generate license URL if repository is provided
|
|
88
|
+
const url = generateLicenseUrl(repositoryUrl, fileName);
|
|
89
|
+
return {
|
|
90
|
+
type,
|
|
91
|
+
text,
|
|
92
|
+
url,
|
|
93
|
+
fileName,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// File doesn't exist or can't be read, try next pattern
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// No license file found
|
|
102
|
+
return {
|
|
103
|
+
type: null,
|
|
104
|
+
text: null,
|
|
105
|
+
url: null,
|
|
106
|
+
fileName: null,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Display license information if found
|
|
111
|
+
*/
|
|
112
|
+
function validateLicenseInfo(licenseInfo, packageName) {
|
|
113
|
+
if (licenseInfo.text && licenseInfo.type) {
|
|
114
|
+
console.log(` License: ${licenseInfo.type} (${licenseInfo.fileName})`);
|
|
115
|
+
}
|
|
116
|
+
else if (licenseInfo.text && !licenseInfo.type) {
|
|
117
|
+
console.log(` License: Found (${licenseInfo.fileName})`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.log(` License: Not found (package will be published without license)`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Multi-package manifest utilities
|
|
4
|
+
* Handles merging root-level fields with package-level fields
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.mergePackageFields = mergePackageFields;
|
|
8
|
+
exports.getPackagesWithInheritance = getPackagesWithInheritance;
|
|
9
|
+
exports.validateMultiPackageManifest = validateMultiPackageManifest;
|
|
10
|
+
exports.filterPackages = filterPackages;
|
|
11
|
+
/**
|
|
12
|
+
* Fields that can be inherited from root to packages
|
|
13
|
+
*/
|
|
14
|
+
const INHERITABLE_FIELDS = [
|
|
15
|
+
'author',
|
|
16
|
+
'license',
|
|
17
|
+
'repository',
|
|
18
|
+
'homepage',
|
|
19
|
+
'documentation',
|
|
20
|
+
'organization',
|
|
21
|
+
'keywords',
|
|
22
|
+
'tags',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Merge root-level fields into a package manifest
|
|
26
|
+
* Package-level fields take precedence over root-level fields
|
|
27
|
+
*/
|
|
28
|
+
function mergePackageFields(root, pkg) {
|
|
29
|
+
const merged = { ...pkg };
|
|
30
|
+
// Inherit each inheritable field if not defined in package
|
|
31
|
+
for (const field of INHERITABLE_FIELDS) {
|
|
32
|
+
if (merged[field] === undefined && root[field] !== undefined) {
|
|
33
|
+
// @ts-ignore - dynamic field access
|
|
34
|
+
merged[field] = root[field];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return merged;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all packages from a multi-package manifest with inherited fields
|
|
41
|
+
*/
|
|
42
|
+
function getPackagesWithInheritance(manifest) {
|
|
43
|
+
return manifest.packages.map(pkg => mergePackageFields(manifest, pkg));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validate multi-package manifest
|
|
47
|
+
*/
|
|
48
|
+
function validateMultiPackageManifest(manifest) {
|
|
49
|
+
const errors = [];
|
|
50
|
+
// Check packages array exists and is not empty
|
|
51
|
+
if (!manifest.packages || !Array.isArray(manifest.packages)) {
|
|
52
|
+
errors.push('packages field must be an array');
|
|
53
|
+
return { valid: false, errors };
|
|
54
|
+
}
|
|
55
|
+
if (manifest.packages.length === 0) {
|
|
56
|
+
errors.push('packages array must contain at least one package');
|
|
57
|
+
return { valid: false, errors };
|
|
58
|
+
}
|
|
59
|
+
// Check for duplicate package names
|
|
60
|
+
const names = new Set();
|
|
61
|
+
for (let i = 0; i < manifest.packages.length; i++) {
|
|
62
|
+
const pkg = manifest.packages[i];
|
|
63
|
+
if (names.has(pkg.name)) {
|
|
64
|
+
errors.push(`Duplicate package name: ${pkg.name}`);
|
|
65
|
+
}
|
|
66
|
+
names.add(pkg.name);
|
|
67
|
+
}
|
|
68
|
+
// Validate each package has required fields
|
|
69
|
+
for (let i = 0; i < manifest.packages.length; i++) {
|
|
70
|
+
const pkg = manifest.packages[i];
|
|
71
|
+
const pkgPrefix = `Package ${i} (${pkg.name || 'unnamed'})`;
|
|
72
|
+
if (!pkg.name) {
|
|
73
|
+
errors.push(`${pkgPrefix}: missing required field 'name'`);
|
|
74
|
+
}
|
|
75
|
+
if (!pkg.version) {
|
|
76
|
+
errors.push(`${pkgPrefix}: missing required field 'version'`);
|
|
77
|
+
}
|
|
78
|
+
if (!pkg.description) {
|
|
79
|
+
errors.push(`${pkgPrefix}: missing required field 'description'`);
|
|
80
|
+
}
|
|
81
|
+
if (!pkg.format) {
|
|
82
|
+
errors.push(`${pkgPrefix}: missing required field 'format'`);
|
|
83
|
+
}
|
|
84
|
+
if (!pkg.files || pkg.files.length === 0) {
|
|
85
|
+
errors.push(`${pkgPrefix}: must have at least one file in 'files' array`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
valid: errors.length === 0,
|
|
90
|
+
errors,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Filter packages by name or pattern
|
|
95
|
+
*/
|
|
96
|
+
function filterPackages(packages, filter) {
|
|
97
|
+
// If filter is a number, treat as index
|
|
98
|
+
if (typeof filter === 'number') {
|
|
99
|
+
if (filter < 0 || filter >= packages.length) {
|
|
100
|
+
throw new Error(`Package index ${filter} out of range (0-${packages.length - 1})`);
|
|
101
|
+
}
|
|
102
|
+
return [packages[filter]];
|
|
103
|
+
}
|
|
104
|
+
// If exact match, return that package
|
|
105
|
+
const exactMatch = packages.find(pkg => pkg.name === filter);
|
|
106
|
+
if (exactMatch) {
|
|
107
|
+
return [exactMatch];
|
|
108
|
+
}
|
|
109
|
+
// Try as glob pattern
|
|
110
|
+
const pattern = filter.replace(/\*/g, '.*');
|
|
111
|
+
const regex = new RegExp(`^${pattern}$`);
|
|
112
|
+
const matches = packages.filter(pkg => regex.test(pkg.name));
|
|
113
|
+
if (matches.length === 0) {
|
|
114
|
+
throw new Error(`No packages match filter: ${filter}`);
|
|
115
|
+
}
|
|
116
|
+
return matches;
|
|
117
|
+
}
|