@vercel/build-utils 10.3.0 → 10.3.2

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
+ ## 10.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Add support for expire values in Next.js prerender manifest ([#13087](https://github.com/vercel/vercel/pull/13087))
8
+
9
+ - Detect yarn version from lockfile version ([#13118](https://github.com/vercel/vercel/pull/13118))
10
+
11
+ ## 10.3.1
12
+
13
+ ### Patch Changes
14
+
15
+ - Parse yarn.lock file version ([#13114](https://github.com/vercel/vercel/pull/13114))
16
+
17
+ - [env-vars] expose VERCEL_DEPLOYMENT_ID as NEXT_PUBLIC_VERCEL_DEPLOYMENT_ID ([#13115](https://github.com/vercel/vercel/pull/13115))
18
+
19
+ - Fix vitest-e2e glob to include integration.test.ts ([#13097](https://github.com/vercel/vercel/pull/13097))
20
+
3
21
  ## 10.3.0
4
22
 
5
23
  ### Minor Changes
@@ -68,6 +68,7 @@ var import_node_version = require("./node-version");
68
68
  var import_read_config_file = require("./read-config-file");
69
69
  var import_clone_env = require("../clone-env");
70
70
  var import_json5 = __toESM(require("json5"));
71
+ var import_js_yaml = __toESM(require("js-yaml"));
71
72
  const NO_OVERRIDE = {
72
73
  detectedLockfile: void 0,
73
74
  detectedPackageManager: void 0,
@@ -263,11 +264,11 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
263
264
  let lockfileVersion;
264
265
  let cliType;
265
266
  const bunLockPath = bunLockTextPath ?? bunLockBinPath;
266
- const [hasYarnLock, packageLockJson, pnpmLockYaml, bunLock] = await Promise.all([
267
- Boolean(yarnLockPath),
267
+ const [packageLockJson, pnpmLockYaml, bunLock, yarnLock] = await Promise.all([
268
268
  npmLockPath ? (0, import_read_config_file.readConfigFile)(npmLockPath) : null,
269
269
  pnpmLockPath ? (0, import_read_config_file.readConfigFile)(pnpmLockPath) : null,
270
- bunLockPath ? import_fs_extra.default.readFile(bunLockPath) : null
270
+ bunLockPath ? import_fs_extra.default.readFile(bunLockPath) : null,
271
+ yarnLockPath ? import_fs_extra.default.readFile(yarnLockPath, "utf8") : null
271
272
  ]);
272
273
  const rootProjectInfo = readPackageJson ? await readProjectRootInfo({
273
274
  base,
@@ -278,13 +279,14 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
278
279
  turboVersionRange,
279
280
  rootProjectInfo?.rootDir
280
281
  ) : void 0;
281
- if (bunLock && hasYarnLock) {
282
+ if (bunLock && yarnLock) {
282
283
  cliType = "bun";
283
284
  lockfilePath = bunLockPath;
284
285
  lockfileVersion = bunLockTextPath ? 1 : 0;
285
- } else if (hasYarnLock) {
286
+ } else if (yarnLock) {
286
287
  cliType = "yarn";
287
288
  lockfilePath = yarnLockPath;
289
+ lockfileVersion = parseYarnLockVersion(yarnLock);
288
290
  } else if (pnpmLockYaml) {
289
291
  cliType = "pnpm";
290
292
  lockfilePath = pnpmLockPath;
@@ -314,6 +316,17 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
314
316
  turboSupportsCorepackHome
315
317
  };
316
318
  }
319
+ function parseYarnLockVersion(yarnLock) {
320
+ if (!yarnLock.includes("__metadata:")) {
321
+ return 1;
322
+ }
323
+ try {
324
+ const metadata = import_js_yaml.default.load(yarnLock).__metadata;
325
+ return Number(metadata.version);
326
+ } catch {
327
+ return void 0;
328
+ }
329
+ }
317
330
  async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
318
331
  if (turboVersionSpecifierSupportsCorepack(turboVersionRange)) {
319
332
  return true;
@@ -636,6 +649,20 @@ function detectPnpmVersion(lockfileVersion, projectCreatedAt) {
636
649
  return "not found";
637
650
  }
638
651
  }
652
+ function detectYarnVersion(lockfileVersion) {
653
+ if (lockfileVersion) {
654
+ if ([1].includes(lockfileVersion)) {
655
+ return "yarn@1.x";
656
+ } else if ([4, 5].includes(lockfileVersion)) {
657
+ return "yarn@2.x";
658
+ } else if ([6, 7].includes(lockfileVersion)) {
659
+ return "yarn@3.x";
660
+ } else if ([8].includes(lockfileVersion)) {
661
+ return "yarn@4.x";
662
+ }
663
+ }
664
+ return "unknown yarn";
665
+ }
639
666
  function validLockfileForPackageManager(cliType, lockfileVersion, packageManagerVersion) {
640
667
  const packageManagerMajorVersion = packageManagerVersion.major;
641
668
  switch (cliType) {
@@ -825,7 +852,7 @@ function detectPackageManager(cliType, lockfileVersion, projectCreatedAt) {
825
852
  return {
826
853
  path: void 0,
827
854
  detectedLockfile: "yarn.lock",
828
- detectedPackageManager: "yarn"
855
+ detectedPackageManager: detectYarnVersion(lockfileVersion)
829
856
  };
830
857
  }
831
858
  }
@@ -32,7 +32,8 @@ function getPrefixedEnvVars({
32
32
  "VERCEL_TARGET_ENV",
33
33
  "VERCEL_REGION",
34
34
  "VERCEL_BRANCH_URL",
35
- "VERCEL_PROJECT_PRODUCTION_URL"
35
+ "VERCEL_PROJECT_PRODUCTION_URL",
36
+ "VERCEL_DEPLOYMENT_ID"
36
37
  ];
37
38
  const newEnvs = {};
38
39
  if (envPrefix && envs.VERCEL_URL) {
package/dist/index.js CHANGED
@@ -18333,8 +18333,8 @@ var require_js_yaml = __commonJS({
18333
18333
  var require_js_yaml2 = __commonJS({
18334
18334
  "../../node_modules/.pnpm/js-yaml@3.13.1/node_modules/js-yaml/index.js"(exports2, module2) {
18335
18335
  "use strict";
18336
- var yaml2 = require_js_yaml();
18337
- module2.exports = yaml2;
18336
+ var yaml3 = require_js_yaml();
18337
+ module2.exports = yaml3;
18338
18338
  }
18339
18339
  });
18340
18340
 
@@ -22604,6 +22604,7 @@ var NodejsLambda = class extends Lambda {
22604
22604
  var Prerender = class {
22605
22605
  constructor({
22606
22606
  expiration,
22607
+ staleExpiration,
22607
22608
  lambda,
22608
22609
  fallback,
22609
22610
  group,
@@ -22620,6 +22621,7 @@ var Prerender = class {
22620
22621
  }) {
22621
22622
  this.type = "Prerender";
22622
22623
  this.expiration = expiration;
22624
+ this.staleExpiration = staleExpiration;
22623
22625
  this.sourcePath = sourcePath;
22624
22626
  this.lambda = lambda;
22625
22627
  if (this.lambda) {
@@ -23080,6 +23082,7 @@ function cloneEnv(...envs) {
23080
23082
 
23081
23083
  // src/fs/run-user-scripts.ts
23082
23084
  var import_json5 = __toESM(require_lib5());
23085
+ var import_js_yaml2 = __toESM(require_js_yaml2());
23083
23086
  var NO_OVERRIDE = {
23084
23087
  detectedLockfile: void 0,
23085
23088
  detectedPackageManager: void 0,
@@ -23275,11 +23278,11 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
23275
23278
  let lockfileVersion;
23276
23279
  let cliType;
23277
23280
  const bunLockPath = bunLockTextPath ?? bunLockBinPath;
23278
- const [hasYarnLock, packageLockJson, pnpmLockYaml, bunLock] = await Promise.all([
23279
- Boolean(yarnLockPath),
23281
+ const [packageLockJson, pnpmLockYaml, bunLock, yarnLock] = await Promise.all([
23280
23282
  npmLockPath ? readConfigFile(npmLockPath) : null,
23281
23283
  pnpmLockPath ? readConfigFile(pnpmLockPath) : null,
23282
- bunLockPath ? import_fs_extra7.default.readFile(bunLockPath) : null
23284
+ bunLockPath ? import_fs_extra7.default.readFile(bunLockPath) : null,
23285
+ yarnLockPath ? import_fs_extra7.default.readFile(yarnLockPath, "utf8") : null
23283
23286
  ]);
23284
23287
  const rootProjectInfo = readPackageJson ? await readProjectRootInfo({
23285
23288
  base,
@@ -23290,13 +23293,14 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
23290
23293
  turboVersionRange,
23291
23294
  rootProjectInfo?.rootDir
23292
23295
  ) : void 0;
23293
- if (bunLock && hasYarnLock) {
23296
+ if (bunLock && yarnLock) {
23294
23297
  cliType = "bun";
23295
23298
  lockfilePath = bunLockPath;
23296
23299
  lockfileVersion = bunLockTextPath ? 1 : 0;
23297
- } else if (hasYarnLock) {
23300
+ } else if (yarnLock) {
23298
23301
  cliType = "yarn";
23299
23302
  lockfilePath = yarnLockPath;
23303
+ lockfileVersion = parseYarnLockVersion(yarnLock);
23300
23304
  } else if (pnpmLockYaml) {
23301
23305
  cliType = "pnpm";
23302
23306
  lockfilePath = pnpmLockPath;
@@ -23326,6 +23330,17 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
23326
23330
  turboSupportsCorepackHome
23327
23331
  };
23328
23332
  }
23333
+ function parseYarnLockVersion(yarnLock) {
23334
+ if (!yarnLock.includes("__metadata:")) {
23335
+ return 1;
23336
+ }
23337
+ try {
23338
+ const metadata = import_js_yaml2.default.load(yarnLock).__metadata;
23339
+ return Number(metadata.version);
23340
+ } catch {
23341
+ return void 0;
23342
+ }
23343
+ }
23329
23344
  async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
23330
23345
  if (turboVersionSpecifierSupportsCorepack(turboVersionRange)) {
23331
23346
  return true;
@@ -23648,6 +23663,20 @@ function detectPnpmVersion(lockfileVersion, projectCreatedAt) {
23648
23663
  return "not found";
23649
23664
  }
23650
23665
  }
23666
+ function detectYarnVersion(lockfileVersion) {
23667
+ if (lockfileVersion) {
23668
+ if ([1].includes(lockfileVersion)) {
23669
+ return "yarn@1.x";
23670
+ } else if ([4, 5].includes(lockfileVersion)) {
23671
+ return "yarn@2.x";
23672
+ } else if ([6, 7].includes(lockfileVersion)) {
23673
+ return "yarn@3.x";
23674
+ } else if ([8].includes(lockfileVersion)) {
23675
+ return "yarn@4.x";
23676
+ }
23677
+ }
23678
+ return "unknown yarn";
23679
+ }
23651
23680
  function validLockfileForPackageManager(cliType, lockfileVersion, packageManagerVersion) {
23652
23681
  const packageManagerMajorVersion = packageManagerVersion.major;
23653
23682
  switch (cliType) {
@@ -23837,7 +23866,7 @@ function detectPackageManager(cliType, lockfileVersion, projectCreatedAt) {
23837
23866
  return {
23838
23867
  path: void 0,
23839
23868
  detectedLockfile: "yarn.lock",
23840
- detectedPackageManager: "yarn"
23869
+ detectedPackageManager: detectYarnVersion(lockfileVersion)
23841
23870
  };
23842
23871
  }
23843
23872
  }
@@ -24060,7 +24089,8 @@ function getPrefixedEnvVars({
24060
24089
  "VERCEL_TARGET_ENV",
24061
24090
  "VERCEL_REGION",
24062
24091
  "VERCEL_BRANCH_URL",
24063
- "VERCEL_PROJECT_PRODUCTION_URL"
24092
+ "VERCEL_PROJECT_PRODUCTION_URL",
24093
+ "VERCEL_DEPLOYMENT_ID"
24064
24094
  ];
24065
24095
  const newEnvs = {};
24066
24096
  if (envPrefix && envs.VERCEL_URL) {
@@ -2,6 +2,7 @@ import type { File, HasField, Chain } from './types';
2
2
  import { Lambda } from './lambda';
3
3
  interface PrerenderOptions {
4
4
  expiration: number | false;
5
+ staleExpiration?: number;
5
6
  lambda?: Lambda;
6
7
  fallback: File | null;
7
8
  group?: number;
@@ -18,7 +19,17 @@ interface PrerenderOptions {
18
19
  }
19
20
  export declare class Prerender {
20
21
  type: 'Prerender';
22
+ /**
23
+ * `expiration` is `revalidate` in Next.js terms, and `s-maxage` in
24
+ * `cache-control` terms.
25
+ */
21
26
  expiration: number | false;
27
+ /**
28
+ * `staleExpiration` is `expire` in Next.js terms, and
29
+ * `stale-while-revalidate` + `s-maxage` in `cache-control` terms. It's
30
+ * expected to be undefined if `expiration` is `false`.
31
+ */
32
+ staleExpiration?: number;
22
33
  lambda?: Lambda;
23
34
  fallback: File | null;
24
35
  group?: number;
@@ -32,6 +43,6 @@ export declare class Prerender {
32
43
  experimentalBypassFor?: HasField;
33
44
  experimentalStreamingLambdaPath?: string;
34
45
  chain?: Chain;
35
- constructor({ expiration, lambda, fallback, group, bypassToken, allowQuery, allowHeader, initialHeaders, initialStatus, passQuery, sourcePath, experimentalBypassFor, experimentalStreamingLambdaPath, chain, }: PrerenderOptions);
46
+ constructor({ expiration, staleExpiration, lambda, fallback, group, bypassToken, allowQuery, allowHeader, initialHeaders, initialStatus, passQuery, sourcePath, experimentalBypassFor, experimentalStreamingLambdaPath, chain, }: PrerenderOptions);
36
47
  }
37
48
  export {};
package/dist/prerender.js CHANGED
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(prerender_exports);
24
24
  class Prerender {
25
25
  constructor({
26
26
  expiration,
27
+ staleExpiration,
27
28
  lambda,
28
29
  fallback,
29
30
  group,
@@ -40,6 +41,7 @@ class Prerender {
40
41
  }) {
41
42
  this.type = "Prerender";
42
43
  this.expiration = expiration;
44
+ this.staleExpiration = staleExpiration;
43
45
  this.sourcePath = sourcePath;
44
46
  this.lambda = lambda;
45
47
  if (this.lambda) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "10.3.0",
3
+ "version": "10.3.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -54,7 +54,7 @@
54
54
  "test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail --runInBand",
55
55
  "vitest-run": "vitest -c ../../vitest.config.mts",
56
56
  "vitest-unit": "glob --absolute 'test/unit.*test.ts'",
57
- "vitest-e2e": "glob --absolute 'test/integration-*.test.ts'",
57
+ "vitest-e2e": "glob --absolute 'test/integration*.test.ts'",
58
58
  "type-check": "tsc --noEmit"
59
59
  }
60
60
  }