@vercel/build-utils 8.4.1 → 8.4.2
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 +0 -6
- package/dist/fs/run-user-scripts.js +18 -32
- package/dist/index.js +18 -32
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -26,12 +26,6 @@ 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;
|
35
29
|
}
|
36
30
|
export interface TraverseUpDirectoriesProps {
|
37
31
|
/**
|
@@ -219,10 +219,7 @@ 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 {
|
223
|
-
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
224
|
-
packageJsonPackageManager
|
225
|
-
} = await walkParentDirsMulti({
|
222
|
+
const [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
|
226
223
|
base,
|
227
224
|
start: destPath,
|
228
225
|
filenames: [
|
@@ -261,21 +258,19 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
261
258
|
lockfilePath = bunLockPath;
|
262
259
|
lockfileVersion = 0;
|
263
260
|
} else {
|
264
|
-
cliType = detectPackageManagerNameWithoutLockfile(
|
265
|
-
packageJsonPackageManager
|
266
|
-
);
|
261
|
+
cliType = packageJson ? detectPackageManagerNameWithoutLockfile(packageJson) : "npm";
|
267
262
|
}
|
268
263
|
const packageJsonPath = pkgJsonPath || void 0;
|
269
264
|
return {
|
270
265
|
cliType,
|
271
266
|
packageJson,
|
272
|
-
packageJsonPackageManager,
|
273
267
|
lockfilePath,
|
274
268
|
lockfileVersion,
|
275
269
|
packageJsonPath
|
276
270
|
};
|
277
271
|
}
|
278
|
-
function detectPackageManagerNameWithoutLockfile(
|
272
|
+
function detectPackageManagerNameWithoutLockfile(packageJson) {
|
273
|
+
const packageJsonPackageManager = packageJson.packageManager;
|
279
274
|
if (usingCorepack(process.env, packageJsonPackageManager)) {
|
280
275
|
const corepackPackageManager = validateVersionSpecifier(
|
281
276
|
packageJsonPackageManager
|
@@ -320,26 +315,17 @@ async function walkParentDirsMulti({
|
|
320
315
|
start,
|
321
316
|
filenames
|
322
317
|
}) {
|
323
|
-
let packageManager;
|
324
318
|
for (const dir of traverseUpDirectories({ start, base })) {
|
325
319
|
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
326
320
|
const existResults = await Promise.all(
|
327
321
|
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
328
322
|
);
|
329
323
|
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
|
-
}
|
335
324
|
if (foundOneOrMore) {
|
336
|
-
return
|
337
|
-
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
338
|
-
packageJsonPackageManager: packageManager
|
339
|
-
};
|
325
|
+
return fullPaths.map((f, i) => existResults[i] ? f : void 0);
|
340
326
|
}
|
341
327
|
}
|
342
|
-
return
|
328
|
+
return [];
|
343
329
|
}
|
344
330
|
function isSet(v) {
|
345
331
|
return v?.constructor?.name === "Set";
|
@@ -352,13 +338,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
352
338
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
353
339
|
try {
|
354
340
|
await runNpmInstallSema.acquire();
|
355
|
-
const {
|
356
|
-
cliType,
|
357
|
-
packageJsonPath,
|
358
|
-
lockfileVersion,
|
359
|
-
packageJsonPackageManager,
|
360
|
-
packageJson
|
361
|
-
} = await scanParentDirs(destPath);
|
341
|
+
const { cliType, packageJsonPath, packageJson, lockfileVersion } = await scanParentDirs(destPath, true);
|
362
342
|
if (!packageJsonPath) {
|
363
343
|
(0, import_debug.default)(
|
364
344
|
`Skipping dependency installation because no package.json was found for ${destPath}`
|
@@ -387,7 +367,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
387
367
|
opts.env = getEnvForPackageManager({
|
388
368
|
cliType,
|
389
369
|
lockfileVersion,
|
390
|
-
packageJsonPackageManager,
|
370
|
+
packageJsonPackageManager: packageJson?.packageManager,
|
391
371
|
nodeVersion,
|
392
372
|
env,
|
393
373
|
packageJsonEngines: packageJson?.engines
|
@@ -726,11 +706,14 @@ async function runCustomInstallCommand({
|
|
726
706
|
spawnOpts
|
727
707
|
}) {
|
728
708
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
729
|
-
const { cliType, lockfileVersion,
|
709
|
+
const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
|
710
|
+
destPath,
|
711
|
+
true
|
712
|
+
);
|
730
713
|
const env = getEnvForPackageManager({
|
731
714
|
cliType,
|
732
715
|
lockfileVersion,
|
733
|
-
packageJsonPackageManager,
|
716
|
+
packageJsonPackageManager: packageJson?.packageManager,
|
734
717
|
nodeVersion,
|
735
718
|
env: spawnOpts?.env || {},
|
736
719
|
packageJsonEngines: packageJson?.engines
|
@@ -744,7 +727,10 @@ async function runCustomInstallCommand({
|
|
744
727
|
}
|
745
728
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
746
729
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
747
|
-
const { packageJson, cliType, lockfileVersion
|
730
|
+
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
731
|
+
destPath,
|
732
|
+
true
|
733
|
+
);
|
748
734
|
const scriptName = getScriptName(
|
749
735
|
packageJson,
|
750
736
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -759,7 +745,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
759
745
|
env: getEnvForPackageManager({
|
760
746
|
cliType,
|
761
747
|
lockfileVersion,
|
762
|
-
packageJsonPackageManager,
|
748
|
+
packageJsonPackageManager: packageJson?.packageManager,
|
763
749
|
nodeVersion: void 0,
|
764
750
|
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
|
765
751
|
packageJsonEngines: packageJson?.engines
|
package/dist/index.js
CHANGED
@@ -21940,10 +21940,7 @@ 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 {
|
21944
|
-
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
21945
|
-
packageJsonPackageManager
|
21946
|
-
} = await walkParentDirsMulti({
|
21943
|
+
const [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
|
21947
21944
|
base,
|
21948
21945
|
start: destPath,
|
21949
21946
|
filenames: [
|
@@ -21982,21 +21979,19 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
21982
21979
|
lockfilePath = bunLockPath;
|
21983
21980
|
lockfileVersion = 0;
|
21984
21981
|
} else {
|
21985
|
-
cliType = detectPackageManagerNameWithoutLockfile(
|
21986
|
-
packageJsonPackageManager
|
21987
|
-
);
|
21982
|
+
cliType = packageJson ? detectPackageManagerNameWithoutLockfile(packageJson) : "npm";
|
21988
21983
|
}
|
21989
21984
|
const packageJsonPath = pkgJsonPath || void 0;
|
21990
21985
|
return {
|
21991
21986
|
cliType,
|
21992
21987
|
packageJson,
|
21993
|
-
packageJsonPackageManager,
|
21994
21988
|
lockfilePath,
|
21995
21989
|
lockfileVersion,
|
21996
21990
|
packageJsonPath
|
21997
21991
|
};
|
21998
21992
|
}
|
21999
|
-
function detectPackageManagerNameWithoutLockfile(
|
21993
|
+
function detectPackageManagerNameWithoutLockfile(packageJson) {
|
21994
|
+
const packageJsonPackageManager = packageJson.packageManager;
|
22000
21995
|
if (usingCorepack(process.env, packageJsonPackageManager)) {
|
22001
21996
|
const corepackPackageManager = validateVersionSpecifier(
|
22002
21997
|
packageJsonPackageManager
|
@@ -22041,26 +22036,17 @@ async function walkParentDirsMulti({
|
|
22041
22036
|
start,
|
22042
22037
|
filenames
|
22043
22038
|
}) {
|
22044
|
-
let packageManager;
|
22045
22039
|
for (const dir of traverseUpDirectories({ start, base })) {
|
22046
22040
|
const fullPaths = filenames.map((f) => import_path5.default.join(dir, f));
|
22047
22041
|
const existResults = await Promise.all(
|
22048
22042
|
fullPaths.map((f) => import_fs_extra7.default.pathExists(f))
|
22049
22043
|
);
|
22050
22044
|
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
|
-
}
|
22056
22045
|
if (foundOneOrMore) {
|
22057
|
-
return
|
22058
|
-
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
22059
|
-
packageJsonPackageManager: packageManager
|
22060
|
-
};
|
22046
|
+
return fullPaths.map((f, i) => existResults[i] ? f : void 0);
|
22061
22047
|
}
|
22062
22048
|
}
|
22063
|
-
return
|
22049
|
+
return [];
|
22064
22050
|
}
|
22065
22051
|
function isSet(v) {
|
22066
22052
|
return v?.constructor?.name === "Set";
|
@@ -22073,13 +22059,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
22073
22059
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
22074
22060
|
try {
|
22075
22061
|
await runNpmInstallSema.acquire();
|
22076
|
-
const {
|
22077
|
-
cliType,
|
22078
|
-
packageJsonPath,
|
22079
|
-
lockfileVersion,
|
22080
|
-
packageJsonPackageManager,
|
22081
|
-
packageJson
|
22082
|
-
} = await scanParentDirs(destPath);
|
22062
|
+
const { cliType, packageJsonPath, packageJson, lockfileVersion } = await scanParentDirs(destPath, true);
|
22083
22063
|
if (!packageJsonPath) {
|
22084
22064
|
debug(
|
22085
22065
|
`Skipping dependency installation because no package.json was found for ${destPath}`
|
@@ -22108,7 +22088,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
22108
22088
|
opts.env = getEnvForPackageManager({
|
22109
22089
|
cliType,
|
22110
22090
|
lockfileVersion,
|
22111
|
-
packageJsonPackageManager,
|
22091
|
+
packageJsonPackageManager: packageJson?.packageManager,
|
22112
22092
|
nodeVersion,
|
22113
22093
|
env,
|
22114
22094
|
packageJsonEngines: packageJson?.engines
|
@@ -22447,11 +22427,14 @@ async function runCustomInstallCommand({
|
|
22447
22427
|
spawnOpts
|
22448
22428
|
}) {
|
22449
22429
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
22450
|
-
const { cliType, lockfileVersion,
|
22430
|
+
const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
|
22431
|
+
destPath,
|
22432
|
+
true
|
22433
|
+
);
|
22451
22434
|
const env = getEnvForPackageManager({
|
22452
22435
|
cliType,
|
22453
22436
|
lockfileVersion,
|
22454
|
-
packageJsonPackageManager,
|
22437
|
+
packageJsonPackageManager: packageJson?.packageManager,
|
22455
22438
|
nodeVersion,
|
22456
22439
|
env: spawnOpts?.env || {},
|
22457
22440
|
packageJsonEngines: packageJson?.engines
|
@@ -22465,7 +22448,10 @@ async function runCustomInstallCommand({
|
|
22465
22448
|
}
|
22466
22449
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
22467
22450
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
22468
|
-
const { packageJson, cliType, lockfileVersion
|
22451
|
+
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
22452
|
+
destPath,
|
22453
|
+
true
|
22454
|
+
);
|
22469
22455
|
const scriptName = getScriptName(
|
22470
22456
|
packageJson,
|
22471
22457
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -22480,7 +22466,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
22480
22466
|
env: getEnvForPackageManager({
|
22481
22467
|
cliType,
|
22482
22468
|
lockfileVersion,
|
22483
|
-
packageJsonPackageManager,
|
22469
|
+
packageJsonPackageManager: packageJson?.packageManager,
|
22484
22470
|
nodeVersion: void 0,
|
22485
22471
|
env: cloneEnv(process.env, spawnOpts?.env),
|
22486
22472
|
packageJsonEngines: packageJson?.engines
|