@vercel/build-utils 8.4.0 → 8.4.1
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 +32 -18
- package/dist/index.js +32 -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,13 @@ 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
|
+
packageJson
|
361
|
+
} = await scanParentDirs(destPath);
|
342
362
|
if (!packageJsonPath) {
|
343
363
|
(0, import_debug.default)(
|
344
364
|
`Skipping dependency installation because no package.json was found for ${destPath}`
|
@@ -367,7 +387,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
367
387
|
opts.env = getEnvForPackageManager({
|
368
388
|
cliType,
|
369
389
|
lockfileVersion,
|
370
|
-
packageJsonPackageManager
|
390
|
+
packageJsonPackageManager,
|
371
391
|
nodeVersion,
|
372
392
|
env,
|
373
393
|
packageJsonEngines: packageJson?.engines
|
@@ -706,14 +726,11 @@ async function runCustomInstallCommand({
|
|
706
726
|
spawnOpts
|
707
727
|
}) {
|
708
728
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
709
|
-
const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
|
710
|
-
destPath,
|
711
|
-
true
|
712
|
-
);
|
729
|
+
const { cliType, lockfileVersion, packageJsonPackageManager, packageJson } = await scanParentDirs(destPath);
|
713
730
|
const env = getEnvForPackageManager({
|
714
731
|
cliType,
|
715
732
|
lockfileVersion,
|
716
|
-
packageJsonPackageManager
|
733
|
+
packageJsonPackageManager,
|
717
734
|
nodeVersion,
|
718
735
|
env: spawnOpts?.env || {},
|
719
736
|
packageJsonEngines: packageJson?.engines
|
@@ -727,10 +744,7 @@ async function runCustomInstallCommand({
|
|
727
744
|
}
|
728
745
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
729
746
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
730
|
-
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
731
|
-
destPath,
|
732
|
-
true
|
733
|
-
);
|
747
|
+
const { packageJson, cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath, true);
|
734
748
|
const scriptName = getScriptName(
|
735
749
|
packageJson,
|
736
750
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -745,7 +759,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
745
759
|
env: getEnvForPackageManager({
|
746
760
|
cliType,
|
747
761
|
lockfileVersion,
|
748
|
-
packageJsonPackageManager
|
762
|
+
packageJsonPackageManager,
|
749
763
|
nodeVersion: void 0,
|
750
764
|
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
|
751
765
|
packageJsonEngines: packageJson?.engines
|
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,13 @@ 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
|
+
packageJson
|
22082
|
+
} = await scanParentDirs(destPath);
|
22063
22083
|
if (!packageJsonPath) {
|
22064
22084
|
debug(
|
22065
22085
|
`Skipping dependency installation because no package.json was found for ${destPath}`
|
@@ -22088,7 +22108,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
22088
22108
|
opts.env = getEnvForPackageManager({
|
22089
22109
|
cliType,
|
22090
22110
|
lockfileVersion,
|
22091
|
-
packageJsonPackageManager
|
22111
|
+
packageJsonPackageManager,
|
22092
22112
|
nodeVersion,
|
22093
22113
|
env,
|
22094
22114
|
packageJsonEngines: packageJson?.engines
|
@@ -22427,14 +22447,11 @@ async function runCustomInstallCommand({
|
|
22427
22447
|
spawnOpts
|
22428
22448
|
}) {
|
22429
22449
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
22430
|
-
const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
|
22431
|
-
destPath,
|
22432
|
-
true
|
22433
|
-
);
|
22450
|
+
const { cliType, lockfileVersion, packageJsonPackageManager, packageJson } = await scanParentDirs(destPath);
|
22434
22451
|
const env = getEnvForPackageManager({
|
22435
22452
|
cliType,
|
22436
22453
|
lockfileVersion,
|
22437
|
-
packageJsonPackageManager
|
22454
|
+
packageJsonPackageManager,
|
22438
22455
|
nodeVersion,
|
22439
22456
|
env: spawnOpts?.env || {},
|
22440
22457
|
packageJsonEngines: packageJson?.engines
|
@@ -22448,10 +22465,7 @@ async function runCustomInstallCommand({
|
|
22448
22465
|
}
|
22449
22466
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
22450
22467
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
22451
|
-
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
22452
|
-
destPath,
|
22453
|
-
true
|
22454
|
-
);
|
22468
|
+
const { packageJson, cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath, true);
|
22455
22469
|
const scriptName = getScriptName(
|
22456
22470
|
packageJson,
|
22457
22471
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -22466,7 +22480,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
22466
22480
|
env: getEnvForPackageManager({
|
22467
22481
|
cliType,
|
22468
22482
|
lockfileVersion,
|
22469
|
-
packageJsonPackageManager
|
22483
|
+
packageJsonPackageManager,
|
22470
22484
|
nodeVersion: void 0,
|
22471
22485
|
env: cloneEnv(process.env, spawnOpts?.env),
|
22472
22486
|
packageJsonEngines: packageJson?.engines
|