@vercel/build-utils 8.4.9 → 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 +14 -0
- package/dist/fs/run-user-scripts.d.ts +6 -0
- package/dist/fs/run-user-scripts.js +49 -15
- package/dist/index.js +1161 -15
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
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
|
+
|
11
|
+
## 8.4.10
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- Parse `turbo.json` as json5 ([#12259](https://github.com/vercel/vercel/pull/12259))
|
16
|
+
|
3
17
|
## 8.4.9
|
4
18
|
|
5
19
|
### 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.
|
@@ -66,6 +66,7 @@ var import_errors = require("../errors");
|
|
66
66
|
var import_node_version = require("./node-version");
|
67
67
|
var import_read_config_file = require("./read-config-file");
|
68
68
|
var import_clone_env = require("../clone-env");
|
69
|
+
var import_json5 = __toESM(require("json5"));
|
69
70
|
const runNpmInstallSema = new import_async_sema.default(1);
|
70
71
|
const NO_OVERRIDE = {
|
71
72
|
detectedLockfile: void 0,
|
@@ -237,7 +238,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
237
238
|
filename: "package.json"
|
238
239
|
});
|
239
240
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
240
|
-
const
|
241
|
+
const {
|
242
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
243
|
+
packageJsonPackageManager
|
244
|
+
} = await walkParentDirsMulti({
|
241
245
|
base,
|
242
246
|
start: destPath,
|
243
247
|
filenames: [
|
@@ -285,15 +289,16 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
285
289
|
lockfilePath = bunLockPath;
|
286
290
|
lockfileVersion = 0;
|
287
291
|
} else {
|
288
|
-
cliType =
|
289
|
-
|
292
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
293
|
+
packageJsonPackageManager,
|
290
294
|
turboSupportsCorepackHome
|
291
|
-
)
|
295
|
+
);
|
292
296
|
}
|
293
297
|
const packageJsonPath = pkgJsonPath || void 0;
|
294
298
|
return {
|
295
299
|
cliType,
|
296
300
|
packageJson,
|
301
|
+
packageJsonPackageManager,
|
297
302
|
lockfilePath,
|
298
303
|
lockfileVersion,
|
299
304
|
packageJsonPath,
|
@@ -306,8 +311,16 @@ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
|
|
306
311
|
}
|
307
312
|
const turboJsonPath = import_path.default.join(rootDir, "turbo.json");
|
308
313
|
const turboJsonExists = await import_fs_extra.default.pathExists(turboJsonPath);
|
309
|
-
|
310
|
-
|
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;
|
311
324
|
}
|
312
325
|
function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
313
326
|
if (!(0, import_semver.validRange)(turboVersionSpecifier)) {
|
@@ -320,8 +333,7 @@ function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
|
320
333
|
}
|
321
334
|
return (0, import_semver.gte)(minTurboBeingUsed, versionSupportingCorepack);
|
322
335
|
}
|
323
|
-
function detectPackageManagerNameWithoutLockfile(
|
324
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
336
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
|
325
337
|
if (usingCorepack(
|
326
338
|
process.env,
|
327
339
|
packageJsonPackageManager,
|
@@ -378,17 +390,26 @@ async function walkParentDirsMulti({
|
|
378
390
|
start,
|
379
391
|
filenames
|
380
392
|
}) {
|
393
|
+
let packageManager;
|
381
394
|
for (const dir of traverseUpDirectories({ start, base })) {
|
382
395
|
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
383
396
|
const existResults = await Promise.all(
|
384
397
|
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
385
398
|
);
|
386
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
|
+
}
|
387
405
|
if (foundOneOrMore) {
|
388
|
-
return
|
406
|
+
return {
|
407
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
408
|
+
packageJsonPackageManager: packageManager
|
409
|
+
};
|
389
410
|
}
|
390
411
|
}
|
391
|
-
return [];
|
412
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
392
413
|
}
|
393
414
|
function isSet(v) {
|
394
415
|
return v?.constructor?.name === "Set";
|
@@ -406,6 +427,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
406
427
|
packageJsonPath,
|
407
428
|
packageJson,
|
408
429
|
lockfileVersion,
|
430
|
+
packageJsonPackageManager,
|
409
431
|
turboSupportsCorepackHome
|
410
432
|
} = await scanParentDirs(destPath, true);
|
411
433
|
if (!packageJsonPath) {
|
@@ -436,7 +458,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
436
458
|
opts.env = getEnvForPackageManager({
|
437
459
|
cliType,
|
438
460
|
lockfileVersion,
|
439
|
-
packageJsonPackageManager
|
461
|
+
packageJsonPackageManager,
|
440
462
|
nodeVersion,
|
441
463
|
env,
|
442
464
|
packageJsonEngines: packageJson?.engines,
|
@@ -781,11 +803,17 @@ async function runCustomInstallCommand({
|
|
781
803
|
spawnOpts
|
782
804
|
}) {
|
783
805
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
784
|
-
const {
|
806
|
+
const {
|
807
|
+
cliType,
|
808
|
+
lockfileVersion,
|
809
|
+
packageJson,
|
810
|
+
packageJsonPackageManager,
|
811
|
+
turboSupportsCorepackHome
|
812
|
+
} = await scanParentDirs(destPath, true);
|
785
813
|
const env = getEnvForPackageManager({
|
786
814
|
cliType,
|
787
815
|
lockfileVersion,
|
788
|
-
packageJsonPackageManager
|
816
|
+
packageJsonPackageManager,
|
789
817
|
nodeVersion,
|
790
818
|
env: spawnOpts?.env || {},
|
791
819
|
packageJsonEngines: packageJson?.engines,
|
@@ -800,7 +828,13 @@ async function runCustomInstallCommand({
|
|
800
828
|
}
|
801
829
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
802
830
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
803
|
-
const {
|
831
|
+
const {
|
832
|
+
packageJson,
|
833
|
+
cliType,
|
834
|
+
lockfileVersion,
|
835
|
+
packageJsonPackageManager,
|
836
|
+
turboSupportsCorepackHome
|
837
|
+
} = await scanParentDirs(destPath, true);
|
804
838
|
const scriptName = getScriptName(
|
805
839
|
packageJson,
|
806
840
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -815,7 +849,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
815
849
|
env: getEnvForPackageManager({
|
816
850
|
cliType,
|
817
851
|
lockfileVersion,
|
818
|
-
packageJsonPackageManager
|
852
|
+
packageJsonPackageManager,
|
819
853
|
nodeVersion: void 0,
|
820
854
|
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
|
821
855
|
packageJsonEngines: packageJson?.engines,
|