@vercel/build-utils 8.4.10 → 8.4.12
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 +48 -15
- package/dist/index.js +62 -15
- package/dist/prerender.d.ts +3 -1
- package/dist/prerender.js +14 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @vercel/build-utils
|
2
2
|
|
3
|
+
## 8.4.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Support allowHeader from Next.js for filtering request headers during revalidation ([#12420](https://github.com/vercel/vercel/pull/12420))
|
8
|
+
|
9
|
+
## 8.4.11
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- Improve parsing of `turbo.json` ([#12266](https://github.com/vercel/vercel/pull/12266))
|
14
|
+
|
15
|
+
- Fix corepack `packageManager` detection on monorepos ([#12258](https://github.com/vercel/vercel/pull/12258))
|
16
|
+
|
3
17
|
## 8.4.10
|
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.
|
@@ -238,7 +238,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
238
238
|
filename: "package.json"
|
239
239
|
});
|
240
240
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
241
|
-
const
|
241
|
+
const {
|
242
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
243
|
+
packageJsonPackageManager
|
244
|
+
} = await walkParentDirsMulti({
|
242
245
|
base,
|
243
246
|
start: destPath,
|
244
247
|
filenames: [
|
@@ -286,15 +289,16 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
286
289
|
lockfilePath = bunLockPath;
|
287
290
|
lockfileVersion = 0;
|
288
291
|
} else {
|
289
|
-
cliType =
|
290
|
-
|
292
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
293
|
+
packageJsonPackageManager,
|
291
294
|
turboSupportsCorepackHome
|
292
|
-
)
|
295
|
+
);
|
293
296
|
}
|
294
297
|
const packageJsonPath = pkgJsonPath || void 0;
|
295
298
|
return {
|
296
299
|
cliType,
|
297
300
|
packageJson,
|
301
|
+
packageJsonPackageManager,
|
298
302
|
lockfilePath,
|
299
303
|
lockfileVersion,
|
300
304
|
packageJsonPath,
|
@@ -307,8 +311,16 @@ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
|
|
307
311
|
}
|
308
312
|
const turboJsonPath = import_path.default.join(rootDir, "turbo.json");
|
309
313
|
const turboJsonExists = await import_fs_extra.default.pathExists(turboJsonPath);
|
310
|
-
|
311
|
-
|
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;
|
312
324
|
}
|
313
325
|
function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
314
326
|
if (!(0, import_semver.validRange)(turboVersionSpecifier)) {
|
@@ -321,8 +333,7 @@ function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
|
321
333
|
}
|
322
334
|
return (0, import_semver.gte)(minTurboBeingUsed, versionSupportingCorepack);
|
323
335
|
}
|
324
|
-
function detectPackageManagerNameWithoutLockfile(
|
325
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
336
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
|
326
337
|
if (usingCorepack(
|
327
338
|
process.env,
|
328
339
|
packageJsonPackageManager,
|
@@ -379,17 +390,26 @@ async function walkParentDirsMulti({
|
|
379
390
|
start,
|
380
391
|
filenames
|
381
392
|
}) {
|
393
|
+
let packageManager;
|
382
394
|
for (const dir of traverseUpDirectories({ start, base })) {
|
383
395
|
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
384
396
|
const existResults = await Promise.all(
|
385
397
|
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
386
398
|
);
|
387
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
|
+
}
|
388
405
|
if (foundOneOrMore) {
|
389
|
-
return
|
406
|
+
return {
|
407
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
408
|
+
packageJsonPackageManager: packageManager
|
409
|
+
};
|
390
410
|
}
|
391
411
|
}
|
392
|
-
return [];
|
412
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
393
413
|
}
|
394
414
|
function isSet(v) {
|
395
415
|
return v?.constructor?.name === "Set";
|
@@ -407,6 +427,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
407
427
|
packageJsonPath,
|
408
428
|
packageJson,
|
409
429
|
lockfileVersion,
|
430
|
+
packageJsonPackageManager,
|
410
431
|
turboSupportsCorepackHome
|
411
432
|
} = await scanParentDirs(destPath, true);
|
412
433
|
if (!packageJsonPath) {
|
@@ -437,7 +458,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
437
458
|
opts.env = getEnvForPackageManager({
|
438
459
|
cliType,
|
439
460
|
lockfileVersion,
|
440
|
-
packageJsonPackageManager
|
461
|
+
packageJsonPackageManager,
|
441
462
|
nodeVersion,
|
442
463
|
env,
|
443
464
|
packageJsonEngines: packageJson?.engines,
|
@@ -782,11 +803,17 @@ async function runCustomInstallCommand({
|
|
782
803
|
spawnOpts
|
783
804
|
}) {
|
784
805
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
785
|
-
const {
|
806
|
+
const {
|
807
|
+
cliType,
|
808
|
+
lockfileVersion,
|
809
|
+
packageJson,
|
810
|
+
packageJsonPackageManager,
|
811
|
+
turboSupportsCorepackHome
|
812
|
+
} = await scanParentDirs(destPath, true);
|
786
813
|
const env = getEnvForPackageManager({
|
787
814
|
cliType,
|
788
815
|
lockfileVersion,
|
789
|
-
packageJsonPackageManager
|
816
|
+
packageJsonPackageManager,
|
790
817
|
nodeVersion,
|
791
818
|
env: spawnOpts?.env || {},
|
792
819
|
packageJsonEngines: packageJson?.engines,
|
@@ -801,7 +828,13 @@ async function runCustomInstallCommand({
|
|
801
828
|
}
|
802
829
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
803
830
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
804
|
-
const {
|
831
|
+
const {
|
832
|
+
packageJson,
|
833
|
+
cliType,
|
834
|
+
lockfileVersion,
|
835
|
+
packageJsonPackageManager,
|
836
|
+
turboSupportsCorepackHome
|
837
|
+
} = await scanParentDirs(destPath, true);
|
805
838
|
const scriptName = getScriptName(
|
806
839
|
packageJson,
|
807
840
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -816,7 +849,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
816
849
|
env: getEnvForPackageManager({
|
817
850
|
cliType,
|
818
851
|
lockfileVersion,
|
819
|
-
packageJsonPackageManager
|
852
|
+
packageJsonPackageManager,
|
820
853
|
nodeVersion: void 0,
|
821
854
|
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env),
|
822
855
|
packageJsonEngines: packageJson?.engines,
|
package/dist/index.js
CHANGED
@@ -24130,6 +24130,7 @@ var Prerender = class {
|
|
24130
24130
|
group,
|
24131
24131
|
bypassToken,
|
24132
24132
|
allowQuery,
|
24133
|
+
allowHeader,
|
24133
24134
|
initialHeaders,
|
24134
24135
|
initialStatus,
|
24135
24136
|
passQuery,
|
@@ -24220,6 +24221,19 @@ var Prerender = class {
|
|
24220
24221
|
}
|
24221
24222
|
this.allowQuery = allowQuery;
|
24222
24223
|
}
|
24224
|
+
if (allowHeader !== void 0) {
|
24225
|
+
if (!Array.isArray(allowHeader)) {
|
24226
|
+
throw new Error(
|
24227
|
+
"The `allowHeader` argument for `Prerender` must be Array."
|
24228
|
+
);
|
24229
|
+
}
|
24230
|
+
if (!allowHeader.every((q) => typeof q === "string")) {
|
24231
|
+
throw new Error(
|
24232
|
+
"The `allowHeader` argument for `Prerender` must be Array of strings."
|
24233
|
+
);
|
24234
|
+
}
|
24235
|
+
this.allowHeader = allowHeader;
|
24236
|
+
}
|
24223
24237
|
if (experimentalStreamingLambdaPath !== void 0) {
|
24224
24238
|
if (typeof experimentalStreamingLambdaPath !== "string") {
|
24225
24239
|
throw new Error(
|
@@ -24719,7 +24733,10 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
24719
24733
|
filename: "package.json"
|
24720
24734
|
});
|
24721
24735
|
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra7.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
24722
|
-
const
|
24736
|
+
const {
|
24737
|
+
paths: [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath],
|
24738
|
+
packageJsonPackageManager
|
24739
|
+
} = await walkParentDirsMulti({
|
24723
24740
|
base,
|
24724
24741
|
start: destPath,
|
24725
24742
|
filenames: [
|
@@ -24767,15 +24784,16 @@ async function scanParentDirs(destPath, readPackageJson = false, base = "/") {
|
|
24767
24784
|
lockfilePath = bunLockPath;
|
24768
24785
|
lockfileVersion = 0;
|
24769
24786
|
} else {
|
24770
|
-
cliType =
|
24771
|
-
|
24787
|
+
cliType = detectPackageManagerNameWithoutLockfile(
|
24788
|
+
packageJsonPackageManager,
|
24772
24789
|
turboSupportsCorepackHome
|
24773
|
-
)
|
24790
|
+
);
|
24774
24791
|
}
|
24775
24792
|
const packageJsonPath = pkgJsonPath || void 0;
|
24776
24793
|
return {
|
24777
24794
|
cliType,
|
24778
24795
|
packageJson,
|
24796
|
+
packageJsonPackageManager,
|
24779
24797
|
lockfilePath,
|
24780
24798
|
lockfileVersion,
|
24781
24799
|
packageJsonPath,
|
@@ -24788,8 +24806,16 @@ async function checkTurboSupportsCorepack(turboVersionRange, rootDir) {
|
|
24788
24806
|
}
|
24789
24807
|
const turboJsonPath = import_path5.default.join(rootDir, "turbo.json");
|
24790
24808
|
const turboJsonExists = await import_fs_extra7.default.pathExists(turboJsonPath);
|
24791
|
-
|
24792
|
-
|
24809
|
+
let turboJson = null;
|
24810
|
+
if (turboJsonExists) {
|
24811
|
+
try {
|
24812
|
+
turboJson = import_json5.default.parse(await import_fs_extra7.default.readFile(turboJsonPath, "utf8"));
|
24813
|
+
} catch (err) {
|
24814
|
+
console.warn(`WARNING: Failed to parse turbo.json`);
|
24815
|
+
}
|
24816
|
+
}
|
24817
|
+
const turboJsonIncludesCorepackHome = turboJson !== null && typeof turboJson === "object" && "globalPassThroughEnv" in turboJson && Array.isArray(turboJson.globalPassThroughEnv) && turboJson.globalPassThroughEnv.includes("COREPACK_HOME");
|
24818
|
+
return turboJsonIncludesCorepackHome;
|
24793
24819
|
}
|
24794
24820
|
function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
24795
24821
|
if (!(0, import_semver2.validRange)(turboVersionSpecifier)) {
|
@@ -24802,8 +24828,7 @@ function turboVersionSpecifierSupportsCorepack(turboVersionSpecifier) {
|
|
24802
24828
|
}
|
24803
24829
|
return (0, import_semver2.gte)(minTurboBeingUsed, versionSupportingCorepack);
|
24804
24830
|
}
|
24805
|
-
function detectPackageManagerNameWithoutLockfile(
|
24806
|
-
const packageJsonPackageManager = packageJson.packageManager;
|
24831
|
+
function detectPackageManagerNameWithoutLockfile(packageJsonPackageManager, turboSupportsCorepackHome) {
|
24807
24832
|
if (usingCorepack(
|
24808
24833
|
process.env,
|
24809
24834
|
packageJsonPackageManager,
|
@@ -24860,17 +24885,26 @@ async function walkParentDirsMulti({
|
|
24860
24885
|
start,
|
24861
24886
|
filenames
|
24862
24887
|
}) {
|
24888
|
+
let packageManager;
|
24863
24889
|
for (const dir of traverseUpDirectories({ start, base })) {
|
24864
24890
|
const fullPaths = filenames.map((f) => import_path5.default.join(dir, f));
|
24865
24891
|
const existResults = await Promise.all(
|
24866
24892
|
fullPaths.map((f) => import_fs_extra7.default.pathExists(f))
|
24867
24893
|
);
|
24868
24894
|
const foundOneOrMore = existResults.some((b) => b);
|
24895
|
+
const packageJsonPath = import_path5.default.join(dir, "package.json");
|
24896
|
+
const packageJson = await import_fs_extra7.default.readJSON(packageJsonPath).catch(() => null);
|
24897
|
+
if (packageJson?.packageManager) {
|
24898
|
+
packageManager = packageJson.packageManager;
|
24899
|
+
}
|
24869
24900
|
if (foundOneOrMore) {
|
24870
|
-
return
|
24901
|
+
return {
|
24902
|
+
paths: fullPaths.map((f, i) => existResults[i] ? f : void 0),
|
24903
|
+
packageJsonPackageManager: packageManager
|
24904
|
+
};
|
24871
24905
|
}
|
24872
24906
|
}
|
24873
|
-
return [];
|
24907
|
+
return { paths: [], packageJsonPackageManager: packageManager };
|
24874
24908
|
}
|
24875
24909
|
function isSet(v) {
|
24876
24910
|
return v?.constructor?.name === "Set";
|
@@ -24888,6 +24922,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
24888
24922
|
packageJsonPath,
|
24889
24923
|
packageJson,
|
24890
24924
|
lockfileVersion,
|
24925
|
+
packageJsonPackageManager,
|
24891
24926
|
turboSupportsCorepackHome
|
24892
24927
|
} = await scanParentDirs(destPath, true);
|
24893
24928
|
if (!packageJsonPath) {
|
@@ -24918,7 +24953,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
24918
24953
|
opts.env = getEnvForPackageManager({
|
24919
24954
|
cliType,
|
24920
24955
|
lockfileVersion,
|
24921
|
-
packageJsonPackageManager
|
24956
|
+
packageJsonPackageManager,
|
24922
24957
|
nodeVersion,
|
24923
24958
|
env,
|
24924
24959
|
packageJsonEngines: packageJson?.engines,
|
@@ -25263,11 +25298,17 @@ async function runCustomInstallCommand({
|
|
25263
25298
|
spawnOpts
|
25264
25299
|
}) {
|
25265
25300
|
console.log(`Running "install" command: \`${installCommand}\`...`);
|
25266
|
-
const {
|
25301
|
+
const {
|
25302
|
+
cliType,
|
25303
|
+
lockfileVersion,
|
25304
|
+
packageJson,
|
25305
|
+
packageJsonPackageManager,
|
25306
|
+
turboSupportsCorepackHome
|
25307
|
+
} = await scanParentDirs(destPath, true);
|
25267
25308
|
const env = getEnvForPackageManager({
|
25268
25309
|
cliType,
|
25269
25310
|
lockfileVersion,
|
25270
|
-
packageJsonPackageManager
|
25311
|
+
packageJsonPackageManager,
|
25271
25312
|
nodeVersion,
|
25272
25313
|
env: spawnOpts?.env || {},
|
25273
25314
|
packageJsonEngines: packageJson?.engines,
|
@@ -25282,7 +25323,13 @@ async function runCustomInstallCommand({
|
|
25282
25323
|
}
|
25283
25324
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
25284
25325
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
25285
|
-
const {
|
25326
|
+
const {
|
25327
|
+
packageJson,
|
25328
|
+
cliType,
|
25329
|
+
lockfileVersion,
|
25330
|
+
packageJsonPackageManager,
|
25331
|
+
turboSupportsCorepackHome
|
25332
|
+
} = await scanParentDirs(destPath, true);
|
25286
25333
|
const scriptName = getScriptName(
|
25287
25334
|
packageJson,
|
25288
25335
|
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
@@ -25297,7 +25344,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
25297
25344
|
env: getEnvForPackageManager({
|
25298
25345
|
cliType,
|
25299
25346
|
lockfileVersion,
|
25300
|
-
packageJsonPackageManager
|
25347
|
+
packageJsonPackageManager,
|
25301
25348
|
nodeVersion: void 0,
|
25302
25349
|
env: cloneEnv(process.env, spawnOpts?.env),
|
25303
25350
|
packageJsonEngines: packageJson?.engines,
|
package/dist/prerender.d.ts
CHANGED
@@ -7,6 +7,7 @@ interface PrerenderOptions {
|
|
7
7
|
group?: number;
|
8
8
|
bypassToken?: string | null;
|
9
9
|
allowQuery?: string[];
|
10
|
+
allowHeader?: string[];
|
10
11
|
initialHeaders?: Record<string, string>;
|
11
12
|
initialStatus?: number;
|
12
13
|
passQuery?: boolean;
|
@@ -23,6 +24,7 @@ export declare class Prerender {
|
|
23
24
|
group?: number;
|
24
25
|
bypassToken: string | null;
|
25
26
|
allowQuery?: string[];
|
27
|
+
allowHeader?: string[];
|
26
28
|
initialHeaders?: Record<string, string>;
|
27
29
|
initialStatus?: number;
|
28
30
|
passQuery?: boolean;
|
@@ -30,6 +32,6 @@ export declare class Prerender {
|
|
30
32
|
experimentalBypassFor?: HasField;
|
31
33
|
experimentalStreamingLambdaPath?: string;
|
32
34
|
chain?: Chain;
|
33
|
-
constructor({ expiration, lambda, fallback, group, bypassToken, allowQuery, initialHeaders, initialStatus, passQuery, sourcePath, experimentalBypassFor, experimentalStreamingLambdaPath, chain, }: PrerenderOptions);
|
35
|
+
constructor({ expiration, lambda, fallback, group, bypassToken, allowQuery, allowHeader, initialHeaders, initialStatus, passQuery, sourcePath, experimentalBypassFor, experimentalStreamingLambdaPath, chain, }: PrerenderOptions);
|
34
36
|
}
|
35
37
|
export {};
|
package/dist/prerender.js
CHANGED
@@ -29,6 +29,7 @@ class Prerender {
|
|
29
29
|
group,
|
30
30
|
bypassToken,
|
31
31
|
allowQuery,
|
32
|
+
allowHeader,
|
32
33
|
initialHeaders,
|
33
34
|
initialStatus,
|
34
35
|
passQuery,
|
@@ -119,6 +120,19 @@ class Prerender {
|
|
119
120
|
}
|
120
121
|
this.allowQuery = allowQuery;
|
121
122
|
}
|
123
|
+
if (allowHeader !== void 0) {
|
124
|
+
if (!Array.isArray(allowHeader)) {
|
125
|
+
throw new Error(
|
126
|
+
"The `allowHeader` argument for `Prerender` must be Array."
|
127
|
+
);
|
128
|
+
}
|
129
|
+
if (!allowHeader.every((q) => typeof q === "string")) {
|
130
|
+
throw new Error(
|
131
|
+
"The `allowHeader` argument for `Prerender` must be Array of strings."
|
132
|
+
);
|
133
|
+
}
|
134
|
+
this.allowHeader = allowHeader;
|
135
|
+
}
|
122
136
|
if (experimentalStreamingLambdaPath !== void 0) {
|
123
137
|
if (typeof experimentalStreamingLambdaPath !== "string") {
|
124
138
|
throw new Error(
|