@vercel/build-utils 7.1.0 → 7.2.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 +20 -0
- package/build.mjs +3 -0
- package/dist/clone-env.js +39 -30
- package/dist/debug.js +28 -9
- package/dist/edge-function.js +36 -16
- package/dist/errors.js +83 -74
- package/dist/file-blob.js +63 -32
- package/dist/file-fs-ref.js +99 -65
- package/dist/file-ref.js +97 -77
- package/dist/fs/download.js +121 -91
- package/dist/fs/get-writable-directory.js +29 -9
- package/dist/fs/glob.js +104 -77
- package/dist/fs/node-version.js +115 -82
- package/dist/fs/normalize-path.js +28 -8
- package/dist/fs/read-config-file.js +66 -40
- package/dist/fs/rename.js +27 -14
- package/dist/fs/run-user-scripts.d.ts +1 -1
- package/dist/fs/run-user-scripts.js +481 -419
- package/dist/fs/stream-to-buffer.js +51 -24
- package/dist/get-ignore-filter.js +80 -49
- package/dist/get-platform-env.js +41 -22
- package/dist/get-prefixed-env-vars.js +48 -32
- package/dist/hard-link-dir.js +90 -70
- package/dist/index.js +21456 -29356
- package/dist/lambda.js +208 -144
- package/dist/nodejs-lambda.js +40 -12
- package/dist/prerender.d.ts +6 -2
- package/dist/prerender.js +130 -64
- package/dist/schemas.js +83 -57
- package/dist/should-serve.js +43 -16
- package/dist/types.d.ts +12 -0
- package/dist/types.js +15 -1
- package/dist/validate-npmrc.js +38 -24
- package/package.json +3 -3
- package/build.js +0 -30
@@ -1,468 +1,530 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
4
11
|
};
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var run_user_scripts_exports = {};
|
30
|
+
__export(run_user_scripts_exports, {
|
31
|
+
execCommand: () => execCommand,
|
32
|
+
getEnvForPackageManager: () => getEnvForPackageManager,
|
33
|
+
getNodeBinPath: () => getNodeBinPath,
|
34
|
+
getNodeBinPaths: () => getNodeBinPaths,
|
35
|
+
getNodeVersion: () => getNodeVersion,
|
36
|
+
getScriptName: () => getScriptName,
|
37
|
+
getSpawnOptions: () => getSpawnOptions,
|
38
|
+
installDependencies: () => installDependencies,
|
39
|
+
runBundleInstall: () => runBundleInstall,
|
40
|
+
runCustomInstallCommand: () => runCustomInstallCommand,
|
41
|
+
runNpmInstall: () => runNpmInstall,
|
42
|
+
runPackageJsonScript: () => runPackageJsonScript,
|
43
|
+
runPipInstall: () => runPipInstall,
|
44
|
+
runShellScript: () => runShellScript,
|
45
|
+
scanParentDirs: () => scanParentDirs,
|
46
|
+
spawnAsync: () => spawnAsync,
|
47
|
+
spawnCommand: () => spawnCommand,
|
48
|
+
traverseUpDirectories: () => traverseUpDirectories,
|
49
|
+
walkParentDirs: () => walkParentDirs
|
50
|
+
});
|
51
|
+
module.exports = __toCommonJS(run_user_scripts_exports);
|
52
|
+
var import_assert = __toESM(require("assert"));
|
53
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
54
|
+
var import_path = __toESM(require("path"));
|
55
|
+
var import_async_sema = __toESM(require("async-sema"));
|
56
|
+
var import_cross_spawn = __toESM(require("cross-spawn"));
|
57
|
+
var import_semver = require("semver");
|
58
|
+
var import_util = require("util");
|
59
|
+
var import_debug = __toESM(require("../debug"));
|
60
|
+
var import_errors = require("../errors");
|
61
|
+
var import_node_version = require("./node-version");
|
62
|
+
var import_read_config_file = require("./read-config-file");
|
63
|
+
var import_clone_env = require("../clone-env");
|
64
|
+
const runNpmInstallSema = new import_async_sema.default(1);
|
21
65
|
function spawnAsync(command, args, opts = {}) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
: stderrLogs.map(line => line.toString()).join(''),
|
42
|
-
}));
|
43
|
-
});
|
66
|
+
return new Promise((resolve, reject) => {
|
67
|
+
const stderrLogs = [];
|
68
|
+
opts = { stdio: "inherit", ...opts };
|
69
|
+
const child = (0, import_cross_spawn.default)(command, args, opts);
|
70
|
+
if (opts.stdio === "pipe" && child.stderr) {
|
71
|
+
child.stderr.on("data", (data) => stderrLogs.push(data));
|
72
|
+
}
|
73
|
+
child.on("error", reject);
|
74
|
+
child.on("close", (code, signal) => {
|
75
|
+
if (code === 0 || opts.ignoreNon0Exit) {
|
76
|
+
return resolve();
|
77
|
+
}
|
78
|
+
const cmd = opts.prettyCommand ? `Command "${opts.prettyCommand}"` : "Command";
|
79
|
+
reject(
|
80
|
+
new import_errors.NowBuildError({
|
81
|
+
code: `BUILD_UTILS_SPAWN_${code || signal}`,
|
82
|
+
message: opts.stdio === "inherit" ? `${cmd} exited with ${code || signal}` : stderrLogs.map((line) => line.toString()).join("")
|
83
|
+
})
|
84
|
+
);
|
44
85
|
});
|
86
|
+
});
|
45
87
|
}
|
46
|
-
exports.spawnAsync = spawnAsync;
|
47
88
|
function spawnCommand(command, options = {}) {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
89
|
+
const opts = { ...options, prettyCommand: command };
|
90
|
+
if (process.platform === "win32") {
|
91
|
+
return (0, import_cross_spawn.default)("cmd.exe", ["/C", command], opts);
|
92
|
+
}
|
93
|
+
return (0, import_cross_spawn.default)("sh", ["-c", command], opts);
|
53
94
|
}
|
54
|
-
exports.spawnCommand = spawnCommand;
|
55
95
|
async function execCommand(command, options = {}) {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return true;
|
96
|
+
const opts = { ...options, prettyCommand: command };
|
97
|
+
if (process.platform === "win32") {
|
98
|
+
await spawnAsync("cmd.exe", ["/C", command], opts);
|
99
|
+
} else {
|
100
|
+
await spawnAsync("sh", ["-c", command], opts);
|
101
|
+
}
|
102
|
+
return true;
|
64
103
|
}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
104
|
+
function* traverseUpDirectories({
|
105
|
+
start,
|
106
|
+
base
|
107
|
+
}) {
|
108
|
+
let current = import_path.default.normalize(start);
|
109
|
+
const normalizedRoot = base ? import_path.default.normalize(base) : void 0;
|
110
|
+
while (current) {
|
111
|
+
yield current;
|
112
|
+
if (current === normalizedRoot)
|
113
|
+
break;
|
114
|
+
const next = import_path.default.join(current, "..");
|
115
|
+
current = next === current ? void 0 : next;
|
116
|
+
}
|
77
117
|
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
const dir = path_1.default.dirname(lockfilePath || cwd);
|
85
|
-
return path_1.default.join(dir, 'node_modules', '.bin');
|
118
|
+
async function getNodeBinPath({
|
119
|
+
cwd
|
120
|
+
}) {
|
121
|
+
const { lockfilePath } = await scanParentDirs(cwd);
|
122
|
+
const dir = import_path.default.dirname(lockfilePath || cwd);
|
123
|
+
return import_path.default.join(dir, "node_modules", ".bin");
|
86
124
|
}
|
87
|
-
|
88
|
-
|
89
|
-
|
125
|
+
function getNodeBinPaths({
|
126
|
+
start,
|
127
|
+
base
|
128
|
+
}) {
|
129
|
+
return Array.from(traverseUpDirectories({ start, base })).map(
|
130
|
+
(dir) => import_path.default.join(dir, "node_modules/.bin")
|
131
|
+
);
|
90
132
|
}
|
91
|
-
exports.getNodeBinPaths = getNodeBinPaths;
|
92
133
|
async function chmodPlusX(fsPath) {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
134
|
+
const s = await import_fs_extra.default.stat(fsPath);
|
135
|
+
const newMode = s.mode | 64 | 8 | 1;
|
136
|
+
if (s.mode === newMode)
|
137
|
+
return;
|
138
|
+
const base8 = newMode.toString(8).slice(-3);
|
139
|
+
await import_fs_extra.default.chmod(fsPath, base8);
|
99
140
|
}
|
100
141
|
async function runShellScript(fsPath, args = [], spawnOpts) {
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
142
|
+
(0, import_assert.default)(import_path.default.isAbsolute(fsPath));
|
143
|
+
const destPath = import_path.default.dirname(fsPath);
|
144
|
+
await chmodPlusX(fsPath);
|
145
|
+
const command = `./${import_path.default.basename(fsPath)}`;
|
146
|
+
await spawnAsync(command, args, {
|
147
|
+
...spawnOpts,
|
148
|
+
cwd: destPath,
|
149
|
+
prettyCommand: command
|
150
|
+
});
|
151
|
+
return true;
|
111
152
|
}
|
112
|
-
exports.runShellScript = runShellScript;
|
113
153
|
function getSpawnOptions(meta, nodeVersion) {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
pathSegments.unshift(`/node${nodeVersion.major}/bin`);
|
130
|
-
}
|
131
|
-
opts.env.PATH = pathSegments.filter(Boolean).join(path_1.default.delimiter);
|
154
|
+
const opts = {
|
155
|
+
env: (0, import_clone_env.cloneEnv)(process.env)
|
156
|
+
};
|
157
|
+
if (!meta.isDev) {
|
158
|
+
let found = false;
|
159
|
+
const oldPath = opts.env.PATH || process.env.PATH || "";
|
160
|
+
const pathSegments = oldPath.split(import_path.default.delimiter).map((segment) => {
|
161
|
+
if (/^\/node[0-9]+\/bin/.test(segment)) {
|
162
|
+
found = true;
|
163
|
+
return `/node${nodeVersion.major}/bin`;
|
164
|
+
}
|
165
|
+
return segment;
|
166
|
+
});
|
167
|
+
if (!found) {
|
168
|
+
pathSegments.unshift(`/node${nodeVersion.major}/bin`);
|
132
169
|
}
|
133
|
-
|
170
|
+
opts.env.PATH = pathSegments.filter(Boolean).join(import_path.default.delimiter);
|
171
|
+
}
|
172
|
+
return opts;
|
134
173
|
}
|
135
|
-
exports.getSpawnOptions = getSpawnOptions;
|
136
174
|
async function getNodeVersion(destPath, nodeVersionFallback = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}) {
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
175
|
+
const latest = (0, import_node_version.getLatestNodeVersion)();
|
176
|
+
if (meta.isDev) {
|
177
|
+
return { ...latest, runtime: "nodejs" };
|
178
|
+
}
|
179
|
+
const { packageJson } = await scanParentDirs(destPath, true);
|
180
|
+
let nodeVersion = config.nodeVersion || nodeVersionFallback;
|
181
|
+
let isAuto = true;
|
182
|
+
if (packageJson?.engines?.node) {
|
183
|
+
const { node } = packageJson.engines;
|
184
|
+
if (nodeVersion && (0, import_semver.validRange)(node) && !(0, import_semver.intersects)(nodeVersion, node)) {
|
185
|
+
console.warn(
|
186
|
+
`Warning: Due to "engines": { "node": "${node}" } in your \`package.json\` file, the Node.js Version defined in your Project Settings ("${nodeVersion}") will not apply. Learn More: http://vercel.link/node-version`
|
187
|
+
);
|
188
|
+
} else if ((0, import_semver.coerce)(node)?.raw === node) {
|
189
|
+
console.warn(
|
190
|
+
`Warning: Detected "engines": { "node": "${node}" } in your \`package.json\` with major.minor.patch, but only major Node.js Version can be selected. Learn More: http://vercel.link/node-version`
|
191
|
+
);
|
192
|
+
} else if ((0, import_semver.validRange)(node) && (0, import_semver.intersects)(`${latest.major + 1}.x`, node)) {
|
193
|
+
console.warn(
|
194
|
+
`Warning: Detected "engines": { "node": "${node}" } in your \`package.json\` that will automatically upgrade when a new major Node.js Version is released. Learn More: http://vercel.link/node-version`
|
195
|
+
);
|
141
196
|
}
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
const { node } = packageJson.engines;
|
147
|
-
if (nodeVersion && (0, semver_1.validRange)(node) && !(0, semver_1.intersects)(nodeVersion, node)) {
|
148
|
-
console.warn(`Warning: Due to "engines": { "node": "${node}" } in your \`package.json\` file, the Node.js Version defined in your Project Settings ("${nodeVersion}") will not apply. Learn More: http://vercel.link/node-version`);
|
149
|
-
}
|
150
|
-
else if ((0, semver_1.coerce)(node)?.raw === node) {
|
151
|
-
console.warn(`Warning: Detected "engines": { "node": "${node}" } in your \`package.json\` with major.minor.patch, but only major Node.js Version can be selected. Learn More: http://vercel.link/node-version`);
|
152
|
-
}
|
153
|
-
else if ((0, semver_1.validRange)(node) && (0, semver_1.intersects)(`${latest.major + 1}.x`, node)) {
|
154
|
-
console.warn(`Warning: Detected "engines": { "node": "${node}" } in your \`package.json\` that will automatically upgrade when a new major Node.js Version is released. Learn More: http://vercel.link/node-version`);
|
155
|
-
}
|
156
|
-
nodeVersion = node;
|
157
|
-
isAuto = false;
|
158
|
-
}
|
159
|
-
return (0, node_version_1.getSupportedNodeVersion)(nodeVersion, isAuto);
|
197
|
+
nodeVersion = node;
|
198
|
+
isAuto = false;
|
199
|
+
}
|
200
|
+
return (0, import_node_version.getSupportedNodeVersion)(nodeVersion, isAuto);
|
160
201
|
}
|
161
|
-
exports.getNodeVersion = getNodeVersion;
|
162
202
|
async function scanParentDirs(destPath, readPackageJson = false) {
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
203
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
204
|
+
const pkgJsonPath = await walkParentDirs({
|
205
|
+
base: "/",
|
206
|
+
start: destPath,
|
207
|
+
filename: "package.json"
|
208
|
+
});
|
209
|
+
const packageJson = readPackageJson && pkgJsonPath ? JSON.parse(await import_fs_extra.default.readFile(pkgJsonPath, "utf8")) : void 0;
|
210
|
+
const [yarnLockPath, npmLockPath, pnpmLockPath, bunLockPath] = await walkParentDirsMulti({
|
211
|
+
base: "/",
|
212
|
+
start: destPath,
|
213
|
+
filenames: [
|
214
|
+
"yarn.lock",
|
215
|
+
"package-lock.json",
|
216
|
+
"pnpm-lock.yaml",
|
217
|
+
"bun.lockb"
|
218
|
+
]
|
219
|
+
});
|
220
|
+
let lockfilePath;
|
221
|
+
let lockfileVersion;
|
222
|
+
let cliType = "yarn";
|
223
|
+
const [hasYarnLock, packageLockJson, pnpmLockYaml, bunLockBin] = await Promise.all([
|
224
|
+
Boolean(yarnLockPath),
|
225
|
+
npmLockPath ? (0, import_read_config_file.readConfigFile)(npmLockPath) : null,
|
226
|
+
pnpmLockPath ? (0, import_read_config_file.readConfigFile)(pnpmLockPath) : null,
|
227
|
+
bunLockPath ? import_fs_extra.default.readFile(bunLockPath, "utf8") : null
|
228
|
+
]);
|
229
|
+
if (hasYarnLock) {
|
230
|
+
cliType = "yarn";
|
231
|
+
lockfilePath = yarnLockPath;
|
232
|
+
} else if (pnpmLockYaml) {
|
233
|
+
cliType = "pnpm";
|
234
|
+
lockfilePath = pnpmLockPath;
|
235
|
+
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
236
|
+
} else if (packageLockJson) {
|
237
|
+
cliType = "npm";
|
238
|
+
lockfilePath = npmLockPath;
|
239
|
+
lockfileVersion = packageLockJson.lockfileVersion;
|
240
|
+
} else if (bunLockBin) {
|
241
|
+
cliType = "bun";
|
242
|
+
lockfilePath = bunLockPath;
|
243
|
+
lockfileVersion = 0;
|
244
|
+
}
|
245
|
+
const packageJsonPath = pkgJsonPath || void 0;
|
246
|
+
return {
|
247
|
+
cliType,
|
248
|
+
packageJson,
|
249
|
+
lockfilePath,
|
250
|
+
lockfileVersion,
|
251
|
+
packageJsonPath
|
252
|
+
};
|
212
253
|
}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
254
|
+
async function walkParentDirs({
|
255
|
+
base,
|
256
|
+
start,
|
257
|
+
filename
|
258
|
+
}) {
|
259
|
+
(0, import_assert.default)(import_path.default.isAbsolute(base), 'Expected "base" to be absolute path');
|
260
|
+
(0, import_assert.default)(import_path.default.isAbsolute(start), 'Expected "start" to be absolute path');
|
261
|
+
for (const dir of traverseUpDirectories({ start, base })) {
|
262
|
+
const fullPath = import_path.default.join(dir, filename);
|
263
|
+
if (await import_fs_extra.default.pathExists(fullPath)) {
|
264
|
+
return fullPath;
|
223
265
|
}
|
224
|
-
|
266
|
+
}
|
267
|
+
return null;
|
225
268
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
269
|
+
async function walkParentDirsMulti({
|
270
|
+
base,
|
271
|
+
start,
|
272
|
+
filenames
|
273
|
+
}) {
|
274
|
+
for (const dir of traverseUpDirectories({ start, base })) {
|
275
|
+
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
276
|
+
const existResults = await Promise.all(
|
277
|
+
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
278
|
+
);
|
279
|
+
const foundOneOrMore = existResults.some((b) => b);
|
280
|
+
if (foundOneOrMore) {
|
281
|
+
return fullPaths.map((f, i) => existResults[i] ? f : void 0);
|
235
282
|
}
|
236
|
-
|
283
|
+
}
|
284
|
+
return [];
|
237
285
|
}
|
238
286
|
function isSet(v) {
|
239
|
-
|
287
|
+
return v?.constructor?.name === "Set";
|
240
288
|
}
|
241
289
|
async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion) {
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
meta.runNpmInstallSet.add(packageJsonPath);
|
262
|
-
}
|
263
|
-
}
|
290
|
+
if (meta?.isDev) {
|
291
|
+
(0, import_debug.default)("Skipping dependency installation because dev mode is enabled");
|
292
|
+
return false;
|
293
|
+
}
|
294
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
295
|
+
try {
|
296
|
+
await runNpmInstallSema.acquire();
|
297
|
+
const { cliType, packageJsonPath, lockfileVersion } = await scanParentDirs(
|
298
|
+
destPath
|
299
|
+
);
|
300
|
+
if (meta && packageJsonPath && args.length === 0) {
|
301
|
+
if (!isSet(meta.runNpmInstallSet)) {
|
302
|
+
meta.runNpmInstallSet = /* @__PURE__ */ new Set();
|
303
|
+
}
|
304
|
+
if (isSet(meta.runNpmInstallSet)) {
|
305
|
+
if (meta.runNpmInstallSet.has(packageJsonPath)) {
|
306
|
+
return false;
|
307
|
+
} else {
|
308
|
+
meta.runNpmInstallSet.add(packageJsonPath);
|
264
309
|
}
|
265
|
-
|
266
|
-
console.log('Installing dependencies...');
|
267
|
-
(0, debug_1.default)(`Installing to ${destPath}`);
|
268
|
-
const opts = { cwd: destPath, ...spawnOpts };
|
269
|
-
const env = (0, clone_env_1.cloneEnv)(opts.env || process.env);
|
270
|
-
delete env.NODE_ENV;
|
271
|
-
opts.env = getEnvForPackageManager({
|
272
|
-
cliType,
|
273
|
-
lockfileVersion,
|
274
|
-
nodeVersion,
|
275
|
-
env,
|
276
|
-
});
|
277
|
-
let commandArgs;
|
278
|
-
const isPotentiallyBrokenNpm = cliType === 'npm' &&
|
279
|
-
(nodeVersion?.major === 16 ||
|
280
|
-
opts.env.PATH?.includes('/node16/bin-npm7')) &&
|
281
|
-
!args.includes('--legacy-peer-deps') &&
|
282
|
-
spawnOpts?.env?.ENABLE_EXPERIMENTAL_COREPACK !== '1';
|
283
|
-
if (cliType === 'npm') {
|
284
|
-
opts.prettyCommand = 'npm install';
|
285
|
-
commandArgs = args
|
286
|
-
.filter(a => a !== '--prefer-offline')
|
287
|
-
.concat(['install', '--no-audit', '--unsafe-perm']);
|
288
|
-
if (isPotentiallyBrokenNpm &&
|
289
|
-
spawnOpts?.env?.VERCEL_NPM_LEGACY_PEER_DEPS === '1') {
|
290
|
-
// Starting in npm@8.6.0, if you ran `npm install --legacy-peer-deps`,
|
291
|
-
// and then later ran `npm install`, it would fail. So the only way
|
292
|
-
// to safely upgrade npm from npm@8.5.0 is to set this flag. The docs
|
293
|
-
// say this flag is not recommended so its is behind a feature flag
|
294
|
-
// so we can remove it in node@18, which can introduce breaking changes.
|
295
|
-
// See https://docs.npmjs.com/cli/v8/using-npm/config#legacy-peer-deps
|
296
|
-
commandArgs.push('--legacy-peer-deps');
|
297
|
-
}
|
298
|
-
}
|
299
|
-
else if (cliType === 'pnpm') {
|
300
|
-
// PNPM's install command is similar to NPM's but without the audit nonsense
|
301
|
-
// @see options https://pnpm.io/cli/install
|
302
|
-
opts.prettyCommand = 'pnpm install';
|
303
|
-
commandArgs = args
|
304
|
-
.filter(a => a !== '--prefer-offline')
|
305
|
-
.concat(['install', '--unsafe-perm']);
|
306
|
-
}
|
307
|
-
else {
|
308
|
-
opts.prettyCommand = 'yarn install';
|
309
|
-
commandArgs = ['install', ...args];
|
310
|
-
}
|
311
|
-
if (process.env.NPM_ONLY_PRODUCTION) {
|
312
|
-
commandArgs.push('--production');
|
313
|
-
}
|
314
|
-
try {
|
315
|
-
await spawnAsync(cliType, commandArgs, opts);
|
316
|
-
}
|
317
|
-
catch (err) {
|
318
|
-
const potentialErrorPath = path_1.default.join(process.env.HOME || '/', '.npm', 'eresolve-report.txt');
|
319
|
-
if (isPotentiallyBrokenNpm &&
|
320
|
-
!commandArgs.includes('--legacy-peer-deps') &&
|
321
|
-
fs_extra_1.default.existsSync(potentialErrorPath)) {
|
322
|
-
console.warn('Warning: Retrying "Install Command" with `--legacy-peer-deps` which may accept a potentially broken dependency and slow install time.');
|
323
|
-
commandArgs.push('--legacy-peer-deps');
|
324
|
-
await spawnAsync(cliType, commandArgs, opts);
|
325
|
-
}
|
326
|
-
else {
|
327
|
-
throw err;
|
328
|
-
}
|
329
|
-
}
|
330
|
-
(0, debug_1.default)(`Install complete [${Date.now() - installTime}ms]`);
|
331
|
-
return true;
|
310
|
+
}
|
332
311
|
}
|
333
|
-
|
334
|
-
|
312
|
+
const installTime = Date.now();
|
313
|
+
console.log("Installing dependencies...");
|
314
|
+
(0, import_debug.default)(`Installing to ${destPath}`);
|
315
|
+
const opts = { cwd: destPath, ...spawnOpts };
|
316
|
+
const env = (0, import_clone_env.cloneEnv)(opts.env || process.env);
|
317
|
+
delete env.NODE_ENV;
|
318
|
+
opts.env = getEnvForPackageManager({
|
319
|
+
cliType,
|
320
|
+
lockfileVersion,
|
321
|
+
nodeVersion,
|
322
|
+
env
|
323
|
+
});
|
324
|
+
let commandArgs;
|
325
|
+
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";
|
326
|
+
if (cliType === "npm") {
|
327
|
+
opts.prettyCommand = "npm install";
|
328
|
+
commandArgs = args.filter((a) => a !== "--prefer-offline").concat(["install", "--no-audit", "--unsafe-perm"]);
|
329
|
+
if (isPotentiallyBrokenNpm && spawnOpts?.env?.VERCEL_NPM_LEGACY_PEER_DEPS === "1") {
|
330
|
+
commandArgs.push("--legacy-peer-deps");
|
331
|
+
}
|
332
|
+
} else if (cliType === "pnpm") {
|
333
|
+
opts.prettyCommand = "pnpm install";
|
334
|
+
commandArgs = args.filter((a) => a !== "--prefer-offline").concat(["install", "--unsafe-perm"]);
|
335
|
+
} else if (cliType === "bun") {
|
336
|
+
opts.prettyCommand = "bun install";
|
337
|
+
commandArgs = ["install", ...args];
|
338
|
+
} else {
|
339
|
+
opts.prettyCommand = "yarn install";
|
340
|
+
commandArgs = ["install", ...args];
|
335
341
|
}
|
342
|
+
if (process.env.NPM_ONLY_PRODUCTION) {
|
343
|
+
commandArgs.push("--production");
|
344
|
+
}
|
345
|
+
try {
|
346
|
+
await spawnAsync(cliType, commandArgs, opts);
|
347
|
+
} catch (err) {
|
348
|
+
const potentialErrorPath = import_path.default.join(
|
349
|
+
process.env.HOME || "/",
|
350
|
+
".npm",
|
351
|
+
"eresolve-report.txt"
|
352
|
+
);
|
353
|
+
if (isPotentiallyBrokenNpm && !commandArgs.includes("--legacy-peer-deps") && import_fs_extra.default.existsSync(potentialErrorPath)) {
|
354
|
+
console.warn(
|
355
|
+
'Warning: Retrying "Install Command" with `--legacy-peer-deps` which may accept a potentially broken dependency and slow install time.'
|
356
|
+
);
|
357
|
+
commandArgs.push("--legacy-peer-deps");
|
358
|
+
await spawnAsync(cliType, commandArgs, opts);
|
359
|
+
} else {
|
360
|
+
throw err;
|
361
|
+
}
|
362
|
+
}
|
363
|
+
(0, import_debug.default)(`Install complete [${Date.now() - installTime}ms]`);
|
364
|
+
return true;
|
365
|
+
} finally {
|
366
|
+
runNpmInstallSema.release();
|
367
|
+
}
|
336
368
|
}
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
}
|
369
|
+
function getEnvForPackageManager({
|
370
|
+
cliType,
|
371
|
+
lockfileVersion,
|
372
|
+
nodeVersion,
|
373
|
+
env
|
374
|
+
}) {
|
375
|
+
const newEnv = { ...env };
|
376
|
+
const oldPath = env.PATH + "";
|
377
|
+
const npm7 = "/node16/bin-npm7";
|
378
|
+
const pnpm7 = "/pnpm7/node_modules/.bin";
|
379
|
+
const pnpm8 = "/pnpm8/node_modules/.bin";
|
380
|
+
const bun1 = "/bun1";
|
381
|
+
const corepackEnabled = env.ENABLE_EXPERIMENTAL_COREPACK === "1";
|
382
|
+
if (cliType === "npm") {
|
383
|
+
if (typeof lockfileVersion === "number" && lockfileVersion >= 2 && (nodeVersion?.major || 0) < 16 && !oldPath.includes(npm7) && !corepackEnabled) {
|
384
|
+
newEnv.PATH = `${npm7}${import_path.default.delimiter}${oldPath}`;
|
385
|
+
console.log("Detected `package-lock.json` generated by npm 7+");
|
355
386
|
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
!oldPath.includes(pnpm8) &&
|
368
|
-
!corepackEnabled) {
|
369
|
-
// Ensure that pnpm 8 is at the beginning of the `$PATH`
|
370
|
-
newEnv.PATH = `${pnpm8}${path_1.default.delimiter}${oldPath}`;
|
371
|
-
console.log(`Detected \`pnpm-lock.yaml\` version ${lockfileVersion} generated by pnpm 8...`);
|
372
|
-
}
|
387
|
+
} else if (cliType === "pnpm") {
|
388
|
+
if (typeof lockfileVersion === "number" && lockfileVersion === 5.4 && !oldPath.includes(pnpm7) && !corepackEnabled) {
|
389
|
+
newEnv.PATH = `${pnpm7}${import_path.default.delimiter}${oldPath}`;
|
390
|
+
console.log(
|
391
|
+
`Detected \`pnpm-lock.yaml\` version ${lockfileVersion} generated by pnpm 7`
|
392
|
+
);
|
393
|
+
} else if (typeof lockfileVersion === "number" && lockfileVersion >= 6 && !oldPath.includes(pnpm8) && !corepackEnabled) {
|
394
|
+
newEnv.PATH = `${pnpm8}${import_path.default.delimiter}${oldPath}`;
|
395
|
+
console.log(
|
396
|
+
`Detected \`pnpm-lock.yaml\` version ${lockfileVersion} generated by pnpm 8`
|
397
|
+
);
|
373
398
|
}
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
399
|
+
} else if (cliType === "bun") {
|
400
|
+
if (!oldPath.includes(bun1) && !corepackEnabled) {
|
401
|
+
newEnv.PATH = `${bun1}${import_path.default.delimiter}${oldPath}`;
|
402
|
+
console.log("Detected `bun.lockb` generated by Bun");
|
403
|
+
console.warn(
|
404
|
+
"Warning: Bun is used as a package manager at build time only, not at runtime with Functions"
|
405
|
+
);
|
406
|
+
}
|
407
|
+
} else {
|
408
|
+
if (!env.YARN_NODE_LINKER) {
|
409
|
+
newEnv.YARN_NODE_LINKER = "node-modules";
|
379
410
|
}
|
380
|
-
|
411
|
+
}
|
412
|
+
return newEnv;
|
381
413
|
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
414
|
+
async function runCustomInstallCommand({
|
415
|
+
destPath,
|
416
|
+
installCommand,
|
417
|
+
nodeVersion,
|
418
|
+
spawnOpts
|
419
|
+
}) {
|
420
|
+
console.log(`Running "install" command: \`${installCommand}\`...`);
|
421
|
+
const { cliType, lockfileVersion } = await scanParentDirs(destPath);
|
422
|
+
const env = getEnvForPackageManager({
|
423
|
+
cliType,
|
424
|
+
lockfileVersion,
|
425
|
+
nodeVersion,
|
426
|
+
env: spawnOpts?.env || {}
|
427
|
+
});
|
428
|
+
(0, import_debug.default)(`Running with $PATH:`, env?.PATH || "");
|
429
|
+
await execCommand(installCommand, {
|
430
|
+
...spawnOpts,
|
431
|
+
env,
|
432
|
+
cwd: destPath
|
433
|
+
});
|
398
434
|
}
|
399
|
-
exports.runCustomInstallCommand = runCustomInstallCommand;
|
400
435
|
async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
436
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
437
|
+
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
438
|
+
destPath,
|
439
|
+
true
|
440
|
+
);
|
441
|
+
const scriptName = getScriptName(
|
442
|
+
packageJson,
|
443
|
+
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
444
|
+
);
|
445
|
+
if (!scriptName)
|
446
|
+
return false;
|
447
|
+
(0, import_debug.default)("Running user script...");
|
448
|
+
const runScriptTime = Date.now();
|
449
|
+
const opts = {
|
450
|
+
cwd: destPath,
|
451
|
+
...spawnOpts,
|
452
|
+
env: getEnvForPackageManager({
|
453
|
+
cliType,
|
454
|
+
lockfileVersion,
|
455
|
+
nodeVersion: void 0,
|
456
|
+
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env)
|
457
|
+
})
|
458
|
+
};
|
459
|
+
if (cliType === "npm") {
|
460
|
+
opts.prettyCommand = `npm run ${scriptName}`;
|
461
|
+
} else if (cliType === "pnpm") {
|
462
|
+
opts.prettyCommand = `pnpm run ${scriptName}`;
|
463
|
+
} else if (cliType === "bun") {
|
464
|
+
opts.prettyCommand = `bun run ${scriptName}`;
|
465
|
+
} else {
|
466
|
+
opts.prettyCommand = `yarn run ${scriptName}`;
|
467
|
+
}
|
468
|
+
console.log(`Running "${opts.prettyCommand}"`);
|
469
|
+
await spawnAsync(cliType, ["run", scriptName], opts);
|
470
|
+
(0, import_debug.default)(`Script complete [${Date.now() - runScriptTime}ms]`);
|
471
|
+
return true;
|
431
472
|
}
|
432
|
-
exports.runPackageJsonScript = runPackageJsonScript;
|
433
473
|
async function runBundleInstall(destPath, args = [], spawnOpts, meta) {
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
474
|
+
if (meta && meta.isDev) {
|
475
|
+
(0, import_debug.default)("Skipping dependency installation because dev mode is enabled");
|
476
|
+
return;
|
477
|
+
}
|
478
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
479
|
+
const opts = { ...spawnOpts, cwd: destPath, prettyCommand: "bundle install" };
|
480
|
+
await spawnAsync("bundle", args.concat(["install"]), opts);
|
441
481
|
}
|
442
|
-
exports.runBundleInstall = runBundleInstall;
|
443
482
|
async function runPipInstall(destPath, args = [], spawnOpts, meta) {
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
483
|
+
if (meta && meta.isDev) {
|
484
|
+
(0, import_debug.default)("Skipping dependency installation because dev mode is enabled");
|
485
|
+
return;
|
486
|
+
}
|
487
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
488
|
+
const opts = { ...spawnOpts, cwd: destPath, prettyCommand: "pip3 install" };
|
489
|
+
await spawnAsync(
|
490
|
+
"pip3",
|
491
|
+
["install", "--disable-pip-version-check", ...args],
|
492
|
+
opts
|
493
|
+
);
|
451
494
|
}
|
452
|
-
exports.runPipInstall = runPipInstall;
|
453
495
|
function getScriptName(pkg, possibleNames) {
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
}
|
496
|
+
if (pkg?.scripts) {
|
497
|
+
for (const name of possibleNames) {
|
498
|
+
if (name in pkg.scripts) {
|
499
|
+
return name;
|
500
|
+
}
|
460
501
|
}
|
461
|
-
|
502
|
+
}
|
503
|
+
return null;
|
462
504
|
}
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
505
|
+
const installDependencies = (0, import_util.deprecate)(
|
506
|
+
runNpmInstall,
|
507
|
+
"installDependencies() is deprecated. Please use runNpmInstall() instead."
|
508
|
+
);
|
509
|
+
// Annotate the CommonJS export names for ESM import in node:
|
510
|
+
0 && (module.exports = {
|
511
|
+
execCommand,
|
512
|
+
getEnvForPackageManager,
|
513
|
+
getNodeBinPath,
|
514
|
+
getNodeBinPaths,
|
515
|
+
getNodeVersion,
|
516
|
+
getScriptName,
|
517
|
+
getSpawnOptions,
|
518
|
+
installDependencies,
|
519
|
+
runBundleInstall,
|
520
|
+
runCustomInstallCommand,
|
521
|
+
runNpmInstall,
|
522
|
+
runPackageJsonScript,
|
523
|
+
runPipInstall,
|
524
|
+
runShellScript,
|
525
|
+
scanParentDirs,
|
526
|
+
spawnAsync,
|
527
|
+
spawnCommand,
|
528
|
+
traverseUpDirectories,
|
529
|
+
walkParentDirs
|
530
|
+
});
|