@vercel/build-utils 7.2.3 → 7.2.5
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 +12 -0
- package/dist/fs/node-version.d.ts +65 -3
- package/dist/fs/node-version.js +36 -14
- package/dist/fs/run-user-scripts.d.ts +1 -1
- package/dist/fs/run-user-scripts.js +3 -3
- package/dist/index.js +46 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @vercel/build-utils
|
2
2
|
|
3
|
+
## 7.2.5
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Remove Node.js v20 env var check ([#10834](https://github.com/vercel/vercel/pull/10834))
|
8
|
+
|
9
|
+
## 7.2.4
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- Select Node.js version based on what's available in build-container ([#10822](https://github.com/vercel/vercel/pull/10822))
|
14
|
+
|
3
15
|
## 7.2.3
|
4
16
|
|
5
17
|
### Patch Changes
|
@@ -1,12 +1,74 @@
|
|
1
1
|
import { NodeVersion } from '../types';
|
2
|
-
export
|
2
|
+
export type NodeVersionMajor = ReturnType<typeof getOptions>[number]['major'];
|
3
|
+
declare function getOptions(): readonly [{
|
4
|
+
readonly major: 20;
|
5
|
+
readonly range: "20.x";
|
6
|
+
readonly runtime: "nodejs20.x";
|
7
|
+
}, {
|
3
8
|
readonly major: 18;
|
4
9
|
readonly range: "18.x";
|
5
10
|
readonly runtime: "nodejs18.x";
|
6
|
-
}
|
11
|
+
}, {
|
12
|
+
readonly major: 16;
|
13
|
+
readonly range: "16.x";
|
14
|
+
readonly runtime: "nodejs16.x";
|
15
|
+
readonly discontinueDate: Date;
|
16
|
+
}, {
|
17
|
+
readonly major: 14;
|
18
|
+
readonly range: "14.x";
|
19
|
+
readonly runtime: "nodejs14.x";
|
20
|
+
readonly discontinueDate: Date;
|
21
|
+
}, {
|
22
|
+
readonly major: 12;
|
23
|
+
readonly range: "12.x";
|
24
|
+
readonly runtime: "nodejs12.x";
|
25
|
+
readonly discontinueDate: Date;
|
26
|
+
}, {
|
27
|
+
readonly major: 10;
|
28
|
+
readonly range: "10.x";
|
29
|
+
readonly runtime: "nodejs10.x";
|
30
|
+
readonly discontinueDate: Date;
|
31
|
+
}, {
|
32
|
+
readonly major: 8;
|
33
|
+
readonly range: "8.10.x";
|
34
|
+
readonly runtime: "nodejs8.10";
|
35
|
+
readonly discontinueDate: Date;
|
36
|
+
}];
|
37
|
+
export declare function getAvailableNodeVersions(): NodeVersionMajor[];
|
38
|
+
export declare function getLatestNodeVersion(availableVersions?: NodeVersionMajor[]): {
|
7
39
|
readonly major: 20;
|
8
40
|
readonly range: "20.x";
|
9
41
|
readonly runtime: "nodejs20.x";
|
42
|
+
} | {
|
43
|
+
readonly major: 18;
|
44
|
+
readonly range: "18.x";
|
45
|
+
readonly runtime: "nodejs18.x";
|
46
|
+
} | {
|
47
|
+
readonly major: 16;
|
48
|
+
readonly range: "16.x";
|
49
|
+
readonly runtime: "nodejs16.x";
|
50
|
+
readonly discontinueDate: Date;
|
51
|
+
} | {
|
52
|
+
readonly major: 14;
|
53
|
+
readonly range: "14.x";
|
54
|
+
readonly runtime: "nodejs14.x";
|
55
|
+
readonly discontinueDate: Date;
|
56
|
+
} | {
|
57
|
+
readonly major: 12;
|
58
|
+
readonly range: "12.x";
|
59
|
+
readonly runtime: "nodejs12.x";
|
60
|
+
readonly discontinueDate: Date;
|
61
|
+
} | {
|
62
|
+
readonly major: 10;
|
63
|
+
readonly range: "10.x";
|
64
|
+
readonly runtime: "nodejs10.x";
|
65
|
+
readonly discontinueDate: Date;
|
66
|
+
} | {
|
67
|
+
readonly major: 8;
|
68
|
+
readonly range: "8.10.x";
|
69
|
+
readonly runtime: "nodejs8.10";
|
70
|
+
readonly discontinueDate: Date;
|
10
71
|
};
|
11
72
|
export declare function getDiscontinuedNodeVersions(): NodeVersion[];
|
12
|
-
export declare function getSupportedNodeVersion(engineRange: string | undefined, isAuto?: boolean): Promise<NodeVersion>;
|
73
|
+
export declare function getSupportedNodeVersion(engineRange: string | undefined, isAuto?: boolean, availableVersions?: NodeVersionMajor[]): Promise<NodeVersion>;
|
74
|
+
export {};
|
package/dist/fs/node-version.js
CHANGED
@@ -28,16 +28,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var node_version_exports = {};
|
30
30
|
__export(node_version_exports, {
|
31
|
+
getAvailableNodeVersions: () => getAvailableNodeVersions,
|
31
32
|
getDiscontinuedNodeVersions: () => getDiscontinuedNodeVersions,
|
32
33
|
getLatestNodeVersion: () => getLatestNodeVersion,
|
33
34
|
getSupportedNodeVersion: () => getSupportedNodeVersion
|
34
35
|
});
|
35
36
|
module.exports = __toCommonJS(node_version_exports);
|
37
|
+
var import_fs = require("fs");
|
36
38
|
var import_semver = require("semver");
|
37
39
|
var import_errors = require("../errors");
|
38
40
|
var import_debug = __toESM(require("../debug"));
|
39
41
|
function getOptions() {
|
40
42
|
const options = [
|
43
|
+
{ major: 20, range: "20.x", runtime: "nodejs20.x" },
|
41
44
|
{ major: 18, range: "18.x", runtime: "nodejs18.x" },
|
42
45
|
{
|
43
46
|
major: 16,
|
@@ -70,41 +73,59 @@ function getOptions() {
|
|
70
73
|
discontinueDate: /* @__PURE__ */ new Date("2020-01-06")
|
71
74
|
}
|
72
75
|
];
|
73
|
-
if (process.env.VERCEL_ALLOW_NODEJS20 === "1") {
|
74
|
-
return [
|
75
|
-
{ major: 20, range: "20.x", runtime: "nodejs20.x" },
|
76
|
-
...options
|
77
|
-
];
|
78
|
-
}
|
79
76
|
return options;
|
80
77
|
}
|
81
|
-
function
|
82
|
-
|
78
|
+
function isNodeVersionAvailable(version) {
|
79
|
+
try {
|
80
|
+
return (0, import_fs.statSync)(`/node${version.major}`).isDirectory();
|
81
|
+
} catch {
|
82
|
+
}
|
83
|
+
return false;
|
84
|
+
}
|
85
|
+
function getAvailableNodeVersions() {
|
86
|
+
return getOptions().filter(isNodeVersionAvailable).map((n) => n.major);
|
87
|
+
}
|
88
|
+
function getHint(isAuto = false, availableVersions) {
|
89
|
+
const { major, range } = getLatestNodeVersion(availableVersions);
|
83
90
|
return isAuto ? `Please set Node.js Version to ${range} in your Project Settings to use Node.js ${major}.` : `Please set "engines": { "node": "${range}" } in your \`package.json\` file to use Node.js ${major}.`;
|
84
91
|
}
|
85
|
-
function getLatestNodeVersion() {
|
86
|
-
|
92
|
+
function getLatestNodeVersion(availableVersions) {
|
93
|
+
const all = getOptions();
|
94
|
+
if (availableVersions) {
|
95
|
+
for (const version of all) {
|
96
|
+
for (const major of availableVersions) {
|
97
|
+
if (version.major === major) {
|
98
|
+
return version;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return all[0];
|
87
104
|
}
|
88
105
|
function getDiscontinuedNodeVersions() {
|
89
106
|
return getOptions().filter(isDiscontinued);
|
90
107
|
}
|
91
|
-
async function getSupportedNodeVersion(engineRange, isAuto = false) {
|
92
|
-
let selection
|
108
|
+
async function getSupportedNodeVersion(engineRange, isAuto = false, availableVersions) {
|
109
|
+
let selection;
|
93
110
|
if (engineRange) {
|
94
111
|
const found = (0, import_semver.validRange)(engineRange) && getOptions().some((o) => {
|
95
112
|
selection = o;
|
96
|
-
return (0, import_semver.intersects)(o.range, engineRange);
|
113
|
+
return (0, import_semver.intersects)(o.range, engineRange) && (availableVersions?.length ? availableVersions.includes(o.major) : true);
|
97
114
|
});
|
98
115
|
if (!found) {
|
99
116
|
throw new import_errors.NowBuildError({
|
100
117
|
code: "BUILD_UTILS_NODE_VERSION_INVALID",
|
101
118
|
link: "http://vercel.link/node-version",
|
102
119
|
message: `Found invalid Node.js Version: "${engineRange}". ${getHint(
|
103
|
-
isAuto
|
120
|
+
isAuto,
|
121
|
+
availableVersions
|
104
122
|
)}`
|
105
123
|
});
|
106
124
|
}
|
107
125
|
}
|
126
|
+
if (!selection) {
|
127
|
+
selection = getLatestNodeVersion(availableVersions);
|
128
|
+
}
|
108
129
|
if (isDiscontinued(selection)) {
|
109
130
|
const intro = `Node.js Version "${selection.range}" is discontinued and must be upgraded.`;
|
110
131
|
throw new import_errors.NowBuildError({
|
@@ -130,6 +151,7 @@ function isDiscontinued({ discontinueDate }) {
|
|
130
151
|
}
|
131
152
|
// Annotate the CommonJS export names for ESM import in node:
|
132
153
|
0 && (module.exports = {
|
154
|
+
getAvailableNodeVersions,
|
133
155
|
getDiscontinuedNodeVersions,
|
134
156
|
getLatestNodeVersion,
|
135
157
|
getSupportedNodeVersion
|
@@ -74,7 +74,7 @@ export declare function getNodeBinPath({ cwd, }: {
|
|
74
74
|
export declare function getNodeBinPaths({ start, base, }: TraverseUpDirectoriesProps): string[];
|
75
75
|
export declare function runShellScript(fsPath: string, args?: string[], spawnOpts?: SpawnOptions): Promise<boolean>;
|
76
76
|
export declare function getSpawnOptions(meta: Meta, nodeVersion: NodeVersion): SpawnOptions;
|
77
|
-
export declare function getNodeVersion(destPath: string, nodeVersionFallback?: string | undefined, config?: Config, meta?: Meta): Promise<NodeVersion>;
|
77
|
+
export declare function getNodeVersion(destPath: string, nodeVersionFallback?: string | undefined, config?: Config, meta?: Meta, availableVersions?: (20 | 10 | 16 | 18 | 14 | 12 | 8)[]): Promise<NodeVersion>;
|
78
78
|
export declare function scanParentDirs(destPath: string, readPackageJson?: boolean): Promise<ScanParentDirsResult>;
|
79
79
|
export declare function walkParentDirs({ base, start, filename, }: WalkParentDirsProps): Promise<string | null>;
|
80
80
|
export declare function runNpmInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta, nodeVersion?: NodeVersion): Promise<boolean>;
|
@@ -171,8 +171,8 @@ function getSpawnOptions(meta, nodeVersion) {
|
|
171
171
|
}
|
172
172
|
return opts;
|
173
173
|
}
|
174
|
-
async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}) {
|
175
|
-
const latest = (0, import_node_version.getLatestNodeVersion)();
|
174
|
+
async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}, availableVersions = (0, import_node_version.getAvailableNodeVersions)()) {
|
175
|
+
const latest = (0, import_node_version.getLatestNodeVersion)(availableVersions);
|
176
176
|
if (meta.isDev) {
|
177
177
|
return { ...latest, runtime: "nodejs" };
|
178
178
|
}
|
@@ -197,7 +197,7 @@ async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL
|
|
197
197
|
nodeVersion = node;
|
198
198
|
isAuto = false;
|
199
199
|
}
|
200
|
-
return (0, import_node_version.getSupportedNodeVersion)(nodeVersion, isAuto);
|
200
|
+
return (0, import_node_version.getSupportedNodeVersion)(nodeVersion, isAuto, availableVersions);
|
201
201
|
}
|
202
202
|
async function scanParentDirs(destPath, readPackageJson = false) {
|
203
203
|
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
package/dist/index.js
CHANGED
@@ -3548,8 +3548,8 @@ var require_copy_sync = __commonJS({
|
|
3548
3548
|
return getStats(destStat, src, dest, opts);
|
3549
3549
|
}
|
3550
3550
|
function getStats(destStat, src, dest, opts) {
|
3551
|
-
const
|
3552
|
-
const srcStat =
|
3551
|
+
const statSync2 = opts.dereference ? fs5.statSync : fs5.lstatSync;
|
3552
|
+
const srcStat = statSync2(src);
|
3553
3553
|
if (srcStat.isDirectory())
|
3554
3554
|
return onDir(srcStat, destStat, src, dest, opts);
|
3555
3555
|
else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice())
|
@@ -21589,9 +21589,11 @@ var import_semver2 = __toESM(require_semver2());
|
|
21589
21589
|
var import_util2 = require("util");
|
21590
21590
|
|
21591
21591
|
// src/fs/node-version.ts
|
21592
|
+
var import_fs = require("fs");
|
21592
21593
|
var import_semver = __toESM(require_semver2());
|
21593
21594
|
function getOptions() {
|
21594
21595
|
const options = [
|
21596
|
+
{ major: 20, range: "20.x", runtime: "nodejs20.x" },
|
21595
21597
|
{ major: 18, range: "18.x", runtime: "nodejs18.x" },
|
21596
21598
|
{
|
21597
21599
|
major: 16,
|
@@ -21624,41 +21626,59 @@ function getOptions() {
|
|
21624
21626
|
discontinueDate: /* @__PURE__ */ new Date("2020-01-06")
|
21625
21627
|
}
|
21626
21628
|
];
|
21627
|
-
if (process.env.VERCEL_ALLOW_NODEJS20 === "1") {
|
21628
|
-
return [
|
21629
|
-
{ major: 20, range: "20.x", runtime: "nodejs20.x" },
|
21630
|
-
...options
|
21631
|
-
];
|
21632
|
-
}
|
21633
21629
|
return options;
|
21634
21630
|
}
|
21635
|
-
function
|
21636
|
-
|
21631
|
+
function isNodeVersionAvailable(version) {
|
21632
|
+
try {
|
21633
|
+
return (0, import_fs.statSync)(`/node${version.major}`).isDirectory();
|
21634
|
+
} catch {
|
21635
|
+
}
|
21636
|
+
return false;
|
21637
|
+
}
|
21638
|
+
function getAvailableNodeVersions() {
|
21639
|
+
return getOptions().filter(isNodeVersionAvailable).map((n) => n.major);
|
21640
|
+
}
|
21641
|
+
function getHint(isAuto = false, availableVersions) {
|
21642
|
+
const { major, range } = getLatestNodeVersion(availableVersions);
|
21637
21643
|
return isAuto ? `Please set Node.js Version to ${range} in your Project Settings to use Node.js ${major}.` : `Please set "engines": { "node": "${range}" } in your \`package.json\` file to use Node.js ${major}.`;
|
21638
21644
|
}
|
21639
|
-
function getLatestNodeVersion() {
|
21640
|
-
|
21645
|
+
function getLatestNodeVersion(availableVersions) {
|
21646
|
+
const all = getOptions();
|
21647
|
+
if (availableVersions) {
|
21648
|
+
for (const version of all) {
|
21649
|
+
for (const major of availableVersions) {
|
21650
|
+
if (version.major === major) {
|
21651
|
+
return version;
|
21652
|
+
}
|
21653
|
+
}
|
21654
|
+
}
|
21655
|
+
}
|
21656
|
+
return all[0];
|
21641
21657
|
}
|
21642
21658
|
function getDiscontinuedNodeVersions() {
|
21643
21659
|
return getOptions().filter(isDiscontinued);
|
21644
21660
|
}
|
21645
|
-
async function getSupportedNodeVersion(engineRange, isAuto = false) {
|
21646
|
-
let selection
|
21661
|
+
async function getSupportedNodeVersion(engineRange, isAuto = false, availableVersions) {
|
21662
|
+
let selection;
|
21647
21663
|
if (engineRange) {
|
21648
21664
|
const found = (0, import_semver.validRange)(engineRange) && getOptions().some((o) => {
|
21649
21665
|
selection = o;
|
21650
|
-
return (0, import_semver.intersects)(o.range, engineRange);
|
21666
|
+
return (0, import_semver.intersects)(o.range, engineRange) && (availableVersions?.length ? availableVersions.includes(o.major) : true);
|
21651
21667
|
});
|
21652
21668
|
if (!found) {
|
21653
21669
|
throw new NowBuildError({
|
21654
21670
|
code: "BUILD_UTILS_NODE_VERSION_INVALID",
|
21655
21671
|
link: "http://vercel.link/node-version",
|
21656
21672
|
message: `Found invalid Node.js Version: "${engineRange}". ${getHint(
|
21657
|
-
isAuto
|
21673
|
+
isAuto,
|
21674
|
+
availableVersions
|
21658
21675
|
)}`
|
21659
21676
|
});
|
21660
21677
|
}
|
21661
21678
|
}
|
21679
|
+
if (!selection) {
|
21680
|
+
selection = getLatestNodeVersion(availableVersions);
|
21681
|
+
}
|
21662
21682
|
if (isDiscontinued(selection)) {
|
21663
21683
|
const intro = `Node.js Version "${selection.range}" is discontinued and must be upgraded.`;
|
21664
21684
|
throw new NowBuildError({
|
@@ -21853,8 +21873,8 @@ function getSpawnOptions(meta, nodeVersion) {
|
|
21853
21873
|
}
|
21854
21874
|
return opts;
|
21855
21875
|
}
|
21856
|
-
async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}) {
|
21857
|
-
const latest = getLatestNodeVersion();
|
21876
|
+
async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}, availableVersions = getAvailableNodeVersions()) {
|
21877
|
+
const latest = getLatestNodeVersion(availableVersions);
|
21858
21878
|
if (meta.isDev) {
|
21859
21879
|
return { ...latest, runtime: "nodejs" };
|
21860
21880
|
}
|
@@ -21879,7 +21899,7 @@ async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL
|
|
21879
21899
|
nodeVersion = node;
|
21880
21900
|
isAuto = false;
|
21881
21901
|
}
|
21882
|
-
return getSupportedNodeVersion(nodeVersion, isAuto);
|
21902
|
+
return getSupportedNodeVersion(nodeVersion, isAuto, availableVersions);
|
21883
21903
|
}
|
21884
21904
|
async function scanParentDirs(destPath, readPackageJson = false) {
|
21885
21905
|
(0, import_assert6.default)(import_path5.default.isAbsolute(destPath));
|
@@ -22279,23 +22299,23 @@ function getPrefixedEnvVars({
|
|
22279
22299
|
|
22280
22300
|
// src/hard-link-dir.ts
|
22281
22301
|
var import_path7 = __toESM(require("path"));
|
22282
|
-
var
|
22302
|
+
var import_fs2 = require("fs");
|
22283
22303
|
async function hardLinkDir(src, destDirs) {
|
22284
22304
|
if (destDirs.length === 0)
|
22285
22305
|
return;
|
22286
22306
|
destDirs = destDirs.filter((destDir) => import_path7.default.relative(destDir, src) !== "");
|
22287
|
-
const files = await
|
22307
|
+
const files = await import_fs2.promises.readdir(src);
|
22288
22308
|
await Promise.all(
|
22289
22309
|
files.map(async (file) => {
|
22290
22310
|
if (file === "node_modules")
|
22291
22311
|
return;
|
22292
22312
|
const srcFile = import_path7.default.join(src, file);
|
22293
|
-
if ((await
|
22313
|
+
if ((await import_fs2.promises.lstat(srcFile)).isDirectory()) {
|
22294
22314
|
const destSubdirs = await Promise.all(
|
22295
22315
|
destDirs.map(async (destDir) => {
|
22296
22316
|
const destSubdir = import_path7.default.join(destDir, file);
|
22297
22317
|
try {
|
22298
|
-
await
|
22318
|
+
await import_fs2.promises.mkdir(destSubdir, { recursive: true });
|
22299
22319
|
} catch (err) {
|
22300
22320
|
if (err.code !== "EEXIST")
|
22301
22321
|
throw err;
|
@@ -22327,7 +22347,7 @@ async function linkOrCopyFile(srcFile, destFile) {
|
|
22327
22347
|
await linkOrCopy(srcFile, destFile);
|
22328
22348
|
} catch (err) {
|
22329
22349
|
if (err.code === "ENOENT") {
|
22330
|
-
await
|
22350
|
+
await import_fs2.promises.mkdir(import_path7.default.dirname(destFile), { recursive: true });
|
22331
22351
|
await linkOrCopy(srcFile, destFile);
|
22332
22352
|
return;
|
22333
22353
|
}
|
@@ -22338,11 +22358,11 @@ async function linkOrCopyFile(srcFile, destFile) {
|
|
22338
22358
|
}
|
22339
22359
|
async function linkOrCopy(srcFile, destFile) {
|
22340
22360
|
try {
|
22341
|
-
await
|
22361
|
+
await import_fs2.promises.link(srcFile, destFile);
|
22342
22362
|
} catch (err) {
|
22343
22363
|
if (err.code !== "EXDEV")
|
22344
22364
|
throw err;
|
22345
|
-
await
|
22365
|
+
await import_fs2.promises.copyFile(srcFile, destFile);
|
22346
22366
|
}
|
22347
22367
|
}
|
22348
22368
|
|