@vercel/build-utils 8.3.2 → 8.3.3
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/CHANGELOG.md +6 -0
- package/dist/fs/run-user-scripts.d.ts +6 -0
- package/dist/fs/run-user-scripts.js +31 -18
- package/dist/index.js +31 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -26,6 +26,12 @@ export interface ScanParentDirsResult {
|
|
26
26
|
* or `undefined` if not found.
|
27
27
|
*/
|
28
28
|
lockfileVersion?: number;
|
29
|
+
/**
|
30
|
+
* The contents of the `packageManager` field from `package.json` if found.
|
31
|
+
* The value may come from a different `package.json` file than the one
|
32
|
+
* specified by `packageJsonPath`, in the case of a monorepo.
|
33
|
+
*/
|
34
|
+
packageJsonPackageManager?: string;
|
29
35
|
}
|
30
36
|
export interface TraverseUpDirectoriesProps {
|
31
37
|
/**
|
@@ -219,7 +219,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
219
219
|
filename: "package.json"
|
220
220
|
});
|
221
221
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
222
|
-
const
|
222
|
+
const {
|
223
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
224
|
+
packageJsonPackageManager
|
225
|
+
} = await walkParentDirsMulti({
|
223
226
|
base,
|
224
227
|
start: destPath,
|
225
228
|
filenames: [
|
@@ -258,19 +261,21 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
258
261
|
lockfilePath = bunLockPath;
|
259
262
|
lockfileVersion = 0;
|
260
263
|
} else {
|
261
|
-
cliType =
|
264
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
265
|
+
packageJsonPackageManager
|
266
|
+
);
|
262
267
|
}
|
263
268
|
const packageJsonPath = pkgJsonPath || void 0;
|
264
269
|
return {
|
265
270
|
cliType,
|
266
271
|
packageJson,
|
272
|
+
packageJsonPackageManager,
|
267
273
|
lockfilePath,
|
268
274
|
lockfileVersion,
|
269
275
|
packageJsonPath
|
270
276
|
};
|
271
277
|
}
|
272
|
-
function detectPackageManagerNameWithoutLockfile(
|
273
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
278
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager) {
|
274
279
|
if (usingCorepack(process.env, packageJsonPackageManager)) {
|
275
280
|
const corepackPackageManager = validateVersionSpecifier(
|
276
281
|
packageJsonPackageManager
|
@@ -315,17 +320,26 @@ async function walkParentDirsMulti({
|
|
315
320
|
start,
|
316
321
|
filenames
|
317
322
|
}) {
|
323
|
+
let packageManager;
|
318
324
|
for (const dir of traverseUpDirectories({ start, base })) {
|
319
325
|
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
320
326
|
const existResults = await Promise.all(
|
321
327
|
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
322
328
|
);
|
323
329
|
const foundOneOrMore = existResults.some((b) => b);
|
330
|
+
const packageJsonPath = import_path.default.join(dir, "package.json");
|
331
|
+
const packageJson = await import_fs_extra.default.readJSON(packageJsonPath).catch(() => null);
|
332
|
+
if (packageJson?.packageManager) {
|
333
|
+
packageManager = packageJson.packageManager;
|
334
|
+
}
|
324
335
|
if (foundOneOrMore) {
|
325
|
-
return
|
336
|
+
return {
|
337
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
338
|
+
packageJsonPackageManager: packageManager
|
339
|
+
};
|
326
340
|
}
|
327
341
|
}
|
328
|
-
return [];
|
342
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
329
343
|
}
|
330
344
|
function isSet(v) {
|
331
345
|
return v?.constructor?.name === "Set";
|
@@ -338,7 +352,12 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
338
352
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
339
353
|
try {
|
340
354
|
await runNpmInstallSema.acquire();
|
341
|
-
const {
|
355
|
+
const {
|
356
|
+
cliType,
|
357
|
+
packageJsonPath,
|
358
|
+
lockfileVersion,
|
359
|
+
packageJsonPackageManager
|
360
|
+
} = await scanParentDirs(destPath);
|
342
361
|
if (!packageJsonPath) {
|
343
362
|
(0, import_debug.default)(
|
344
363
|
`Skipping dependency installation because no package.json was found for ${destPath}`
|
@@ -367,7 +386,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
367
386
|
opts.env = getEnvForPackageManager({
|
368
387
|
cliType,
|
369
388
|
lockfileVersion,
|
370
|
-
packageJsonPackageManager
|
389
|
+
packageJsonPackageManager,
|
371
390
|
nodeVersion,
|
372
391
|
env
|
373
392
|
});
|
@@ -677,14 +696,11 @@ async function runCustomInstallCommand({
|
|
677
696
|
spawnOpts
|
678
697
|
}) {
|
679
698
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
680
|
-
const { cliType, lockfileVersion,
|
681
|
-
destPath,
|
682
|
-
true
|
683
|
-
);
|
699
|
+
const { cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath);
|
684
700
|
const env = getEnvForPackageManager({
|
685
701
|
cliType,
|
686
702
|
lockfileVersion,
|
687
|
-
packageJsonPackageManager
|
703
|
+
packageJsonPackageManager,
|
688
704
|
nodeVersion,
|
689
705
|
env: spawnOpts?.env || {}
|
690
706
|
});
|
@@ -697,10 +713,7 @@ async function runCustomInstallCommand({
|
|
697
713
|
}
|
698
714
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
699
715
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
700
|
-
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
701
|
-
destPath,
|
702
|
-
true
|
703
|
-
);
|
716
|
+
const { packageJson, cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath, true);
|
704
717
|
const scriptName = getScriptName(
|
705
718
|
packageJson,
|
706
719
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -715,7 +728,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
715
728
|
env: getEnvForPackageManager({
|
716
729
|
cliType,
|
717
730
|
lockfileVersion,
|
718
|
-
packageJsonPackageManager
|
731
|
+
packageJsonPackageManager,
|
719
732
|
nodeVersion: void 0,
|
720
733
|
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env)
|
721
734
|
})
|
package/dist/index.js
CHANGED
@@ -21940,7 +21940,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
21940
21940
|
filename: "package.json"
|
21941
21941
|
});
|
21942
21942
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra7.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
21943
|
-
const
|
21943
|
+
const {
|
21944
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
21945
|
+
packageJsonPackageManager
|
21946
|
+
} = await walkParentDirsMulti({
|
21944
21947
|
base,
|
21945
21948
|
start: destPath,
|
21946
21949
|
filenames: [
|
@@ -21979,19 +21982,21 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
21979
21982
|
lockfilePath = bunLockPath;
|
21980
21983
|
lockfileVersion = 0;
|
21981
21984
|
} else {
|
21982
|
-
cliType =
|
21985
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
21986
|
+
packageJsonPackageManager
|
21987
|
+
);
|
21983
21988
|
}
|
21984
21989
|
const packageJsonPath = pkgJsonPath || void 0;
|
21985
21990
|
return {
|
21986
21991
|
cliType,
|
21987
21992
|
packageJson,
|
21993
|
+
packageJsonPackageManager,
|
21988
21994
|
lockfilePath,
|
21989
21995
|
lockfileVersion,
|
21990
21996
|
packageJsonPath
|
21991
21997
|
};
|
21992
21998
|
}
|
21993
|
-
function detectPackageManagerNameWithoutLockfile(
|
21994
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
21999
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager) {
|
21995
22000
|
if (usingCorepack(process.env, packageJsonPackageManager)) {
|
21996
22001
|
const corepackPackageManager = validateVersionSpecifier(
|
21997
22002
|
packageJsonPackageManager
|
@@ -22036,17 +22041,26 @@ async function walkParentDirsMulti({
|
|
22036
22041
|
start,
|
22037
22042
|
filenames
|
22038
22043
|
}) {
|
22044
|
+
let packageManager;
|
22039
22045
|
for (const dir of traverseUpDirectories({ start, base })) {
|
22040
22046
|
const fullPaths = filenames.map((f) => import_path5.default.join(dir, f));
|
22041
22047
|
const existResults = await Promise.all(
|
22042
22048
|
fullPaths.map((f) => import_fs_extra7.default.pathExists(f))
|
22043
22049
|
);
|
22044
22050
|
const foundOneOrMore = existResults.some((b) => b);
|
22051
|
+
const packageJsonPath = import_path5.default.join(dir, "package.json");
|
22052
|
+
const packageJson = await import_fs_extra7.default.readJSON(packageJsonPath).catch(() => null);
|
22053
|
+
if (packageJson?.packageManager) {
|
22054
|
+
packageManager = packageJson.packageManager;
|
22055
|
+
}
|
22045
22056
|
if (foundOneOrMore) {
|
22046
|
-
return
|
22057
|
+
return {
|
22058
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
22059
|
+
packageJsonPackageManager: packageManager
|
22060
|
+
};
|
22047
22061
|
}
|
22048
22062
|
}
|
22049
|
-
return [];
|
22063
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
22050
22064
|
}
|
22051
22065
|
function isSet(v) {
|
22052
22066
|
return v?.constructor?.name === "Set";
|
@@ -22059,7 +22073,12 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
22059
22073
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
22060
22074
|
try {
|
22061
22075
|
await runNpmInstallSema.acquire();
|
22062
|
-
const {
|
22076
|
+
const {
|
22077
|
+
cliType,
|
22078
|
+
packageJsonPath,
|
22079
|
+
lockfileVersion,
|
22080
|
+
packageJsonPackageManager
|
22081
|
+
} = await scanParentDirs(destPath);
|
22063
22082
|
if (!packageJsonPath) {
|
22064
22083
|
debug(
|
22065
22084
|
`Skipping dependency installation because no package.json was found for ${destPath}`
|
@@ -22088,7 +22107,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
22088
22107
|
opts.env = getEnvForPackageManager({
|
22089
22108
|
cliType,
|
22090
22109
|
lockfileVersion,
|
22091
|
-
packageJsonPackageManager
|
22110
|
+
packageJsonPackageManager,
|
22092
22111
|
nodeVersion,
|
22093
22112
|
env
|
22094
22113
|
});
|
@@ -22398,14 +22417,11 @@ async function runCustomInstallCommand({
|
|
22398
22417
|
spawnOpts
|
22399
22418
|
}) {
|
22400
22419
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
22401
|
-
const { cliType, lockfileVersion,
|
22402
|
-
destPath,
|
22403
|
-
true
|
22404
|
-
);
|
22420
|
+
const { cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath);
|
22405
22421
|
const env = getEnvForPackageManager({
|
22406
22422
|
cliType,
|
22407
22423
|
lockfileVersion,
|
22408
|
-
packageJsonPackageManager
|
22424
|
+
packageJsonPackageManager,
|
22409
22425
|
nodeVersion,
|
22410
22426
|
env: spawnOpts?.env || {}
|
22411
22427
|
});
|
@@ -22418,10 +22434,7 @@ async function runCustomInstallCommand({
|
|
22418
22434
|
}
|
22419
22435
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
22420
22436
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
22421
|
-
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
22422
|
-
destPath,
|
22423
|
-
true
|
22424
|
-
);
|
22437
|
+
const { packageJson, cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath, true);
|
22425
22438
|
const scriptName = getScriptName(
|
22426
22439
|
packageJson,
|
22427
22440
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -22436,7 +22449,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
22436
22449
|
env: getEnvForPackageManager({
|
22437
22450
|
cliType,
|
22438
22451
|
lockfileVersion,
|
22439
|
-
packageJsonPackageManager
|
22452
|
+
packageJsonPackageManager,
|
22440
22453
|
nodeVersion: void 0,
|
22441
22454
|
env: cloneEnv(process.env, spawnOpts?.env)
|
22442
22455
|
})
|