@vercel/build-utils 8.4.5 → 8.4.7

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 8.4.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Disable corepack when Turborepo does not support `COREPACK_HOME` ([#12211](https://github.com/vercel/vercel/pull/12211))
8
+
9
+ - Fix corepack `packageManager` detection on monorepos ([#12219](https://github.com/vercel/vercel/pull/12219))
10
+
11
+ ## 8.4.6
12
+
13
+ ### Patch Changes
14
+
15
+ - add support for `images.localPatterns` ([#12195](https://github.com/vercel/vercel/pull/12195))
16
+
3
17
  ## 8.4.5
4
18
 
5
19
  ### Patch Changes
@@ -26,6 +26,17 @@ 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
+ /**
36
+ * Whether Turborepo supports the `COREPACK_HOME` environment variable.
37
+ * `undefined` if not a Turborepo project.
38
+ */
39
+ turboSupportsCorepackHome?: boolean;
29
40
  }
30
41
  export interface TraverseUpDirectoriesProps {
31
42
  /**
@@ -76,13 +87,16 @@ export declare function runShellScript(fsPath: string, args?: string[], spawnOpt
76
87
  export declare function getSpawnOptions(meta: Meta, nodeVersion: NodeVersion): SpawnOptions;
77
88
  export declare function getNodeVersion(destPath: string, fallbackVersion?: string | undefined, config?: Config, meta?: Meta, availableVersions?: number[]): Promise<NodeVersion>;
78
89
  export declare function scanParentDirs(destPath: string, readPackageJson?: boolean, base?: string): Promise<ScanParentDirsResult>;
90
+ export declare function usingCorepack(env: {
91
+ [x: string]: string | undefined;
92
+ }, packageJsonPackageManager: string | undefined, turboSupportsCorepackHome: boolean | undefined): boolean;
79
93
  export declare function walkParentDirs({ base, start, filename, }: WalkParentDirsProps): Promise<string | null>;
80
94
  export declare function runNpmInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta, nodeVersion?: NodeVersion): Promise<boolean>;
81
95
  /**
82
96
  * Prepares the input environment based on the used package manager and lockfile
83
97
  * versions.
84
98
  */
85
- export declare function getEnvForPackageManager({ cliType, lockfileVersion, packageJsonPackageManager, nodeVersion, env, packageJsonEngines, }: {
99
+ export declare function getEnvForPackageManager({ cliType, lockfileVersion, packageJsonPackageManager, nodeVersion, env, packageJsonEngines, turboSupportsCorepackHome, }: {
86
100
  cliType: CliType;
87
101
  lockfileVersion: number | undefined;
88
102
  packageJsonPackageManager?: string | undefined;
@@ -91,6 +105,7 @@ export declare function getEnvForPackageManager({ cliType, lockfileVersion, pack
91
105
  [x: string]: string | undefined;
92
106
  };
93
107
  packageJsonEngines?: PackageJson.Engines;
108
+ turboSupportsCorepackHome?: boolean | undefined;
94
109
  }): {
95
110
  [x: string]: string | undefined;
96
111
  };
@@ -49,6 +49,7 @@ __export(run_user_scripts_exports, {
49
49
  spawnAsync: () => spawnAsync,
50
50
  spawnCommand: () => spawnCommand,
51
51
  traverseUpDirectories: () => traverseUpDirectories,
52
+ usingCorepack: () => usingCorepack,
52
53
  walkParentDirs: () => walkParentDirs
53
54
  });
54
55
  module.exports = __toCommonJS(run_user_scripts_exports);
@@ -123,6 +124,22 @@ function* traverseUpDirectories({
123
124
  current = next === current ? void 0 : next;
124
125
  }
125
126
  }
127
+ async function readProjectRootInfo({
128
+ start,
129
+ base
130
+ }) {
131
+ let curRootPackageJsonPath;
132
+ for (const dir of traverseUpDirectories({ start, base })) {
133
+ const packageJsonPath = import_path.default.join(dir, "package.json");
134
+ if (await import_fs_extra.default.pathExists(packageJsonPath)) {
135
+ curRootPackageJsonPath = packageJsonPath;
136
+ }
137
+ }
138
+ return curRootPackageJsonPath ? {
139
+ packageJson: await import_fs_extra.default.readJson(curRootPackageJsonPath),
140
+ rootDir: import_path.default.dirname(curRootPackageJsonPath)
141
+ } : void 0;
142
+ }
126
143
  async function getNodeBinPath({
127
144
  cwd
128
145
  }) {
@@ -219,7 +236,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
219
236
  filename: "package.json"
220
237
  });
221
238
  const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
222
- const [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
239
+ const {
240
+ paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
241
+ packageJsonPackageManager
242
+ } = await walkParentDirsMulti({
223
243
  base,
224
244
  start: destPath,
225
245
  filenames: [
@@ -238,6 +258,15 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
238
258
  pnpmLockPath ? (0, import_read_config_file.readConfigFile)(pnpmLockPath) : null,
239
259
  bunLockPath ? import_fs_extra.default.readFile(bunLockPath, "utf8") : null
240
260
  ]);
261
+ const rootProjectInfo = readPackageJson ? await readProjectRootInfo({
262
+ base,
263
+ start: destPath
264
+ }) : void 0;
265
+ const turboVersionRange = rootProjectInfo?.packageJson?.devDependencies?.turbo;
266
+ const turboSupportsCorepackHome = turboVersionRange ? await checkTurboSupportsCorepack(
267
+ turboVersionRange,
268
+ rootProjectInfo?.rootDir
269
+ ) : void 0;
241
270
  if (bunLockBin && hasYarnLock) {
242
271
  cliType = "bun";
243
272
  lockfilePath = bunLockPath;
@@ -258,20 +287,45 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
258
287
  lockfilePath = bunLockPath;
259
288
  lockfileVersion = 0;
260
289
  } else {
261
- cliType = packageJson ? detectPackageManagerNameWithoutLockfile(packageJson) : "npm";
290
+ cliType = detectPackageManagerNameWithoutLockfile(
291
+ packageJsonPackageManager,
292
+ turboSupportsCorepackHome
293
+ );
262
294
  }
263
295
  const packageJsonPath = pkgJsonPath || void 0;
264
296
  return {
265
297
  cliType,
266
298
  packageJson,
299
+ packageJsonPackageManager,
267
300
  lockfilePath,
268
301
  lockfileVersion,
269
- packageJsonPath
302
+ packageJsonPath,
303
+ turboSupportsCorepackHome
270
304
  };
271
305
  }
272
- function detectPackageManagerNameWithoutLockfile(packageJson) {
273
- const packageJsonPackageManager = packageJson.packageManager;
274
- if (usingCorepack(process.env, packageJsonPackageManager)) {
306
+ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
307
+ if (turboRangeSupportsCorepack(turboVersionRange)) {
308
+ return true;
309
+ }
310
+ const turboJsonPath = import_path.default.join(rootDir, "turbo.json");
311
+ const turboJsonExists = await import_fs_extra.default.pathExists(turboJsonPath);
312
+ const turboJson = turboJsonExists ? JSON.parse(await import_fs_extra.default.readFile(turboJsonPath, "utf8")) : void 0;
313
+ return turboJson?.globalPassThroughEnv?.includes("COREPACK_HOME") || false;
314
+ }
315
+ function turboRangeSupportsCorepack(turboVersionRange) {
316
+ const versionSupportingCorepack = "2.1.3";
317
+ const minTurboBeingUsed = (0, import_semver.minVersion)(turboVersionRange);
318
+ if (!minTurboBeingUsed) {
319
+ return false;
320
+ }
321
+ return (0, import_semver.gte)(minTurboBeingUsed, versionSupportingCorepack);
322
+ }
323
+ function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
324
+ if (usingCorepack(
325
+ process.env,
326
+ packageJsonPackageManager,
327
+ turboSupportsCorepackHome
328
+ )) {
275
329
  const corepackPackageManager = validateVersionSpecifier(
276
330
  packageJsonPackageManager
277
331
  );
@@ -291,9 +345,17 @@ function detectPackageManagerNameWithoutLockfile(packageJson) {
291
345
  }
292
346
  return "npm";
293
347
  }
294
- function usingCorepack(env, packageJsonPackageManager) {
295
- const corepackFlagged = env.ENABLE_EXPERIMENTAL_COREPACK === "1";
296
- return corepackFlagged && Boolean(packageJsonPackageManager);
348
+ function usingCorepack(env, packageJsonPackageManager, turboSupportsCorepackHome) {
349
+ if (env.ENABLE_EXPERIMENTAL_COREPACK !== "1" || packageJsonPackageManager === void 0) {
350
+ return false;
351
+ }
352
+ if (turboSupportsCorepackHome === false) {
353
+ console.warn(
354
+ "Warning: Disabling corepack because it may break your project. To use corepack, either upgrade to `turbo@2.1.3+` or include `COREPACK_HOME` in `turbo.json#globalPassThroughEnv`."
355
+ );
356
+ return false;
357
+ }
358
+ return true;
297
359
  }
298
360
  async function walkParentDirs({
299
361
  base,
@@ -315,17 +377,26 @@ async function walkParentDirsMulti({
315
377
  start,
316
378
  filenames
317
379
  }) {
380
+ let packageManager;
318
381
  for (const dir of traverseUpDirectories({ start, base })) {
319
382
  const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
320
383
  const existResults = await Promise.all(
321
384
  fullPaths.map((f) => import_fs_extra.default.pathExists(f))
322
385
  );
323
386
  const foundOneOrMore = existResults.some((b) => b);
387
+ const packageJsonPath = import_path.default.join(dir, "package.json");
388
+ const packageJson = await import_fs_extra.default.readJSON(packageJsonPath).catch(() => null);
389
+ if (packageJson?.packageManager) {
390
+ packageManager = packageJson.packageManager;
391
+ }
324
392
  if (foundOneOrMore) {
325
- return fullPaths.map((f, i) => existResults[i] ? f : void 0);
393
+ return {
394
+ paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
395
+ packageJsonPackageManager: packageManager
396
+ };
326
397
  }
327
398
  }
328
- return [];
399
+ return { paths: [], packageJsonPackageManager: packageManager };
329
400
  }
330
401
  function isSet(v) {
331
402
  return v?.constructor?.name === "Set";
@@ -338,7 +409,14 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
338
409
  (0, import_assert.default)(import_path.default.isAbsolute(destPath));
339
410
  try {
340
411
  await runNpmInstallSema.acquire();
341
- const { cliType, packageJsonPath, packageJson, lockfileVersion } = await scanParentDirs(destPath, true);
412
+ const {
413
+ cliType,
414
+ packageJsonPath,
415
+ packageJson,
416
+ lockfileVersion,
417
+ packageJsonPackageManager,
418
+ turboSupportsCorepackHome
419
+ } = await scanParentDirs(destPath, true);
342
420
  if (!packageJsonPath) {
343
421
  (0, import_debug.default)(
344
422
  `Skipping dependency installation because no package.json was found for ${destPath}`
@@ -367,10 +445,11 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
367
445
  opts.env = getEnvForPackageManager({
368
446
  cliType,
369
447
  lockfileVersion,
370
- packageJsonPackageManager: packageJson?.packageManager,
448
+ packageJsonPackageManager,
371
449
  nodeVersion,
372
450
  env,
373
- packageJsonEngines: packageJson?.engines
451
+ packageJsonEngines: packageJson?.engines,
452
+ turboSupportsCorepackHome
374
453
  });
375
454
  let commandArgs;
376
455
  const isPotentiallyBrokenNpm = cliType === "npm" && (nodeVersion?.major === 16 || opts.env.PATH?.includes("/node16/bin-npm7")) && !args.includes("--legacy-peer-deps") && spawnOpts?.env?.ENABLE_EXPERIMENTAL_COREPACK !== "1";
@@ -423,9 +502,14 @@ function getEnvForPackageManager({
423
502
  packageJsonPackageManager,
424
503
  nodeVersion,
425
504
  env,
426
- packageJsonEngines
505
+ packageJsonEngines,
506
+ turboSupportsCorepackHome
427
507
  }) {
428
- const corepackEnabled = usingCorepack(env, packageJsonPackageManager);
508
+ const corepackEnabled = usingCorepack(
509
+ env,
510
+ packageJsonPackageManager,
511
+ turboSupportsCorepackHome
512
+ );
429
513
  const {
430
514
  detectedLockfile,
431
515
  detectedPackageManager,
@@ -706,17 +790,21 @@ async function runCustomInstallCommand({
706
790
  spawnOpts
707
791
  }) {
708
792
  console.log(`Running "install" command: \`${installCommand}\`...`);
709
- const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
710
- destPath,
711
- true
712
- );
793
+ const {
794
+ cliType,
795
+ lockfileVersion,
796
+ packageJson,
797
+ packageJsonPackageManager,
798
+ turboSupportsCorepackHome
799
+ } = await scanParentDirs(destPath, true);
713
800
  const env = getEnvForPackageManager({
714
801
  cliType,
715
802
  lockfileVersion,
716
- packageJsonPackageManager: packageJson?.packageManager,
803
+ packageJsonPackageManager,
717
804
  nodeVersion,
718
805
  env: spawnOpts?.env || {},
719
- packageJsonEngines: packageJson?.engines
806
+ packageJsonEngines: packageJson?.engines,
807
+ turboSupportsCorepackHome
720
808
  });
721
809
  (0, import_debug.default)(`Running with $PATH:`, env?.PATH || "");
722
810
  await execCommand(installCommand, {
@@ -727,10 +815,13 @@ async function runCustomInstallCommand({
727
815
  }
728
816
  async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
729
817
  (0, import_assert.default)(import_path.default.isAbsolute(destPath));
730
- const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
731
- destPath,
732
- true
733
- );
818
+ const {
819
+ packageJson,
820
+ cliType,
821
+ lockfileVersion,
822
+ packageJsonPackageManager,
823
+ turboSupportsCorepackHome
824
+ } = await scanParentDirs(destPath, true);
734
825
  const scriptName = getScriptName(
735
826
  packageJson,
736
827
  typeof scriptNames === "string" ? [scriptNames] : scriptNames
@@ -745,10 +836,11 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
745
836
  env: getEnvForPackageManager({
746
837
  cliType,
747
838
  lockfileVersion,
748
- packageJsonPackageManager: packageJson?.packageManager,
839
+ packageJsonPackageManager,
749
840
  nodeVersion: void 0,
750
841
  env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
751
- packageJsonEngines: packageJson?.engines
842
+ packageJsonEngines: packageJson?.engines,
843
+ turboSupportsCorepackHome
752
844
  })
753
845
  };
754
846
  if (cliType === "npm") {
@@ -824,5 +916,6 @@ const installDependencies = (0, import_util.deprecate)(
824
916
  spawnAsync,
825
917
  spawnCommand,
826
918
  traverseUpDirectories,
919
+ usingCorepack,
827
920
  walkParentDirs
828
921
  });
package/dist/index.js CHANGED
@@ -11333,7 +11333,7 @@ var require_brace_expansion = __commonJS({
11333
11333
  function lte(i, y) {
11334
11334
  return i <= y;
11335
11335
  }
11336
- function gte(i, y) {
11336
+ function gte2(i, y) {
11337
11337
  return i >= y;
11338
11338
  }
11339
11339
  function expand(str, isTop) {
@@ -11379,7 +11379,7 @@ var require_brace_expansion = __commonJS({
11379
11379
  var reverse = y < x;
11380
11380
  if (reverse) {
11381
11381
  incr *= -1;
11382
- test = gte;
11382
+ test = gte2;
11383
11383
  }
11384
11384
  var pad = n.some(isPadded);
11385
11385
  N = [];
@@ -12510,7 +12510,7 @@ var require_brace_expansion2 = __commonJS({
12510
12510
  function lte(i, y) {
12511
12511
  return i <= y;
12512
12512
  }
12513
- function gte(i, y) {
12513
+ function gte2(i, y) {
12514
12514
  return i >= y;
12515
12515
  }
12516
12516
  function expand(str, isTop) {
@@ -12561,7 +12561,7 @@ var require_brace_expansion2 = __commonJS({
12561
12561
  var reverse = y < x;
12562
12562
  if (reverse) {
12563
12563
  incr *= -1;
12564
- test = gte;
12564
+ test = gte2;
12565
12565
  }
12566
12566
  var pad = n.some(isPadded);
12567
12567
  N = [];
@@ -15148,8 +15148,8 @@ var require_semver = __commonJS({
15148
15148
  function neq(a, b, loose) {
15149
15149
  return compare(a, b, loose) !== 0;
15150
15150
  }
15151
- exports2.gte = gte;
15152
- function gte(a, b, loose) {
15151
+ exports2.gte = gte2;
15152
+ function gte2(a, b, loose) {
15153
15153
  return compare(a, b, loose) >= 0;
15154
15154
  }
15155
15155
  exports2.lte = lte;
@@ -15180,7 +15180,7 @@ var require_semver = __commonJS({
15180
15180
  case ">":
15181
15181
  return gt(a, b, loose);
15182
15182
  case ">=":
15183
- return gte(a, b, loose);
15183
+ return gte2(a, b, loose);
15184
15184
  case "<":
15185
15185
  return lt(a, b, loose);
15186
15186
  case "<=":
@@ -15621,8 +15621,8 @@ var require_semver = __commonJS({
15621
15621
  });
15622
15622
  return min;
15623
15623
  }
15624
- exports2.minVersion = minVersion;
15625
- function minVersion(range, loose) {
15624
+ exports2.minVersion = minVersion2;
15625
+ function minVersion2(range, loose) {
15626
15626
  range = new Range(range, loose);
15627
15627
  var minver = new SemVer2("0.0.0");
15628
15628
  if (range.test(minver)) {
@@ -15695,7 +15695,7 @@ var require_semver = __commonJS({
15695
15695
  break;
15696
15696
  case "<":
15697
15697
  gtfn = lt;
15698
- ltefn = gte;
15698
+ ltefn = gte2;
15699
15699
  ltfn = gt;
15700
15700
  comp = "<";
15701
15701
  ecomp = "<=";
@@ -16417,8 +16417,8 @@ var require_semver2 = __commonJS({
16417
16417
  function neq(a, b, loose) {
16418
16418
  return compare(a, b, loose) !== 0;
16419
16419
  }
16420
- exports2.gte = gte;
16421
- function gte(a, b, loose) {
16420
+ exports2.gte = gte2;
16421
+ function gte2(a, b, loose) {
16422
16422
  return compare(a, b, loose) >= 0;
16423
16423
  }
16424
16424
  exports2.lte = lte;
@@ -16449,7 +16449,7 @@ var require_semver2 = __commonJS({
16449
16449
  case ">":
16450
16450
  return gt(a, b, loose);
16451
16451
  case ">=":
16452
- return gte(a, b, loose);
16452
+ return gte2(a, b, loose);
16453
16453
  case "<":
16454
16454
  return lt(a, b, loose);
16455
16455
  case "<=":
@@ -16918,8 +16918,8 @@ var require_semver2 = __commonJS({
16918
16918
  });
16919
16919
  return min;
16920
16920
  }
16921
- exports2.minVersion = minVersion;
16922
- function minVersion(range, loose) {
16921
+ exports2.minVersion = minVersion2;
16922
+ function minVersion2(range, loose) {
16923
16923
  range = new Range(range, loose);
16924
16924
  var minver = new SemVer2("0.0.0");
16925
16925
  if (range.test(minver)) {
@@ -16992,7 +16992,7 @@ var require_semver2 = __commonJS({
16992
16992
  break;
16993
16993
  case "<":
16994
16994
  gtfn = lt;
16995
- ltefn = gte;
16995
+ ltefn = gte2;
16996
16996
  ltfn = gt;
16997
16997
  comp = "<";
16998
16998
  ecomp = "<=";
@@ -23494,6 +23494,22 @@ function* traverseUpDirectories({
23494
23494
  current = next === current ? void 0 : next;
23495
23495
  }
23496
23496
  }
23497
+ async function readProjectRootInfo({
23498
+ start,
23499
+ base
23500
+ }) {
23501
+ let curRootPackageJsonPath;
23502
+ for (const dir of traverseUpDirectories({ start, base })) {
23503
+ const packageJsonPath = import_path5.default.join(dir, "package.json");
23504
+ if (await import_fs_extra7.default.pathExists(packageJsonPath)) {
23505
+ curRootPackageJsonPath = packageJsonPath;
23506
+ }
23507
+ }
23508
+ return curRootPackageJsonPath ? {
23509
+ packageJson: await import_fs_extra7.default.readJson(curRootPackageJsonPath),
23510
+ rootDir: import_path5.default.dirname(curRootPackageJsonPath)
23511
+ } : void 0;
23512
+ }
23497
23513
  async function getNodeBinPath({
23498
23514
  cwd
23499
23515
  }) {
@@ -23590,7 +23606,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
23590
23606
  filename: "package.json"
23591
23607
  });
23592
23608
  const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra7.default.readFile(pkgJsonPath, "utf8")) : void 0;
23593
- const [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
23609
+ const {
23610
+ paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
23611
+ packageJsonPackageManager
23612
+ } = await walkParentDirsMulti({
23594
23613
  base,
23595
23614
  start: destPath,
23596
23615
  filenames: [
@@ -23609,6 +23628,15 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
23609
23628
  pnpmLockPath ? readConfigFile(pnpmLockPath) : null,
23610
23629
  bunLockPath ? import_fs_extra7.default.readFile(bunLockPath, "utf8") : null
23611
23630
  ]);
23631
+ const rootProjectInfo = readPackageJson ? await readProjectRootInfo({
23632
+ base,
23633
+ start: destPath
23634
+ }) : void 0;
23635
+ const turboVersionRange = rootProjectInfo?.packageJson?.devDependencies?.turbo;
23636
+ const turboSupportsCorepackHome = turboVersionRange ? await checkTurboSupportsCorepack(
23637
+ turboVersionRange,
23638
+ rootProjectInfo?.rootDir
23639
+ ) : void 0;
23612
23640
  if (bunLockBin && hasYarnLock) {
23613
23641
  cliType = "bun";
23614
23642
  lockfilePath = bunLockPath;
@@ -23629,20 +23657,45 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
23629
23657
  lockfilePath = bunLockPath;
23630
23658
  lockfileVersion = 0;
23631
23659
  } else {
23632
- cliType = packageJson ? detectPackageManagerNameWithoutLockfile(packageJson) : "npm";
23660
+ cliType = detectPackageManagerNameWithoutLockfile(
23661
+ packageJsonPackageManager,
23662
+ turboSupportsCorepackHome
23663
+ );
23633
23664
  }
23634
23665
  const packageJsonPath = pkgJsonPath || void 0;
23635
23666
  return {
23636
23667
  cliType,
23637
23668
  packageJson,
23669
+ packageJsonPackageManager,
23638
23670
  lockfilePath,
23639
23671
  lockfileVersion,
23640
- packageJsonPath
23672
+ packageJsonPath,
23673
+ turboSupportsCorepackHome
23641
23674
  };
23642
23675
  }
23643
- function detectPackageManagerNameWithoutLockfile(packageJson) {
23644
- const packageJsonPackageManager = packageJson.packageManager;
23645
- if (usingCorepack(process.env, packageJsonPackageManager)) {
23676
+ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
23677
+ if (turboRangeSupportsCorepack(turboVersionRange)) {
23678
+ return true;
23679
+ }
23680
+ const turboJsonPath = import_path5.default.join(rootDir, "turbo.json");
23681
+ const turboJsonExists = await import_fs_extra7.default.pathExists(turboJsonPath);
23682
+ const turboJson = turboJsonExists ? JSON.parse(await import_fs_extra7.default.readFile(turboJsonPath, "utf8")) : void 0;
23683
+ return turboJson?.globalPassThroughEnv?.includes("COREPACK_HOME") || false;
23684
+ }
23685
+ function turboRangeSupportsCorepack(turboVersionRange) {
23686
+ const versionSupportingCorepack = "2.1.3";
23687
+ const minTurboBeingUsed = (0, import_semver2.minVersion)(turboVersionRange);
23688
+ if (!minTurboBeingUsed) {
23689
+ return false;
23690
+ }
23691
+ return (0, import_semver2.gte)(minTurboBeingUsed, versionSupportingCorepack);
23692
+ }
23693
+ function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
23694
+ if (usingCorepack(
23695
+ process.env,
23696
+ packageJsonPackageManager,
23697
+ turboSupportsCorepackHome
23698
+ )) {
23646
23699
  const corepackPackageManager = validateVersionSpecifier(
23647
23700
  packageJsonPackageManager
23648
23701
  );
@@ -23662,9 +23715,17 @@ function detectPackageManagerNameWithoutLockfile(packageJson) {
23662
23715
  }
23663
23716
  return "npm";
23664
23717
  }
23665
- function usingCorepack(env, packageJsonPackageManager) {
23666
- const corepackFlagged = env.ENABLE_EXPERIMENTAL_COREPACK === "1";
23667
- return corepackFlagged && Boolean(packageJsonPackageManager);
23718
+ function usingCorepack(env, packageJsonPackageManager, turboSupportsCorepackHome) {
23719
+ if (env.ENABLE_EXPERIMENTAL_COREPACK !== "1" || packageJsonPackageManager === void 0) {
23720
+ return false;
23721
+ }
23722
+ if (turboSupportsCorepackHome === false) {
23723
+ console.warn(
23724
+ "Warning: Disabling corepack because it may break your project. To use corepack, either upgrade to `turbo@2.1.3+` or include `COREPACK_HOME` in `turbo.json#globalPassThroughEnv`."
23725
+ );
23726
+ return false;
23727
+ }
23728
+ return true;
23668
23729
  }
23669
23730
  async function walkParentDirs({
23670
23731
  base,
@@ -23686,17 +23747,26 @@ async function walkParentDirsMulti({
23686
23747
  start,
23687
23748
  filenames
23688
23749
  }) {
23750
+ let packageManager;
23689
23751
  for (const dir of traverseUpDirectories({ start, base })) {
23690
23752
  const fullPaths = filenames.map((f) => import_path5.default.join(dir, f));
23691
23753
  const existResults = await Promise.all(
23692
23754
  fullPaths.map((f) => import_fs_extra7.default.pathExists(f))
23693
23755
  );
23694
23756
  const foundOneOrMore = existResults.some((b) => b);
23757
+ const packageJsonPath = import_path5.default.join(dir, "package.json");
23758
+ const packageJson = await import_fs_extra7.default.readJSON(packageJsonPath).catch(() => null);
23759
+ if (packageJson?.packageManager) {
23760
+ packageManager = packageJson.packageManager;
23761
+ }
23695
23762
  if (foundOneOrMore) {
23696
- return fullPaths.map((f, i) => existResults[i] ? f : void 0);
23763
+ return {
23764
+ paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
23765
+ packageJsonPackageManager: packageManager
23766
+ };
23697
23767
  }
23698
23768
  }
23699
- return [];
23769
+ return { paths: [], packageJsonPackageManager: packageManager };
23700
23770
  }
23701
23771
  function isSet(v) {
23702
23772
  return v?.constructor?.name === "Set";
@@ -23709,7 +23779,14 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
23709
23779
  (0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
23710
23780
  try {
23711
23781
  await runNpmInstallSema.acquire();
23712
- const { cliType, packageJsonPath, packageJson, lockfileVersion } = await scanParentDirs(destPath, true);
23782
+ const {
23783
+ cliType,
23784
+ packageJsonPath,
23785
+ packageJson,
23786
+ lockfileVersion,
23787
+ packageJsonPackageManager,
23788
+ turboSupportsCorepackHome
23789
+ } = await scanParentDirs(destPath, true);
23713
23790
  if (!packageJsonPath) {
23714
23791
  debug(
23715
23792
  `Skipping dependency installation because no package.json was found for ${destPath}`
@@ -23738,10 +23815,11 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
23738
23815
  opts.env = getEnvForPackageManager({
23739
23816
  cliType,
23740
23817
  lockfileVersion,
23741
- packageJsonPackageManager: packageJson?.packageManager,
23818
+ packageJsonPackageManager,
23742
23819
  nodeVersion,
23743
23820
  env,
23744
- packageJsonEngines: packageJson?.engines
23821
+ packageJsonEngines: packageJson?.engines,
23822
+ turboSupportsCorepackHome
23745
23823
  });
23746
23824
  let commandArgs;
23747
23825
  const isPotentiallyBrokenNpm = cliType === "npm" && (nodeVersion?.major === 16 || opts.env.PATH?.includes("/node16/bin-npm7")) && !args.includes("--legacy-peer-deps") && spawnOpts?.env?.ENABLE_EXPERIMENTAL_COREPACK !== "1";
@@ -23794,9 +23872,14 @@ function getEnvForPackageManager({
23794
23872
  packageJsonPackageManager,
23795
23873
  nodeVersion,
23796
23874
  env,
23797
- packageJsonEngines
23875
+ packageJsonEngines,
23876
+ turboSupportsCorepackHome
23798
23877
  }) {
23799
- const corepackEnabled = usingCorepack(env, packageJsonPackageManager);
23878
+ const corepackEnabled = usingCorepack(
23879
+ env,
23880
+ packageJsonPackageManager,
23881
+ turboSupportsCorepackHome
23882
+ );
23800
23883
  const {
23801
23884
  detectedLockfile,
23802
23885
  detectedPackageManager,
@@ -24077,17 +24160,21 @@ async function runCustomInstallCommand({
24077
24160
  spawnOpts
24078
24161
  }) {
24079
24162
  console.log(`Running "install" command: \`${installCommand}\`...`);
24080
- const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
24081
- destPath,
24082
- true
24083
- );
24163
+ const {
24164
+ cliType,
24165
+ lockfileVersion,
24166
+ packageJson,
24167
+ packageJsonPackageManager,
24168
+ turboSupportsCorepackHome
24169
+ } = await scanParentDirs(destPath, true);
24084
24170
  const env = getEnvForPackageManager({
24085
24171
  cliType,
24086
24172
  lockfileVersion,
24087
- packageJsonPackageManager: packageJson?.packageManager,
24173
+ packageJsonPackageManager,
24088
24174
  nodeVersion,
24089
24175
  env: spawnOpts?.env || {},
24090
- packageJsonEngines: packageJson?.engines
24176
+ packageJsonEngines: packageJson?.engines,
24177
+ turboSupportsCorepackHome
24091
24178
  });
24092
24179
  debug(`Running with $PATH:`, env?.PATH || "");
24093
24180
  await execCommand(installCommand, {
@@ -24098,10 +24185,13 @@ async function runCustomInstallCommand({
24098
24185
  }
24099
24186
  async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
24100
24187
  (0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
24101
- const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
24102
- destPath,
24103
- true
24104
- );
24188
+ const {
24189
+ packageJson,
24190
+ cliType,
24191
+ lockfileVersion,
24192
+ packageJsonPackageManager,
24193
+ turboSupportsCorepackHome
24194
+ } = await scanParentDirs(destPath, true);
24105
24195
  const scriptName = getScriptName(
24106
24196
  packageJson,
24107
24197
  typeof scriptNames === "string" ? [scriptNames] : scriptNames
@@ -24116,10 +24206,11 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
24116
24206
  env: getEnvForPackageManager({
24117
24207
  cliType,
24118
24208
  lockfileVersion,
24119
- packageJsonPackageManager: packageJson?.packageManager,
24209
+ packageJsonPackageManager,
24120
24210
  nodeVersion: void 0,
24121
24211
  env: cloneEnv(process.env, spawnOpts?.env),
24122
- packageJsonEngines: packageJson?.engines
24212
+ packageJsonEngines: packageJson?.engines,
24213
+ turboSupportsCorepackHome
24123
24214
  })
24124
24215
  };
24125
24216
  if (cliType === "npm") {
package/dist/types.d.ts CHANGED
@@ -367,9 +367,23 @@ export type RemotePattern = {
367
367
  */
368
368
  search?: string;
369
369
  };
370
+ export interface LocalPattern {
371
+ /**
372
+ * Can be literal or wildcard.
373
+ * Single `*` matches a single path segment.
374
+ * Double `**` matches any number of path segments.
375
+ */
376
+ pathname?: string;
377
+ /**
378
+ * Can be literal query string such as `?v=1` or
379
+ * empty string meaning no query string.
380
+ */
381
+ search?: string;
382
+ }
370
383
  export interface Images {
371
384
  domains: string[];
372
385
  remotePatterns?: RemotePattern[];
386
+ localPatterns?: LocalPattern[];
373
387
  sizes: number[];
374
388
  minimumCacheTTL?: number;
375
389
  formats?: ImageFormat[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "8.4.5",
3
+ "version": "8.4.7",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",