@vercel/build-utils 8.4.10 → 8.4.11
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 +8 -0
- package/dist/fs/run-user-scripts.d.ts +6 -0
- package/dist/fs/run-user-scripts.js +48 -15
- package/dist/index.js +48 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# @vercel/build-utils
|
2
2
|
|
3
|
+
## 8.4.11
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Improve parsing of `turbo.json` ([#12266](https://github.com/vercel/vercel/pull/12266))
|
8
|
+
|
9
|
+
- Fix corepack `packageManager` detection on monorepos ([#12258](https://github.com/vercel/vercel/pull/12258))
|
10
|
+
|
3
11
|
## 8.4.10
|
4
12
|
|
5
13
|
### Patch Changes
|
@@ -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
|
* Whether Turborepo supports the `COREPACK_HOME` environment variable.
|
31
37
|
* `undefined` if not a Turborepo project.
|
@@ -238,7 +238,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
238
238
|
filename: "package.json"
|
239
239
|
});
|
240
240
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
241
|
-
const
|
241
|
+
const {
|
242
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
243
|
+
packageJsonPackageManager
|
244
|
+
} = await walkParentDirsMulti({
|
242
245
|
base,
|
243
246
|
start: destPath,
|
244
247
|
filenames: [
|
@@ -286,15 +289,16 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
286
289
|
lockfilePath = bunLockPath;
|
287
290
|
lockfileVersion = 0;
|
288
291
|
} else {
|
289
|
-
cliType =
|
290
|
-
|
292
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
293
|
+
packageJsonPackageManager,
|
291
294
|
turboSupportsCorepackHome
|
292
|
-
)
|
295
|
+
);
|
293
296
|
}
|
294
297
|
const packageJsonPath = pkgJsonPath || void 0;
|
295
298
|
return {
|
296
299
|
cliType,
|
297
300
|
packageJson,
|
301
|
+
packageJsonPackageManager,
|
298
302
|
lockfilePath,
|
299
303
|
lockfileVersion,
|
300
304
|
packageJsonPath,
|
@@ -307,8 +311,16 @@ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
|
|
307
311
|
}
|
308
312
|
const turboJsonPath = import_path.default.join(rootDir, "turbo.json");
|
309
313
|
const turboJsonExists = await import_fs_extra.default.pathExists(turboJsonPath);
|
310
|
-
|
311
|
-
|
314
|
+
let turboJson = null;
|
315
|
+
if (turboJsonExists) {
|
316
|
+
try {
|
317
|
+
turboJson = import_json5.default.parse(await import_fs_extra.default.readFile(turboJsonPath, "utf8"));
|
318
|
+
} catch (err) {
|
319
|
+
console.warn(`WARNING: Failed to parse turbo.json`);
|
320
|
+
}
|
321
|
+
}
|
322
|
+
const turboJsonIncludesCorepackHome = turboJson !== null && typeof turboJson === "object" && "globalPassThroughEnv" in turboJson && Array.isArray(turboJson.globalPassThroughEnv) && turboJson.globalPassThroughEnv.includes("COREPACK_HOME");
|
323
|
+
return turboJsonIncludesCorepackHome;
|
312
324
|
}
|
313
325
|
function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
314
326
|
if (!(0, import_semver.validRange)(turboVersionSpecifier)) {
|
@@ -321,8 +333,7 @@ function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
|
321
333
|
}
|
322
334
|
return (0, import_semver.gte)(minTurboBeingUsed, versionSupportingCorepack);
|
323
335
|
}
|
324
|
-
function detectPackageManagerNameWithoutLockfile(
|
325
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
336
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
|
326
337
|
if (usingCorepack(
|
327
338
|
process.env,
|
328
339
|
packageJsonPackageManager,
|
@@ -379,17 +390,26 @@ async function walkParentDirsMulti({
|
|
379
390
|
start,
|
380
391
|
filenames
|
381
392
|
}) {
|
393
|
+
let packageManager;
|
382
394
|
for (const dir of traverseUpDirectories({ start, base })) {
|
383
395
|
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
384
396
|
const existResults = await Promise.all(
|
385
397
|
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
386
398
|
);
|
387
399
|
const foundOneOrMore = existResults.some((b) => b);
|
400
|
+
const packageJsonPath = import_path.default.join(dir, "package.json");
|
401
|
+
const packageJson = await import_fs_extra.default.readJSON(packageJsonPath).catch(() => null);
|
402
|
+
if (packageJson?.packageManager) {
|
403
|
+
packageManager = packageJson.packageManager;
|
404
|
+
}
|
388
405
|
if (foundOneOrMore) {
|
389
|
-
return
|
406
|
+
return {
|
407
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
408
|
+
packageJsonPackageManager: packageManager
|
409
|
+
};
|
390
410
|
}
|
391
411
|
}
|
392
|
-
return [];
|
412
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
393
413
|
}
|
394
414
|
function isSet(v) {
|
395
415
|
return v?.constructor?.name === "Set";
|
@@ -407,6 +427,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
407
427
|
packageJsonPath,
|
408
428
|
packageJson,
|
409
429
|
lockfileVersion,
|
430
|
+
packageJsonPackageManager,
|
410
431
|
turboSupportsCorepackHome
|
411
432
|
} = await scanParentDirs(destPath, true);
|
412
433
|
if (!packageJsonPath) {
|
@@ -437,7 +458,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
437
458
|
opts.env = getEnvForPackageManager({
|
438
459
|
cliType,
|
439
460
|
lockfileVersion,
|
440
|
-
packageJsonPackageManager
|
461
|
+
packageJsonPackageManager,
|
441
462
|
nodeVersion,
|
442
463
|
env,
|
443
464
|
packageJsonEngines: packageJson?.engines,
|
@@ -782,11 +803,17 @@ async function runCustomInstallCommand({
|
|
782
803
|
spawnOpts
|
783
804
|
}) {
|
784
805
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
785
|
-
const {
|
806
|
+
const {
|
807
|
+
cliType,
|
808
|
+
lockfileVersion,
|
809
|
+
packageJson,
|
810
|
+
packageJsonPackageManager,
|
811
|
+
turboSupportsCorepackHome
|
812
|
+
} = await scanParentDirs(destPath, true);
|
786
813
|
const env = getEnvForPackageManager({
|
787
814
|
cliType,
|
788
815
|
lockfileVersion,
|
789
|
-
packageJsonPackageManager
|
816
|
+
packageJsonPackageManager,
|
790
817
|
nodeVersion,
|
791
818
|
env: spawnOpts?.env || {},
|
792
819
|
packageJsonEngines: packageJson?.engines,
|
@@ -801,7 +828,13 @@ async function runCustomInstallCommand({
|
|
801
828
|
}
|
802
829
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
803
830
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
804
|
-
const {
|
831
|
+
const {
|
832
|
+
packageJson,
|
833
|
+
cliType,
|
834
|
+
lockfileVersion,
|
835
|
+
packageJsonPackageManager,
|
836
|
+
turboSupportsCorepackHome
|
837
|
+
} = await scanParentDirs(destPath, true);
|
805
838
|
const scriptName = getScriptName(
|
806
839
|
packageJson,
|
807
840
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -816,7 +849,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
816
849
|
env: getEnvForPackageManager({
|
817
850
|
cliType,
|
818
851
|
lockfileVersion,
|
819
|
-
packageJsonPackageManager
|
852
|
+
packageJsonPackageManager,
|
820
853
|
nodeVersion: void 0,
|
821
854
|
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
|
822
855
|
packageJsonEngines: packageJson?.engines,
|
package/dist/index.js
CHANGED
@@ -24719,7 +24719,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
24719
24719
|
filename: "package.json"
|
24720
24720
|
});
|
24721
24721
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra7.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
24722
|
-
const
|
24722
|
+
const {
|
24723
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
24724
|
+
packageJsonPackageManager
|
24725
|
+
} = await walkParentDirsMulti({
|
24723
24726
|
base,
|
24724
24727
|
start: destPath,
|
24725
24728
|
filenames: [
|
@@ -24767,15 +24770,16 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
24767
24770
|
lockfilePath = bunLockPath;
|
24768
24771
|
lockfileVersion = 0;
|
24769
24772
|
} else {
|
24770
|
-
cliType =
|
24771
|
-
|
24773
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
24774
|
+
packageJsonPackageManager,
|
24772
24775
|
turboSupportsCorepackHome
|
24773
|
-
)
|
24776
|
+
);
|
24774
24777
|
}
|
24775
24778
|
const packageJsonPath = pkgJsonPath || void 0;
|
24776
24779
|
return {
|
24777
24780
|
cliType,
|
24778
24781
|
packageJson,
|
24782
|
+
packageJsonPackageManager,
|
24779
24783
|
lockfilePath,
|
24780
24784
|
lockfileVersion,
|
24781
24785
|
packageJsonPath,
|
@@ -24788,8 +24792,16 @@ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
|
|
24788
24792
|
}
|
24789
24793
|
const turboJsonPath = import_path5.default.join(rootDir, "turbo.json");
|
24790
24794
|
const turboJsonExists = await import_fs_extra7.default.pathExists(turboJsonPath);
|
24791
|
-
|
24792
|
-
|
24795
|
+
let turboJson = null;
|
24796
|
+
if (turboJsonExists) {
|
24797
|
+
try {
|
24798
|
+
turboJson = import_json5.default.parse(await import_fs_extra7.default.readFile(turboJsonPath, "utf8"));
|
24799
|
+
} catch (err) {
|
24800
|
+
console.warn(`WARNING: Failed to parse turbo.json`);
|
24801
|
+
}
|
24802
|
+
}
|
24803
|
+
const turboJsonIncludesCorepackHome = turboJson !== null && typeof turboJson === "object" && "globalPassThroughEnv" in turboJson && Array.isArray(turboJson.globalPassThroughEnv) && turboJson.globalPassThroughEnv.includes("COREPACK_HOME");
|
24804
|
+
return turboJsonIncludesCorepackHome;
|
24793
24805
|
}
|
24794
24806
|
function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
24795
24807
|
if (!(0, import_semver2.validRange)(turboVersionSpecifier)) {
|
@@ -24802,8 +24814,7 @@ function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
|
24802
24814
|
}
|
24803
24815
|
return (0, import_semver2.gte)(minTurboBeingUsed, versionSupportingCorepack);
|
24804
24816
|
}
|
24805
|
-
function detectPackageManagerNameWithoutLockfile(
|
24806
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
24817
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
|
24807
24818
|
if (usingCorepack(
|
24808
24819
|
process.env,
|
24809
24820
|
packageJsonPackageManager,
|
@@ -24860,17 +24871,26 @@ async function walkParentDirsMulti({
|
|
24860
24871
|
start,
|
24861
24872
|
filenames
|
24862
24873
|
}) {
|
24874
|
+
let packageManager;
|
24863
24875
|
for (const dir of traverseUpDirectories({ start, base })) {
|
24864
24876
|
const fullPaths = filenames.map((f) => import_path5.default.join(dir, f));
|
24865
24877
|
const existResults = await Promise.all(
|
24866
24878
|
fullPaths.map((f) => import_fs_extra7.default.pathExists(f))
|
24867
24879
|
);
|
24868
24880
|
const foundOneOrMore = existResults.some((b) => b);
|
24881
|
+
const packageJsonPath = import_path5.default.join(dir, "package.json");
|
24882
|
+
const packageJson = await import_fs_extra7.default.readJSON(packageJsonPath).catch(() => null);
|
24883
|
+
if (packageJson?.packageManager) {
|
24884
|
+
packageManager = packageJson.packageManager;
|
24885
|
+
}
|
24869
24886
|
if (foundOneOrMore) {
|
24870
|
-
return
|
24887
|
+
return {
|
24888
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
24889
|
+
packageJsonPackageManager: packageManager
|
24890
|
+
};
|
24871
24891
|
}
|
24872
24892
|
}
|
24873
|
-
return [];
|
24893
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
24874
24894
|
}
|
24875
24895
|
function isSet(v) {
|
24876
24896
|
return v?.constructor?.name === "Set";
|
@@ -24888,6 +24908,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
24888
24908
|
packageJsonPath,
|
24889
24909
|
packageJson,
|
24890
24910
|
lockfileVersion,
|
24911
|
+
packageJsonPackageManager,
|
24891
24912
|
turboSupportsCorepackHome
|
24892
24913
|
} = await scanParentDirs(destPath, true);
|
24893
24914
|
if (!packageJsonPath) {
|
@@ -24918,7 +24939,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
24918
24939
|
opts.env = getEnvForPackageManager({
|
24919
24940
|
cliType,
|
24920
24941
|
lockfileVersion,
|
24921
|
-
packageJsonPackageManager
|
24942
|
+
packageJsonPackageManager,
|
24922
24943
|
nodeVersion,
|
24923
24944
|
env,
|
24924
24945
|
packageJsonEngines: packageJson?.engines,
|
@@ -25263,11 +25284,17 @@ async function runCustomInstallCommand({
|
|
25263
25284
|
spawnOpts
|
25264
25285
|
}) {
|
25265
25286
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
25266
|
-
const {
|
25287
|
+
const {
|
25288
|
+
cliType,
|
25289
|
+
lockfileVersion,
|
25290
|
+
packageJson,
|
25291
|
+
packageJsonPackageManager,
|
25292
|
+
turboSupportsCorepackHome
|
25293
|
+
} = await scanParentDirs(destPath, true);
|
25267
25294
|
const env = getEnvForPackageManager({
|
25268
25295
|
cliType,
|
25269
25296
|
lockfileVersion,
|
25270
|
-
packageJsonPackageManager
|
25297
|
+
packageJsonPackageManager,
|
25271
25298
|
nodeVersion,
|
25272
25299
|
env: spawnOpts?.env || {},
|
25273
25300
|
packageJsonEngines: packageJson?.engines,
|
@@ -25282,7 +25309,13 @@ async function runCustomInstallCommand({
|
|
25282
25309
|
}
|
25283
25310
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
25284
25311
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
25285
|
-
const {
|
25312
|
+
const {
|
25313
|
+
packageJson,
|
25314
|
+
cliType,
|
25315
|
+
lockfileVersion,
|
25316
|
+
packageJsonPackageManager,
|
25317
|
+
turboSupportsCorepackHome
|
25318
|
+
} = await scanParentDirs(destPath, true);
|
25286
25319
|
const scriptName = getScriptName(
|
25287
25320
|
packageJson,
|
25288
25321
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -25297,7 +25330,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
25297
25330
|
env: getEnvForPackageManager({
|
25298
25331
|
cliType,
|
25299
25332
|
lockfileVersion,
|
25300
|
-
packageJsonPackageManager
|
25333
|
+
packageJsonPackageManager,
|
25301
25334
|
nodeVersion: void 0,
|
25302
25335
|
env: cloneEnv(process.env, spawnOpts?.env),
|
25303
25336
|
packageJsonEngines: packageJson?.engines,
|