npmdata 0.10.3 → 0.12.0
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/README.md +133 -58
- package/dist/cli/actions/check.d.ts +6 -0
- package/dist/cli/actions/check.d.ts.map +1 -0
- package/dist/cli/actions/check.js +57 -0
- package/dist/cli/actions/check.js.map +1 -0
- package/dist/cli/actions/extract.d.ts +7 -0
- package/dist/cli/actions/extract.d.ts.map +1 -0
- package/dist/cli/actions/extract.js +84 -0
- package/dist/cli/actions/extract.js.map +1 -0
- package/dist/cli/actions/init.d.ts +6 -0
- package/dist/cli/actions/init.d.ts.map +1 -0
- package/dist/cli/actions/init.js +36 -0
- package/dist/cli/actions/init.js.map +1 -0
- package/dist/cli/actions/list.d.ts +7 -0
- package/dist/cli/actions/list.d.ts.map +1 -0
- package/dist/cli/actions/list.js +42 -0
- package/dist/cli/actions/list.js.map +1 -0
- package/dist/cli/actions/purge.d.ts +6 -0
- package/dist/cli/actions/purge.d.ts.map +1 -0
- package/dist/cli/actions/purge.js +47 -0
- package/dist/cli/actions/purge.js.map +1 -0
- package/dist/cli/argv.d.ts +35 -0
- package/dist/cli/argv.d.ts.map +1 -0
- package/dist/cli/argv.js +125 -0
- package/dist/cli/argv.js.map +1 -0
- package/dist/cli/cli.d.ts +9 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +69 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/runner.d.ts +9 -0
- package/dist/cli/runner.d.ts.map +1 -0
- package/dist/cli/runner.js +106 -0
- package/dist/cli/runner.js.map +1 -0
- package/dist/cli/usage.d.ts +6 -0
- package/dist/cli/usage.d.ts.map +1 -0
- package/dist/cli/usage.js +126 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/fileset/check.d.ts +15 -0
- package/dist/fileset/check.d.ts.map +1 -0
- package/dist/fileset/check.js +68 -0
- package/dist/fileset/check.js.map +1 -0
- package/dist/fileset/constants.d.ts +13 -0
- package/dist/fileset/constants.d.ts.map +1 -0
- package/dist/fileset/constants.js +22 -0
- package/dist/fileset/constants.js.map +1 -0
- package/dist/fileset/diff.d.ts +16 -0
- package/dist/fileset/diff.d.ts.map +1 -0
- package/dist/fileset/diff.js +116 -0
- package/dist/fileset/diff.js.map +1 -0
- package/dist/fileset/execute.d.ts +29 -0
- package/dist/fileset/execute.d.ts.map +1 -0
- package/dist/fileset/execute.js +136 -0
- package/dist/fileset/execute.js.map +1 -0
- package/dist/fileset/gitignore.d.ts +16 -0
- package/dist/fileset/gitignore.d.ts.map +1 -0
- package/dist/fileset/gitignore.js +82 -0
- package/dist/fileset/gitignore.js.map +1 -0
- package/dist/fileset/index.d.ts +5 -0
- package/dist/fileset/index.d.ts.map +1 -0
- package/dist/fileset/index.js +21 -0
- package/dist/fileset/index.js.map +1 -0
- package/dist/fileset/list.d.ts +6 -0
- package/dist/fileset/list.d.ts.map +1 -0
- package/dist/fileset/list.js +11 -0
- package/dist/fileset/list.js.map +1 -0
- package/dist/fileset/markers.d.ts +22 -0
- package/dist/fileset/markers.d.ts.map +1 -0
- package/dist/fileset/markers.js +68 -0
- package/dist/fileset/markers.js.map +1 -0
- package/dist/fileset/package-files.d.ts +14 -0
- package/dist/fileset/package-files.d.ts.map +1 -0
- package/dist/fileset/package-files.js +81 -0
- package/dist/fileset/package-files.js.map +1 -0
- package/dist/fileset/purge.d.ts +12 -0
- package/dist/fileset/purge.d.ts.map +1 -0
- package/dist/fileset/purge.js +95 -0
- package/dist/fileset/purge.js.map +1 -0
- package/dist/fileset/test-utils.d.ts +12 -0
- package/dist/fileset/test-utils.d.ts.map +1 -0
- package/dist/fileset/test-utils.js +65 -0
- package/dist/fileset/test-utils.js.map +1 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -17
- package/dist/index.js.map +1 -1
- package/dist/main.js +9 -16
- package/dist/main.js.map +1 -1
- package/dist/npmdata-0.0.1.tgz +0 -0
- package/dist/package/action-check.d.ts +20 -0
- package/dist/package/action-check.d.ts.map +1 -0
- package/dist/package/action-check.js +61 -0
- package/dist/package/action-check.js.map +1 -0
- package/dist/package/action-extract.d.ts +21 -0
- package/dist/package/action-extract.d.ts.map +1 -0
- package/dist/package/action-extract.js +186 -0
- package/dist/package/action-extract.js.map +1 -0
- package/dist/package/action-init.d.ts +13 -0
- package/dist/package/action-init.d.ts.map +1 -0
- package/dist/package/action-init.js +77 -0
- package/dist/package/action-init.js.map +1 -0
- package/dist/package/action-list.d.ts +14 -0
- package/dist/package/action-list.d.ts.map +1 -0
- package/dist/package/action-list.js +46 -0
- package/dist/package/action-list.js.map +1 -0
- package/dist/package/action-purge.d.ts +21 -0
- package/dist/package/action-purge.d.ts.map +1 -0
- package/dist/package/action-purge.js +60 -0
- package/dist/package/action-purge.js.map +1 -0
- package/dist/package/config-merge.d.ts +18 -0
- package/dist/package/config-merge.d.ts.map +1 -0
- package/dist/package/config-merge.js +48 -0
- package/dist/package/config-merge.js.map +1 -0
- package/dist/package/config.d.ts +13 -0
- package/dist/package/config.d.ts.map +1 -0
- package/dist/package/config.js +29 -0
- package/dist/package/config.js.map +1 -0
- package/dist/package/content-replacements.d.ts +21 -0
- package/dist/package/content-replacements.d.ts.map +1 -0
- package/dist/package/content-replacements.js +96 -0
- package/dist/package/content-replacements.js.map +1 -0
- package/dist/package/index.d.ts +10 -0
- package/dist/package/index.d.ts.map +1 -0
- package/dist/package/index.js +16 -0
- package/dist/package/index.js.map +1 -0
- package/dist/package/symlinks.d.ts +17 -0
- package/dist/package/symlinks.d.ts.map +1 -0
- package/dist/package/symlinks.js +125 -0
- package/dist/package/symlinks.js.map +1 -0
- package/dist/types.d.ts +184 -270
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -12
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +25 -55
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +82 -181
- package/dist/utils.js.map +1 -1
- package/package.json +5 -2
- package/dist/cli.d.ts +0 -6
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -514
- package/dist/cli.js.map +0 -1
- package/dist/consumer.d.ts +0 -74
- package/dist/consumer.d.ts.map +0 -1
- package/dist/consumer.js +0 -820
- package/dist/consumer.js.map +0 -1
- package/dist/publisher.d.ts +0 -38
- package/dist/publisher.d.ts.map +0 -1
- package/dist/publisher.js +0 -164
- package/dist/publisher.js.map +0 -1
- package/dist/runner.d.ts +0 -102
- package/dist/runner.d.ts.map +0 -1
- package/dist/runner.js +0 -748
- package/dist/runner.js.map +0 -1
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAQ5D;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQhE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE3D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAUtD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAgBjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAuBR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI3C;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,mBAAmB,EAAE,EAC9B,OAAO,EAAE,MAAM,EAAE,GAChB,mBAAmB,EAAE,CAOvB"}
|
package/dist/utils.js
CHANGED
|
@@ -3,30 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.matchesFilenamePattern = void 0;
|
|
7
6
|
exports.parsePackageSpec = parsePackageSpec;
|
|
8
|
-
exports.
|
|
7
|
+
exports.hashFile = hashFile;
|
|
8
|
+
exports.hashBuffer = hashBuffer;
|
|
9
|
+
exports.hashFileSync = hashFileSync;
|
|
9
10
|
exports.isBinaryFile = isBinaryFile;
|
|
10
|
-
exports.calculateFileHash = calculateFileHash;
|
|
11
|
-
exports.calculateBufferHash = calculateBufferHash;
|
|
12
|
-
exports.matchesContentRegex = matchesContentRegex;
|
|
13
|
-
exports.findMatchingFiles = findMatchingFiles;
|
|
14
|
-
exports.ensureDir = ensureDir;
|
|
15
|
-
exports.removeFile = removeFile;
|
|
16
|
-
exports.copyFile = copyFile;
|
|
17
11
|
exports.detectPackageManager = detectPackageManager;
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
|
|
12
|
+
exports.installPackage = installPackage;
|
|
13
|
+
exports.getInstalledPackagePath = getInstalledPackagePath;
|
|
14
|
+
exports.ensureDir = ensureDir;
|
|
15
|
+
exports.filterEntriesByPresets = filterEntriesByPresets;
|
|
16
|
+
/* eslint-disable functional/no-try-statements */
|
|
23
17
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
24
18
|
const node_path_1 = __importDefault(require("node:path"));
|
|
25
19
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
26
|
-
const
|
|
20
|
+
const node_child_process_1 = require("node:child_process");
|
|
27
21
|
/**
|
|
28
22
|
* Parse a package spec like "my-pkg@^1.2.3" or "@scope/pkg@2.x" into name and version.
|
|
29
|
-
* The version separator is the LAST "@" so that scoped packages ("@scope/name") are handled
|
|
23
|
+
* The version separator is the LAST "@" so that scoped packages ("@scope/name") are handled.
|
|
30
24
|
*/
|
|
31
25
|
function parsePackageSpec(spec) {
|
|
32
26
|
const atIdx = spec.lastIndexOf('@');
|
|
@@ -38,19 +32,36 @@ function parsePackageSpec(spec) {
|
|
|
38
32
|
return { name: spec, version: undefined };
|
|
39
33
|
}
|
|
40
34
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
35
|
+
* Compute the SHA-256 hash of a file.
|
|
36
|
+
*/
|
|
37
|
+
async function hashFile(filePath) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const hash = node_crypto_1.default.createHash('sha256');
|
|
40
|
+
const stream = node_fs_1.default.createReadStream(filePath);
|
|
41
|
+
stream.on('data', (data) => hash.update(data));
|
|
42
|
+
stream.on('end', () => resolve(hash.digest('hex')));
|
|
43
|
+
stream.on('error', reject);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Compute the SHA-256 hash of an in-memory buffer or string.
|
|
48
|
+
* Used to hash content that has been transformed in memory before comparison.
|
|
49
|
+
*/
|
|
50
|
+
function hashBuffer(content) {
|
|
51
|
+
return node_crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Synchronous file hash (SHA-256).
|
|
43
55
|
*/
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
return
|
|
56
|
+
function hashFileSync(filePath) {
|
|
57
|
+
const content = node_fs_1.default.readFileSync(filePath);
|
|
58
|
+
return node_crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
47
59
|
}
|
|
48
60
|
/**
|
|
49
61
|
* Detect whether a file is binary by scanning it for null bytes.
|
|
50
|
-
* Reads up to the first 8 KB only
|
|
62
|
+
* Reads up to the first 8 KB only.
|
|
51
63
|
*/
|
|
52
64
|
function isBinaryFile(filePath) {
|
|
53
|
-
// eslint-disable-next-line functional/no-try-statements
|
|
54
65
|
try {
|
|
55
66
|
const fd = node_fs_1.default.openSync(filePath, 'r');
|
|
56
67
|
const buf = Buffer.alloc(8192);
|
|
@@ -63,195 +74,85 @@ function isBinaryFile(filePath) {
|
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
function calculateFileHash(filePath) {
|
|
69
|
-
const content = node_fs_1.default.readFileSync(filePath);
|
|
70
|
-
return node_crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Compute the SHA-256 hash of an in-memory buffer or string.
|
|
74
|
-
* Used to hash content that has been transformed in memory before writing to disk.
|
|
75
|
-
*/
|
|
76
|
-
function calculateBufferHash(content) {
|
|
77
|
-
return node_crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Check if file contents match regex patterns.
|
|
81
|
-
* Binary files (detected via null-byte scan) are always excluded when patterns are set.
|
|
82
|
-
*/
|
|
83
|
-
function matchesContentRegex(filePath, patterns) {
|
|
84
|
-
if (!patterns)
|
|
85
|
-
return true;
|
|
86
|
-
if (isBinaryFile(filePath))
|
|
87
|
-
return false;
|
|
88
|
-
const content = node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
89
|
-
return patterns.some((pattern) => pattern.test(content));
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Recursively find all files in directory matching filters
|
|
93
|
-
*/
|
|
94
|
-
function findMatchingFiles(dir, filenamePatterns, contentRegexes) {
|
|
95
|
-
const results = [];
|
|
96
|
-
function walkDir(currentDir) {
|
|
97
|
-
const files = node_fs_1.default.readdirSync(currentDir);
|
|
98
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
99
|
-
for (const file of files) {
|
|
100
|
-
const fullPath = node_path_1.default.join(currentDir, file);
|
|
101
|
-
const stat = node_fs_1.default.statSync(fullPath);
|
|
102
|
-
if (stat.isDirectory()) {
|
|
103
|
-
walkDir(fullPath);
|
|
104
|
-
// eslint-disable-next-line no-continue
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (
|
|
108
|
-
// Check if file matches include patterns and does not match exclude patterns, and matches content regex
|
|
109
|
-
(0, exports.matchesFilenamePattern)(fullPath, filenamePatterns) &&
|
|
110
|
-
matchesContentRegex(fullPath, contentRegexes)) {
|
|
111
|
-
// eslint-disable-next-line functional/immutable-data
|
|
112
|
-
results.push(fullPath);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
walkDir(dir);
|
|
117
|
-
return results;
|
|
118
|
-
}
|
|
119
|
-
const matchesFilenamePattern = (filename, patterns) => {
|
|
120
|
-
if (!patterns)
|
|
121
|
-
return true;
|
|
122
|
-
// Separate include and exclude patterns (exclude patterns start with '!')
|
|
123
|
-
const includes = patterns.filter((p) => !p.startsWith('!'));
|
|
124
|
-
const excludes = patterns.filter((p) => p.startsWith('!')).map((p) => p.slice(1));
|
|
125
|
-
// When there are no positive include patterns, treat as "match all" (same as undefined).
|
|
126
|
-
// This avoids the footgun where an empty array silently excludes every file.
|
|
127
|
-
const matchesIncludes = includes.length === 0 || includes.some((pattern) => (0, minimatch_1.minimatch)(filename, pattern));
|
|
128
|
-
return matchesIncludes && !excludes.some((pattern) => (0, minimatch_1.minimatch)(filename, pattern));
|
|
129
|
-
};
|
|
130
|
-
exports.matchesFilenamePattern = matchesFilenamePattern;
|
|
131
|
-
/**
|
|
132
|
-
* Create directory recursively
|
|
133
|
-
*/
|
|
134
|
-
function ensureDir(dir) {
|
|
135
|
-
if (!node_fs_1.default.existsSync(dir)) {
|
|
136
|
-
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Remove file with error handling
|
|
141
|
-
*/
|
|
142
|
-
function removeFile(filePath) {
|
|
143
|
-
node_fs_1.default.chmodSync(filePath, 0o644); // Make writable before deleting
|
|
144
|
-
node_fs_1.default.unlinkSync(filePath);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Copy file preserving directory structure
|
|
148
|
-
*/
|
|
149
|
-
function copyFile(src, dest) {
|
|
150
|
-
ensureDir(node_path_1.default.dirname(dest));
|
|
151
|
-
// Make destination writable if it exists (e.g., from previous extraction)
|
|
152
|
-
if (node_fs_1.default.existsSync(dest)) {
|
|
153
|
-
node_fs_1.default.chmodSync(dest, 0o644);
|
|
154
|
-
}
|
|
155
|
-
node_fs_1.default.copyFileSync(src, dest);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Detect package manager type.
|
|
159
|
-
* Inspects the lock files in the given directory (defaults to process.cwd()).
|
|
77
|
+
* Detect package manager by inspecting lock files in the given directory.
|
|
78
|
+
* Falls back to npm if no lock file is found.
|
|
160
79
|
*/
|
|
161
80
|
function detectPackageManager(cwd) {
|
|
162
|
-
const dir = cwd ??
|
|
163
|
-
// eslint-disable-next-line functional/no-try-statements
|
|
81
|
+
const dir = cwd ?? process.cwd();
|
|
164
82
|
try {
|
|
165
83
|
const lockFiles = node_fs_1.default.readdirSync(dir);
|
|
166
84
|
if (lockFiles.includes('pnpm-lock.yaml'))
|
|
167
85
|
return 'pnpm';
|
|
168
|
-
if (lockFiles.includes('yarn.lock'))
|
|
169
|
-
return 'yarn';
|
|
170
86
|
if (lockFiles.includes('package-lock.json'))
|
|
171
87
|
return 'npm';
|
|
172
88
|
}
|
|
173
89
|
catch {
|
|
174
|
-
//
|
|
90
|
+
// fall through
|
|
175
91
|
}
|
|
176
92
|
// Check npm_config_user_agent environment variable
|
|
177
93
|
// eslint-disable-next-line no-process-env
|
|
178
|
-
const userAgent = process.env.npm_config_user_agent
|
|
179
|
-
if (userAgent.includes('yarn'))
|
|
180
|
-
return 'yarn';
|
|
94
|
+
const userAgent = process.env.npm_config_user_agent ?? '';
|
|
181
95
|
if (userAgent.includes('pnpm'))
|
|
182
96
|
return 'pnpm';
|
|
183
|
-
return 'npm';
|
|
97
|
+
return 'npm';
|
|
184
98
|
}
|
|
185
99
|
/**
|
|
186
|
-
*
|
|
100
|
+
* Install a package using the detected package manager.
|
|
101
|
+
* Returns the installed package path under node_modules.
|
|
187
102
|
*/
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
103
|
+
function installPackage(name, version, upgrade, cwd) {
|
|
104
|
+
const workDir = cwd ?? process.cwd();
|
|
105
|
+
const pm = detectPackageManager(workDir);
|
|
106
|
+
const spec = version ? `${name}@${version}` : `${name}@latest`;
|
|
107
|
+
// Check if already installed with a satisfying version (skip install if not upgrading)
|
|
108
|
+
if (!upgrade) {
|
|
109
|
+
const installedPath = node_path_1.default.join(workDir, 'node_modules', name, 'package.json');
|
|
110
|
+
if (node_fs_1.default.existsSync(installedPath)) {
|
|
111
|
+
return node_path_1.default.dirname(installedPath);
|
|
195
112
|
}
|
|
196
|
-
const pkgPath = require.resolve(`${packageName}/package.json`);
|
|
197
|
-
const pkg = JSON.parse(node_fs_1.default.readFileSync(pkgPath).toString());
|
|
198
|
-
return pkg.version;
|
|
199
113
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
114
|
+
const cmd = pm === 'pnpm' ? `pnpm add ${spec}` : `npm install ${spec}`;
|
|
115
|
+
try {
|
|
116
|
+
(0, node_child_process_1.execSync)(cmd, { cwd: workDir, stdio: 'pipe', encoding: 'utf8' });
|
|
203
117
|
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
const e = error;
|
|
120
|
+
const detail = (e.stderr ?? e.stdout ?? e.message ?? String(error)).trim();
|
|
121
|
+
throw new Error(`Failed to install ${spec}: ${detail}`);
|
|
122
|
+
}
|
|
123
|
+
return node_path_1.default.join(workDir, 'node_modules', name);
|
|
204
124
|
}
|
|
205
125
|
/**
|
|
206
|
-
*
|
|
207
|
-
*/
|
|
208
|
-
function readJsonFile(filePath) {
|
|
209
|
-
const content = node_fs_1.default.readFileSync(filePath).toString();
|
|
210
|
-
return JSON.parse(content);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Write JSON file
|
|
126
|
+
* Return the installed package path under cwd/node_modules, or null if not installed.
|
|
214
127
|
*/
|
|
215
|
-
function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (node_fs_1.default.existsSync(
|
|
219
|
-
|
|
128
|
+
function getInstalledPackagePath(name, cwd) {
|
|
129
|
+
const workDir = cwd ?? process.cwd();
|
|
130
|
+
const pkgJsonPath = node_path_1.default.join(workDir, 'node_modules', name, 'package.json');
|
|
131
|
+
if (node_fs_1.default.existsSync(pkgJsonPath)) {
|
|
132
|
+
return node_path_1.default.dirname(pkgJsonPath);
|
|
220
133
|
}
|
|
221
134
|
// eslint-disable-next-line unicorn/no-null
|
|
222
|
-
|
|
135
|
+
return null;
|
|
223
136
|
}
|
|
224
|
-
const MARKER_DELIMITER = '|';
|
|
225
137
|
/**
|
|
226
|
-
*
|
|
227
|
-
* Supports both the current pipe-delimited format and the legacy comma-delimited format
|
|
228
|
-
* (detected automatically for backward compatibility).
|
|
138
|
+
* Ensure a directory exists, creating it recursively if needed.
|
|
229
139
|
*/
|
|
230
|
-
function
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
// Detect format: new records use '|'; legacy records use ','
|
|
235
|
-
const delimiter = line.includes(MARKER_DELIMITER) ? MARKER_DELIMITER : ',';
|
|
236
|
-
const fields = line.split(delimiter);
|
|
237
|
-
return {
|
|
238
|
-
path: fields[0],
|
|
239
|
-
packageName: fields[1],
|
|
240
|
-
packageVersion: fields[2],
|
|
241
|
-
force: fields[3] === '1',
|
|
242
|
-
};
|
|
243
|
-
});
|
|
140
|
+
function ensureDir(dir) {
|
|
141
|
+
if (!node_fs_1.default.existsSync(dir)) {
|
|
142
|
+
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
143
|
+
}
|
|
244
144
|
}
|
|
245
145
|
/**
|
|
246
|
-
*
|
|
146
|
+
* Filter entries by requested presets.
|
|
147
|
+
* When no presets are requested, all entries pass through.
|
|
247
148
|
*/
|
|
248
|
-
function
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
149
|
+
function filterEntriesByPresets(entries, presets) {
|
|
150
|
+
if (presets.length === 0)
|
|
151
|
+
return entries;
|
|
152
|
+
return entries.filter((entry) => {
|
|
153
|
+
// Support presets at the entry level (config-file convention) or inside selector (CLI convention)
|
|
154
|
+
const entryPresets = new Set([...(entry.presets ?? []), ...(entry.selector?.presets ?? [])]);
|
|
155
|
+
return presets.some((p) => entryPresets.has(p));
|
|
156
|
+
});
|
|
256
157
|
}
|
|
257
158
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;AAYA,4CAQC;AAKD,4BAQC;AAMD,gCAEC;AAKD,oCAGC;AAMD,oCAUC;AAMD,oD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IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7F,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npmdata",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "dist/main.js",
|
|
@@ -39,14 +39,17 @@
|
|
|
39
39
|
"typescript": "^5.5.4"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"cosmiconfig": "^9.0.1",
|
|
42
43
|
"ignore": "^7.0.5",
|
|
43
44
|
"minimatch": "^10.2.2",
|
|
45
|
+
"mypkg": "^1.0.0",
|
|
44
46
|
"semver": "^7.7.4"
|
|
45
47
|
},
|
|
46
48
|
"pnpm": {
|
|
47
49
|
"overrides": {
|
|
48
50
|
"braces@<3.0.3": ">=3.0.3",
|
|
49
|
-
"rollup@<3.29.5": ">=3.29.5"
|
|
51
|
+
"rollup@<3.29.5": ">=3.29.5",
|
|
52
|
+
"eslint-plugin-import>minimatch": "^3.1.2"
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
}
|
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAaA;;GAEG;AAEH,wBAAsB,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA+chE"}
|