@bobfrankston/npmglobalize 1.0.156 → 1.0.157
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/lib.d.ts +3 -3
- package/lib.js +32 -3
- package/package.json +1 -1
package/lib.d.ts
CHANGED
|
@@ -244,9 +244,9 @@ export declare function compareVersions(a: number[], b: number[]): number;
|
|
|
244
244
|
/** Fix version/tag mismatches */
|
|
245
245
|
export declare function fixVersionTagMismatch(cwd: string, pkg: any, verbose?: boolean): boolean;
|
|
246
246
|
/** Walk `file:` deps transitively and run `npm install` in any target whose
|
|
247
|
-
* package.json declares deps but has no `node_modules/`.
|
|
248
|
-
*
|
|
249
|
-
* upcoming build/pack
|
|
247
|
+
* package.json declares deps but has no `node_modules/`. Also covers `cwd`
|
|
248
|
+
* itself on the first call, so a fresh clone with no `node_modules/` gets
|
|
249
|
+
* installed before the upcoming build/pack tries to resolve imports.
|
|
250
250
|
* Cycle-safe via the shared `visited` set. */
|
|
251
251
|
export declare function ensureFileDepModules(cwd: string, verbose?: boolean, visited?: Set<string>): void;
|
|
252
252
|
/** Run a command and return success status */
|
package/lib.js
CHANGED
|
@@ -1323,9 +1323,9 @@ function restoreNestedDepModules(stashed, verbose) {
|
|
|
1323
1323
|
}
|
|
1324
1324
|
}
|
|
1325
1325
|
/** Walk `file:` deps transitively and run `npm install` in any target whose
|
|
1326
|
-
* package.json declares deps but has no `node_modules/`.
|
|
1327
|
-
*
|
|
1328
|
-
* upcoming build/pack
|
|
1326
|
+
* package.json declares deps but has no `node_modules/`. Also covers `cwd`
|
|
1327
|
+
* itself on the first call, so a fresh clone with no `node_modules/` gets
|
|
1328
|
+
* installed before the upcoming build/pack tries to resolve imports.
|
|
1329
1329
|
* Cycle-safe via the shared `visited` set. */
|
|
1330
1330
|
export function ensureFileDepModules(cwd, verbose = false, visited = new Set()) {
|
|
1331
1331
|
const abs = path.resolve(cwd);
|
|
@@ -1339,6 +1339,26 @@ export function ensureFileDepModules(cwd, verbose = false, visited = new Set())
|
|
|
1339
1339
|
catch {
|
|
1340
1340
|
return;
|
|
1341
1341
|
}
|
|
1342
|
+
const cwdHasDeps = (pkg?.dependencies && Object.keys(pkg.dependencies).length > 0) ||
|
|
1343
|
+
(pkg?.devDependencies && Object.keys(pkg.devDependencies).length > 0);
|
|
1344
|
+
if (cwdHasDeps && !fs.existsSync(path.join(abs, 'node_modules'))) {
|
|
1345
|
+
const lock = path.join(abs, 'package-lock.json');
|
|
1346
|
+
if (fs.existsSync(lock)) {
|
|
1347
|
+
if (verbose)
|
|
1348
|
+
console.log(colors.dim(` removing stale ${lock}`));
|
|
1349
|
+
try {
|
|
1350
|
+
fs.rmSync(lock, { force: true });
|
|
1351
|
+
}
|
|
1352
|
+
catch { /* best-effort */ }
|
|
1353
|
+
}
|
|
1354
|
+
console.log(colors.yellow(`↻ installing node_modules in ${pkg?.name || abs}`));
|
|
1355
|
+
const r = runCommand('npm', ['install'], { cwd: abs, silent: !verbose });
|
|
1356
|
+
if (!r.success) {
|
|
1357
|
+
console.error(colors.red(` ✗ npm install failed in ${abs}`));
|
|
1358
|
+
if (r.stderr)
|
|
1359
|
+
console.error(colors.dim(r.stderr.split('\n').slice(0, 5).join('\n')));
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1342
1362
|
for (const key of ['dependencies', 'devDependencies']) {
|
|
1343
1363
|
const deps = pkg?.[key];
|
|
1344
1364
|
if (!deps || typeof deps !== 'object')
|
|
@@ -1360,6 +1380,15 @@ export function ensureFileDepModules(cwd, verbose = false, visited = new Set())
|
|
|
1360
1380
|
(targetPkg?.devDependencies && Object.keys(targetPkg.devDependencies).length > 0);
|
|
1361
1381
|
const nm = path.join(target, 'node_modules');
|
|
1362
1382
|
if (hasDeps && !fs.existsSync(nm)) {
|
|
1383
|
+
const lock = path.join(target, 'package-lock.json');
|
|
1384
|
+
if (fs.existsSync(lock)) {
|
|
1385
|
+
if (verbose)
|
|
1386
|
+
console.log(colors.dim(` removing stale ${lock}`));
|
|
1387
|
+
try {
|
|
1388
|
+
fs.rmSync(lock, { force: true });
|
|
1389
|
+
}
|
|
1390
|
+
catch { /* best-effort */ }
|
|
1391
|
+
}
|
|
1363
1392
|
console.log(colors.yellow(`↻ restoring node_modules in ${name} (${target})`));
|
|
1364
1393
|
const r = runCommand('npm', ['install'], { cwd: target, silent: !verbose });
|
|
1365
1394
|
if (!r.success) {
|