@vercel/build-utils 8.7.0 → 9.0.0

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,23 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 9.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Change getPathOverrideForPackageManager() to use detectedLockfile argument ([#12813](https://github.com/vercel/vercel/pull/12813))
8
+
9
+ ### Patch Changes
10
+
11
+ - Refactor build-util usage to reuse detected lockfile ([#12813](https://github.com/vercel/vercel/pull/12813))
12
+
13
+ - add support for `images.qualities` ([#12813](https://github.com/vercel/vercel/pull/12813))
14
+
15
+ ## 8.8.0
16
+
17
+ ### Minor Changes
18
+
19
+ - Add bun detection using bun.lock ([#12740](https://github.com/vercel/vercel/pull/12740))
20
+
3
21
  ## 8.7.0
4
22
 
5
23
  ### Minor Changes
@@ -37,6 +37,11 @@ export interface ScanParentDirsResult {
37
37
  * `undefined` if not a Turborepo project.
38
38
  */
39
39
  turboSupportsCorepackHome?: boolean;
40
+ /**
41
+ * Name of the lockfile (`yarn.lock`, `package-lock.json`, ...) detected
42
+ * or `undefined` if no lockfile was detected.
43
+ */
44
+ detectedLockfile?: string;
40
45
  }
41
46
  export interface TraverseUpDirectoriesProps {
42
47
  /**
@@ -97,7 +102,7 @@ export declare function runNpmInstall(destPath: string, args?: string[], spawnOp
97
102
  * Prepares the input environment based on the used package manager and lockfile
98
103
  * versions.
99
104
  */
100
- export declare function getEnvForPackageManager({ cliType, lockfileVersion, packageJsonPackageManager, nodeVersion, env, packageJsonEngines, turboSupportsCorepackHome, }: {
105
+ export declare function getEnvForPackageManager({ cliType, lockfileVersion, packageJsonPackageManager, nodeVersion, env, packageJsonEngines, turboSupportsCorepackHome, detectedLockfile, }: {
101
106
  cliType: CliType;
102
107
  lockfileVersion: number | undefined;
103
108
  packageJsonPackageManager?: string | undefined;
@@ -107,6 +112,7 @@ export declare function getEnvForPackageManager({ cliType, lockfileVersion, pack
107
112
  };
108
113
  packageJsonEngines?: PackageJson.Engines;
109
114
  turboSupportsCorepackHome?: boolean | undefined;
115
+ detectedLockfile: string | undefined;
110
116
  }): {
111
117
  [x: string]: string | undefined;
112
118
  };
@@ -114,13 +120,14 @@ export declare function getEnvForPackageManager({ cliType, lockfileVersion, pack
114
120
  * Helper to get the binary paths that link to the used package manager.
115
121
  * Note: Make sure it doesn't contain any `console.log` calls.
116
122
  */
117
- export declare function getPathOverrideForPackageManager({ cliType, lockfileVersion, corepackPackageManager, corepackEnabled, packageJsonEngines, }: {
123
+ export declare function getPathOverrideForPackageManager({ cliType, lockfileVersion, corepackPackageManager, corepackEnabled, packageJsonEngines, detectedLockfile, }: {
118
124
  cliType: CliType;
119
125
  lockfileVersion: number | undefined;
120
126
  corepackPackageManager: string | undefined;
121
127
  nodeVersion: NodeVersion | undefined;
122
128
  corepackEnabled?: boolean;
123
129
  packageJsonEngines?: PackageJson.Engines;
130
+ detectedLockfile?: string;
124
131
  }): {
125
132
  /**
126
133
  * Which lockfile was detected.
@@ -136,24 +143,24 @@ export declare function getPathOverrideForPackageManager({ cliType, lockfileVers
136
143
  */
137
144
  path: string | undefined;
138
145
  };
139
- export declare function detectPackageManager(cliType: CliType, lockfileVersion: number | undefined): {
146
+ export declare function detectPackageManager(cliType: CliType, lockfileVersion: number | undefined, detectedLockfile: string | undefined): {
140
147
  path: string;
141
- detectedLockfile: string;
148
+ detectedLockfile: string | undefined;
142
149
  detectedPackageManager: string;
143
150
  pnpmVersionRange: string;
144
151
  } | {
145
152
  path: undefined;
146
- detectedLockfile: string;
153
+ detectedLockfile: string | undefined;
147
154
  detectedPackageManager: string;
148
155
  pnpmVersionRange: string;
149
156
  } | {
150
157
  path: string;
151
- detectedLockfile: string;
158
+ detectedLockfile: string | undefined;
152
159
  detectedPackageManager: string;
153
160
  pnpmVersionRange?: undefined;
154
161
  } | {
155
162
  path: undefined;
156
- detectedLockfile: string;
163
+ detectedLockfile: string | undefined;
157
164
  detectedPackageManager: string;
158
165
  pnpmVersionRange?: undefined;
159
166
  } | undefined;
@@ -162,13 +169,14 @@ export declare function detectPackageManager(cliType: CliType, lockfileVersion:
162
169
  * Note: Make sure it doesn't contain any `console.log` calls.
163
170
  * @deprecated use `getEnvForPackageManager` instead
164
171
  */
165
- export declare function getPathForPackageManager({ cliType, lockfileVersion, nodeVersion, env, }: {
172
+ export declare function getPathForPackageManager({ cliType, lockfileVersion, nodeVersion, env, detectedLockfile, }: {
166
173
  cliType: CliType;
167
174
  lockfileVersion: number | undefined;
168
175
  nodeVersion: NodeVersion | undefined;
169
176
  env: {
170
177
  [x: string]: string | undefined;
171
178
  };
179
+ detectedLockfile: string;
172
180
  }): {
173
181
  /**
174
182
  * Which lockfile was detected.
@@ -239,7 +239,13 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
239
239
  });
240
240
  const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
241
241
  const {
242
- paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
242
+ paths: [
243
+ yarnLockPath,
244
+ npmLockPath,
245
+ pnpmLockPath,
246
+ bunLockTextPath,
247
+ bunLockBinPath
248
+ ],
243
249
  packageJsonPackageManager
244
250
  } = await walkParentDirsMulti({
245
251
  base,
@@ -248,17 +254,19 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
248
254
  "yarn.lock",
249
255
  "package-lock.json",
250
256
  "pnpm-lock.yaml",
257
+ "bun.lock",
251
258
  "bun.lockb"
252
259
  ]
253
260
  });
254
261
  let lockfilePath;
255
262
  let lockfileVersion;
256
263
  let cliType;
257
- const [hasYarnLock, packageLockJson, pnpmLockYaml, bunLockBin] = await Promise.all([
264
+ const bunLockPath = bunLockTextPath ?? bunLockBinPath;
265
+ const [hasYarnLock, packageLockJson, pnpmLockYaml, bunLock] = await Promise.all([
258
266
  Boolean(yarnLockPath),
259
267
  npmLockPath ? (0, import_read_config_file.readConfigFile)(npmLockPath) : null,
260
268
  pnpmLockPath ? (0, import_read_config_file.readConfigFile)(pnpmLockPath) : null,
261
- bunLockPath ? import_fs_extra.default.readFile(bunLockPath, "utf8") : null
269
+ bunLockPath ? import_fs_extra.default.readFile(bunLockPath) : null
262
270
  ]);
263
271
  const rootProjectInfo = readPackageJson ? await readProjectRootInfo({
264
272
  base,
@@ -269,10 +277,9 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
269
277
  turboVersionRange,
270
278
  rootProjectInfo?.rootDir
271
279
  ) : void 0;
272
- if (bunLockBin && hasYarnLock) {
280
+ if (bunLock && hasYarnLock) {
273
281
  cliType = "bun";
274
282
  lockfilePath = bunLockPath;
275
- lockfileVersion = 0;
276
283
  } else if (hasYarnLock) {
277
284
  cliType = "yarn";
278
285
  lockfilePath = yarnLockPath;
@@ -284,10 +291,9 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
284
291
  cliType = "npm";
285
292
  lockfilePath = npmLockPath;
286
293
  lockfileVersion = packageLockJson.lockfileVersion;
287
- } else if (bunLockBin) {
294
+ } else if (bunLock) {
288
295
  cliType = "bun";
289
296
  lockfilePath = bunLockPath;
290
- lockfileVersion = 0;
291
297
  } else {
292
298
  cliType = detectPackageManagerNameWithoutLockfile(
293
299
  packageJsonPackageManager,
@@ -302,7 +308,8 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
302
308
  lockfilePath,
303
309
  lockfileVersion,
304
310
  packageJsonPath,
305
- turboSupportsCorepackHome
311
+ turboSupportsCorepackHome,
312
+ detectedLockfile: lockfilePath ? import_path.default.basename(lockfilePath) : void 0
306
313
  };
307
314
  }
308
315
  async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
@@ -428,7 +435,8 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
428
435
  packageJson,
429
436
  lockfileVersion,
430
437
  packageJsonPackageManager,
431
- turboSupportsCorepackHome
438
+ turboSupportsCorepackHome,
439
+ detectedLockfile
432
440
  } = await scanParentDirs(destPath, true);
433
441
  if (!packageJsonPath) {
434
442
  (0, import_debug.default)(
@@ -462,7 +470,8 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
462
470
  nodeVersion,
463
471
  env,
464
472
  packageJsonEngines: packageJson?.engines,
465
- turboSupportsCorepackHome
473
+ turboSupportsCorepackHome,
474
+ detectedLockfile
466
475
  });
467
476
  let commandArgs;
468
477
  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";
@@ -516,24 +525,22 @@ function getEnvForPackageManager({
516
525
  nodeVersion,
517
526
  env,
518
527
  packageJsonEngines,
519
- turboSupportsCorepackHome
528
+ turboSupportsCorepackHome,
529
+ detectedLockfile
520
530
  }) {
521
531
  const corepackEnabled = usingCorepack(
522
532
  env,
523
533
  packageJsonPackageManager,
524
534
  turboSupportsCorepackHome
525
535
  );
526
- const {
527
- detectedLockfile,
528
- detectedPackageManager,
529
- path: newPath
530
- } = getPathOverrideForPackageManager({
536
+ const { detectedPackageManager, path: newPath } = getPathOverrideForPackageManager({
531
537
  cliType,
532
538
  lockfileVersion,
533
539
  corepackPackageManager: packageJsonPackageManager,
534
540
  nodeVersion,
535
541
  corepackEnabled,
536
- packageJsonEngines
542
+ packageJsonEngines,
543
+ detectedLockfile
537
544
  });
538
545
  if (corepackEnabled) {
539
546
  (0, import_debug.default)(
@@ -617,9 +624,14 @@ function getPathOverrideForPackageManager({
617
624
  lockfileVersion,
618
625
  corepackPackageManager,
619
626
  corepackEnabled = true,
620
- packageJsonEngines
627
+ packageJsonEngines,
628
+ detectedLockfile
621
629
  }) {
622
- const detectedPackageManger = detectPackageManager(cliType, lockfileVersion);
630
+ const detectedPackageManger = detectPackageManager(
631
+ cliType,
632
+ lockfileVersion,
633
+ detectedLockfile
634
+ );
623
635
  if (!corepackPackageManager || !corepackEnabled) {
624
636
  if (cliType === "pnpm" && packageJsonEngines?.pnpm) {
625
637
  checkEnginesPnpmAgainstDetected(
@@ -710,7 +722,7 @@ function validateVersionSpecifier(version) {
710
722
  packageVersion
711
723
  };
712
724
  }
713
- function detectPackageManager(cliType, lockfileVersion) {
725
+ function detectPackageManager(cliType, lockfileVersion, detectedLockfile) {
714
726
  switch (cliType) {
715
727
  case "npm":
716
728
  return void 0;
@@ -719,21 +731,21 @@ function detectPackageManager(cliType, lockfileVersion) {
719
731
  case "pnpm 7":
720
732
  return {
721
733
  path: "/pnpm7/node_modules/.bin",
722
- detectedLockfile: "pnpm-lock.yaml",
734
+ detectedLockfile,
723
735
  detectedPackageManager: "pnpm@7.x",
724
736
  pnpmVersionRange: "7.x"
725
737
  };
726
738
  case "pnpm 8":
727
739
  return {
728
740
  path: "/pnpm8/node_modules/.bin",
729
- detectedLockfile: "pnpm-lock.yaml",
741
+ detectedLockfile,
730
742
  detectedPackageManager: "pnpm@8.x",
731
743
  pnpmVersionRange: "8.x"
732
744
  };
733
745
  case "pnpm 9":
734
746
  return {
735
747
  path: "/pnpm9/node_modules/.bin",
736
- detectedLockfile: "pnpm-lock.yaml",
748
+ detectedLockfile,
737
749
  detectedPackageManager: "pnpm@9.x",
738
750
  pnpmVersionRange: "9.x"
739
751
  };
@@ -741,7 +753,7 @@ function detectPackageManager(cliType, lockfileVersion) {
741
753
  return {
742
754
  // undefined because pnpm@6 is the current default in the build container
743
755
  path: void 0,
744
- detectedLockfile: "pnpm-lock.yaml",
756
+ detectedLockfile,
745
757
  detectedPackageManager: "pnpm@6.x",
746
758
  pnpmVersionRange: "6.x"
747
759
  };
@@ -751,13 +763,13 @@ function detectPackageManager(cliType, lockfileVersion) {
751
763
  case "bun":
752
764
  return {
753
765
  path: "/bun1",
754
- detectedLockfile: "bun.lockb",
766
+ detectedLockfile,
755
767
  detectedPackageManager: "bun@1.x"
756
768
  };
757
769
  case "yarn":
758
770
  return {
759
771
  path: void 0,
760
- detectedLockfile: "yarn.lock",
772
+ detectedLockfile,
761
773
  detectedPackageManager: "yarn"
762
774
  };
763
775
  }
@@ -766,14 +778,16 @@ function getPathForPackageManager({
766
778
  cliType,
767
779
  lockfileVersion,
768
780
  nodeVersion,
769
- env
781
+ env,
782
+ detectedLockfile
770
783
  }) {
771
784
  const corepackEnabled = env.ENABLE_EXPERIMENTAL_COREPACK === "1";
772
785
  let overrides = getPathOverrideForPackageManager({
773
786
  cliType,
774
787
  lockfileVersion,
775
788
  corepackPackageManager: void 0,
776
- nodeVersion
789
+ nodeVersion,
790
+ detectedLockfile
777
791
  });
778
792
  if (corepackEnabled) {
779
793
  overrides = NO_OVERRIDE;
@@ -808,7 +822,8 @@ async function runCustomInstallCommand({
808
822
  lockfileVersion,
809
823
  packageJson,
810
824
  packageJsonPackageManager,
811
- turboSupportsCorepackHome
825
+ turboSupportsCorepackHome,
826
+ detectedLockfile
812
827
  } = await scanParentDirs(destPath, true);
813
828
  const env = getEnvForPackageManager({
814
829
  cliType,
@@ -817,7 +832,8 @@ async function runCustomInstallCommand({
817
832
  nodeVersion,
818
833
  env: spawnOpts?.env || {},
819
834
  packageJsonEngines: packageJson?.engines,
820
- turboSupportsCorepackHome
835
+ turboSupportsCorepackHome,
836
+ detectedLockfile
821
837
  });
822
838
  (0, import_debug.default)(`Running with $PATH:`, env?.PATH || "");
823
839
  await execCommand(installCommand, {
@@ -833,7 +849,8 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
833
849
  cliType,
834
850
  lockfileVersion,
835
851
  packageJsonPackageManager,
836
- turboSupportsCorepackHome
852
+ turboSupportsCorepackHome,
853
+ detectedLockfile
837
854
  } = await scanParentDirs(destPath, true);
838
855
  const scriptName = getScriptName(
839
856
  packageJson,
@@ -853,7 +870,8 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
853
870
  nodeVersion: void 0,
854
871
  env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
855
872
  packageJsonEngines: packageJson?.engines,
856
- turboSupportsCorepackHome
873
+ turboSupportsCorepackHome,
874
+ detectedLockfile
857
875
  })
858
876
  };
859
877
  if (cliType === "npm") {