@vercel/build-utils 8.3.9 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 8.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Revert "Revert "Fix corepack `packageManager` detection on monorepos"" ([#11871](https://github.com/vercel/vercel/pull/11871))
8
+
9
+ ## 8.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Change warnings to errors in invalid corepack package manager states ([#12062](https://github.com/vercel/vercel/pull/12062))
14
+
3
15
  ## 8.3.9
4
16
 
5
17
  ### 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
  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 [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
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 = packageJson ? detectPackageManagerNameWithoutLockfile(packageJson) : "npm";
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(packageJson) {
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 fullPaths.map((f, i) => existResults[i] ? f : void 0);
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 { cliType, packageJsonPath, packageJson, lockfileVersion } = await scanParentDirs(destPath, true);
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: packageJson?.packageManager,
390
+ packageJsonPackageManager,
371
391
  nodeVersion,
372
392
  env,
373
393
  packageJsonEngines: packageJson?.engines
@@ -557,16 +577,14 @@ function validateCorepackPackageManager(cliType, lockfileVersion, corepackPackag
557
577
  corepackPackageManager
558
578
  );
559
579
  if (!validatedCorepackPackageManager) {
560
- console.warn(
561
- `WARN [package-manager-warning-2] Intended corepack defined package manager "${corepackPackageManager}" is not a valid semver value.`
580
+ throw new Error(
581
+ `Intended corepack defined package manager "${corepackPackageManager}" is not a valid semver value.`
562
582
  );
563
- return;
564
583
  }
565
584
  if (cliType !== validatedCorepackPackageManager.packageName) {
566
- console.warn(
567
- `WARN [package-manager-warning-3] Detected package manager "${cliType}" does not match intended corepack defined package manager "${validatedCorepackPackageManager.packageName}". Change your lockfile or "package.json#packageManager" value to match.`
585
+ throw new Error(
586
+ `Detected package manager "${cliType}" does not match intended corepack defined package manager "${validatedCorepackPackageManager.packageName}". Change your lockfile or "package.json#packageManager" value to match.`
568
587
  );
569
- return;
570
588
  }
571
589
  if (cliType === "pnpm" && enginesPnpmVersionRange) {
572
590
  const pnpmWithinEngineRange = (0, import_semver.satisfies)(
@@ -586,8 +604,8 @@ function validateCorepackPackageManager(cliType, lockfileVersion, corepackPackag
586
604
  validatedCorepackPackageManager.packageVersion
587
605
  );
588
606
  if (!lockfileValid) {
589
- console.warn(
590
- `WARN [package-manager-warning-1] Detected lockfile "${lockfileVersion}" which is not compatible with the intended corepack package manager "${corepackPackageManager}". Update your lockfile or change to a compatible corepack version.`
607
+ throw new Error(
608
+ `Detected lockfile "${lockfileVersion}" which is not compatible with the intended corepack package manager "${corepackPackageManager}". Update your lockfile or change to a compatible corepack version.`
591
609
  );
592
610
  }
593
611
  }
@@ -708,14 +726,11 @@ async function runCustomInstallCommand({
708
726
  spawnOpts
709
727
  }) {
710
728
  console.log(`Running "install" command: \`${installCommand}\`...`);
711
- const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
712
- destPath,
713
- true
714
- );
729
+ const { cliType, lockfileVersion, packageJsonPackageManager, packageJson } = await scanParentDirs(destPath);
715
730
  const env = getEnvForPackageManager({
716
731
  cliType,
717
732
  lockfileVersion,
718
- packageJsonPackageManager: packageJson?.packageManager,
733
+ packageJsonPackageManager,
719
734
  nodeVersion,
720
735
  env: spawnOpts?.env || {},
721
736
  packageJsonEngines: packageJson?.engines
@@ -729,10 +744,7 @@ async function runCustomInstallCommand({
729
744
  }
730
745
  async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
731
746
  (0, import_assert.default)(import_path.default.isAbsolute(destPath));
732
- const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
733
- destPath,
734
- true
735
- );
747
+ const { packageJson, cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath, true);
736
748
  const scriptName = getScriptName(
737
749
  packageJson,
738
750
  typeof scriptNames === "string" ? [scriptNames] : scriptNames
@@ -747,7 +759,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
747
759
  env: getEnvForPackageManager({
748
760
  cliType,
749
761
  lockfileVersion,
750
- packageJsonPackageManager: packageJson?.packageManager,
762
+ packageJsonPackageManager,
751
763
  nodeVersion: void 0,
752
764
  env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
753
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 [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
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 = packageJson ? detectPackageManagerNameWithoutLockfile(packageJson) : "npm";
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(packageJson) {
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 fullPaths.map((f, i) => existResults[i] ? f : void 0);
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 { cliType, packageJsonPath, packageJson, lockfileVersion } = await scanParentDirs(destPath, true);
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: packageJson?.packageManager,
22111
+ packageJsonPackageManager,
22092
22112
  nodeVersion,
22093
22113
  env,
22094
22114
  packageJsonEngines: packageJson?.engines
@@ -22278,16 +22298,14 @@ function validateCorepackPackageManager(cliType, lockfileVersion, corepackPackag
22278
22298
  corepackPackageManager
22279
22299
  );
22280
22300
  if (!validatedCorepackPackageManager) {
22281
- console.warn(
22282
- `WARN [package-manager-warning-2] Intended corepack defined package manager "${corepackPackageManager}" is not a valid semver value.`
22301
+ throw new Error(
22302
+ `Intended corepack defined package manager "${corepackPackageManager}" is not a valid semver value.`
22283
22303
  );
22284
- return;
22285
22304
  }
22286
22305
  if (cliType !== validatedCorepackPackageManager.packageName) {
22287
- console.warn(
22288
- `WARN [package-manager-warning-3] Detected package manager "${cliType}" does not match intended corepack defined package manager "${validatedCorepackPackageManager.packageName}". Change your lockfile or "package.json#packageManager" value to match.`
22306
+ throw new Error(
22307
+ `Detected package manager "${cliType}" does not match intended corepack defined package manager "${validatedCorepackPackageManager.packageName}". Change your lockfile or "package.json#packageManager" value to match.`
22289
22308
  );
22290
- return;
22291
22309
  }
22292
22310
  if (cliType === "pnpm" && enginesPnpmVersionRange) {
22293
22311
  const pnpmWithinEngineRange = (0, import_semver2.satisfies)(
@@ -22307,8 +22325,8 @@ function validateCorepackPackageManager(cliType, lockfileVersion, corepackPackag
22307
22325
  validatedCorepackPackageManager.packageVersion
22308
22326
  );
22309
22327
  if (!lockfileValid) {
22310
- console.warn(
22311
- `WARN [package-manager-warning-1] Detected lockfile "${lockfileVersion}" which is not compatible with the intended corepack package manager "${corepackPackageManager}". Update your lockfile or change to a compatible corepack version.`
22328
+ throw new Error(
22329
+ `Detected lockfile "${lockfileVersion}" which is not compatible with the intended corepack package manager "${corepackPackageManager}". Update your lockfile or change to a compatible corepack version.`
22312
22330
  );
22313
22331
  }
22314
22332
  }
@@ -22429,14 +22447,11 @@ async function runCustomInstallCommand({
22429
22447
  spawnOpts
22430
22448
  }) {
22431
22449
  console.log(`Running "install" command: \`${installCommand}\`...`);
22432
- const { cliType, lockfileVersion, packageJson } = await scanParentDirs(
22433
- destPath,
22434
- true
22435
- );
22450
+ const { cliType, lockfileVersion, packageJsonPackageManager, packageJson } = await scanParentDirs(destPath);
22436
22451
  const env = getEnvForPackageManager({
22437
22452
  cliType,
22438
22453
  lockfileVersion,
22439
- packageJsonPackageManager: packageJson?.packageManager,
22454
+ packageJsonPackageManager,
22440
22455
  nodeVersion,
22441
22456
  env: spawnOpts?.env || {},
22442
22457
  packageJsonEngines: packageJson?.engines
@@ -22450,10 +22465,7 @@ async function runCustomInstallCommand({
22450
22465
  }
22451
22466
  async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
22452
22467
  (0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
22453
- const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
22454
- destPath,
22455
- true
22456
- );
22468
+ const { packageJson, cliType, lockfileVersion, packageJsonPackageManager } = await scanParentDirs(destPath, true);
22457
22469
  const scriptName = getScriptName(
22458
22470
  packageJson,
22459
22471
  typeof scriptNames === "string" ? [scriptNames] : scriptNames
@@ -22468,7 +22480,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
22468
22480
  env: getEnvForPackageManager({
22469
22481
  cliType,
22470
22482
  lockfileVersion,
22471
- packageJsonPackageManager: packageJson?.packageManager,
22483
+ packageJsonPackageManager,
22472
22484
  nodeVersion: void 0,
22473
22485
  env: cloneEnv(process.env, spawnOpts?.env),
22474
22486
  packageJsonEngines: packageJson?.engines
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "8.3.9",
3
+ "version": "8.4.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",