@vercel/build-utils 7.1.0 → 7.1.1
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 +8 -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.js +457 -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 +22266 -29403
- package/dist/lambda.js +208 -144
- package/dist/nodejs-lambda.js +40 -12
- package/dist/prerender.js +109 -64
- package/dist/schemas.js +83 -57
- package/dist/should-serve.js +43 -16
- package/dist/types.d.ts +4 -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,506 @@
|
|
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
|
-
const packageJsonPath = pkgJsonPath || undefined;
|
205
|
-
return {
|
206
|
-
cliType,
|
207
|
-
packageJson,
|
208
|
-
lockfilePath,
|
209
|
-
lockfileVersion,
|
210
|
-
packageJsonPath,
|
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] = await walkParentDirsMulti({
|
211
|
+
base: "/",
|
212
|
+
start: destPath,
|
213
|
+
filenames: ["yarn.lock", "package-lock.json", "pnpm-lock.yaml"]
|
214
|
+
});
|
215
|
+
let lockfilePath;
|
216
|
+
let lockfileVersion;
|
217
|
+
let cliType = "yarn";
|
218
|
+
const [hasYarnLock, packageLockJson, pnpmLockYaml] = await Promise.all([
|
219
|
+
Boolean(yarnLockPath),
|
220
|
+
npmLockPath ? (0, import_read_config_file.readConfigFile)(npmLockPath) : null,
|
221
|
+
pnpmLockPath ? (0, import_read_config_file.readConfigFile)(pnpmLockPath) : null
|
222
|
+
]);
|
223
|
+
if (hasYarnLock) {
|
224
|
+
cliType = "yarn";
|
225
|
+
lockfilePath = yarnLockPath;
|
226
|
+
} else if (pnpmLockYaml) {
|
227
|
+
cliType = "pnpm";
|
228
|
+
lockfilePath = pnpmLockPath;
|
229
|
+
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
230
|
+
} else if (packageLockJson) {
|
231
|
+
cliType = "npm";
|
232
|
+
lockfilePath = npmLockPath;
|
233
|
+
lockfileVersion = packageLockJson.lockfileVersion;
|
234
|
+
}
|
235
|
+
const packageJsonPath = pkgJsonPath || void 0;
|
236
|
+
return {
|
237
|
+
cliType,
|
238
|
+
packageJson,
|
239
|
+
lockfilePath,
|
240
|
+
lockfileVersion,
|
241
|
+
packageJsonPath
|
242
|
+
};
|
212
243
|
}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
244
|
+
async function walkParentDirs({
|
245
|
+
base,
|
246
|
+
start,
|
247
|
+
filename
|
248
|
+
}) {
|
249
|
+
(0, import_assert.default)(import_path.default.isAbsolute(base), 'Expected "base" to be absolute path');
|
250
|
+
(0, import_assert.default)(import_path.default.isAbsolute(start), 'Expected "start" to be absolute path');
|
251
|
+
for (const dir of traverseUpDirectories({ start, base })) {
|
252
|
+
const fullPath = import_path.default.join(dir, filename);
|
253
|
+
if (await import_fs_extra.default.pathExists(fullPath)) {
|
254
|
+
return fullPath;
|
223
255
|
}
|
224
|
-
|
256
|
+
}
|
257
|
+
return null;
|
225
258
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
259
|
+
async function walkParentDirsMulti({
|
260
|
+
base,
|
261
|
+
start,
|
262
|
+
filenames
|
263
|
+
}) {
|
264
|
+
for (const dir of traverseUpDirectories({ start, base })) {
|
265
|
+
const fullPaths = filenames.map((f) => import_path.default.join(dir, f));
|
266
|
+
const existResults = await Promise.all(
|
267
|
+
fullPaths.map((f) => import_fs_extra.default.pathExists(f))
|
268
|
+
);
|
269
|
+
const foundOneOrMore = existResults.some((b) => b);
|
270
|
+
if (foundOneOrMore) {
|
271
|
+
return fullPaths.map((f, i) => existResults[i] ? f : void 0);
|
235
272
|
}
|
236
|
-
|
273
|
+
}
|
274
|
+
return [];
|
237
275
|
}
|
238
276
|
function isSet(v) {
|
239
|
-
|
277
|
+
return v?.constructor?.name === "Set";
|
240
278
|
}
|
241
279
|
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
|
-
}
|
280
|
+
if (meta?.isDev) {
|
281
|
+
(0, import_debug.default)("Skipping dependency installation because dev mode is enabled");
|
282
|
+
return false;
|
283
|
+
}
|
284
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
285
|
+
try {
|
286
|
+
await runNpmInstallSema.acquire();
|
287
|
+
const { cliType, packageJsonPath, lockfileVersion } = await scanParentDirs(
|
288
|
+
destPath
|
289
|
+
);
|
290
|
+
if (meta && packageJsonPath && args.length === 0) {
|
291
|
+
if (!isSet(meta.runNpmInstallSet)) {
|
292
|
+
meta.runNpmInstallSet = /* @__PURE__ */ new Set();
|
293
|
+
}
|
294
|
+
if (isSet(meta.runNpmInstallSet)) {
|
295
|
+
if (meta.runNpmInstallSet.has(packageJsonPath)) {
|
296
|
+
return false;
|
297
|
+
} else {
|
298
|
+
meta.runNpmInstallSet.add(packageJsonPath);
|
264
299
|
}
|
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;
|
300
|
+
}
|
332
301
|
}
|
333
|
-
|
334
|
-
|
302
|
+
const installTime = Date.now();
|
303
|
+
console.log("Installing dependencies...");
|
304
|
+
(0, import_debug.default)(`Installing to ${destPath}`);
|
305
|
+
const opts = { cwd: destPath, ...spawnOpts };
|
306
|
+
const env = (0, import_clone_env.cloneEnv)(opts.env || process.env);
|
307
|
+
delete env.NODE_ENV;
|
308
|
+
opts.env = getEnvForPackageManager({
|
309
|
+
cliType,
|
310
|
+
lockfileVersion,
|
311
|
+
nodeVersion,
|
312
|
+
env
|
313
|
+
});
|
314
|
+
let commandArgs;
|
315
|
+
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";
|
316
|
+
if (cliType === "npm") {
|
317
|
+
opts.prettyCommand = "npm install";
|
318
|
+
commandArgs = args.filter((a) => a !== "--prefer-offline").concat(["install", "--no-audit", "--unsafe-perm"]);
|
319
|
+
if (isPotentiallyBrokenNpm && spawnOpts?.env?.VERCEL_NPM_LEGACY_PEER_DEPS === "1") {
|
320
|
+
commandArgs.push("--legacy-peer-deps");
|
321
|
+
}
|
322
|
+
} else if (cliType === "pnpm") {
|
323
|
+
opts.prettyCommand = "pnpm install";
|
324
|
+
commandArgs = args.filter((a) => a !== "--prefer-offline").concat(["install", "--unsafe-perm"]);
|
325
|
+
} else {
|
326
|
+
opts.prettyCommand = "yarn install";
|
327
|
+
commandArgs = ["install", ...args];
|
328
|
+
}
|
329
|
+
if (process.env.NPM_ONLY_PRODUCTION) {
|
330
|
+
commandArgs.push("--production");
|
331
|
+
}
|
332
|
+
try {
|
333
|
+
await spawnAsync(cliType, commandArgs, opts);
|
334
|
+
} catch (err) {
|
335
|
+
const potentialErrorPath = import_path.default.join(
|
336
|
+
process.env.HOME || "/",
|
337
|
+
".npm",
|
338
|
+
"eresolve-report.txt"
|
339
|
+
);
|
340
|
+
if (isPotentiallyBrokenNpm && !commandArgs.includes("--legacy-peer-deps") && import_fs_extra.default.existsSync(potentialErrorPath)) {
|
341
|
+
console.warn(
|
342
|
+
'Warning: Retrying "Install Command" with `--legacy-peer-deps` which may accept a potentially broken dependency and slow install time.'
|
343
|
+
);
|
344
|
+
commandArgs.push("--legacy-peer-deps");
|
345
|
+
await spawnAsync(cliType, commandArgs, opts);
|
346
|
+
} else {
|
347
|
+
throw err;
|
348
|
+
}
|
335
349
|
}
|
350
|
+
(0, import_debug.default)(`Install complete [${Date.now() - installTime}ms]`);
|
351
|
+
return true;
|
352
|
+
} finally {
|
353
|
+
runNpmInstallSema.release();
|
354
|
+
}
|
336
355
|
}
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
console.log('Detected `package-lock.json` generated by npm 7+...');
|
354
|
-
}
|
356
|
+
function getEnvForPackageManager({
|
357
|
+
cliType,
|
358
|
+
lockfileVersion,
|
359
|
+
nodeVersion,
|
360
|
+
env
|
361
|
+
}) {
|
362
|
+
const newEnv = { ...env };
|
363
|
+
const oldPath = env.PATH + "";
|
364
|
+
const npm7 = "/node16/bin-npm7";
|
365
|
+
const pnpm7 = "/pnpm7/node_modules/.bin";
|
366
|
+
const pnpm8 = "/pnpm8/node_modules/.bin";
|
367
|
+
const corepackEnabled = env.ENABLE_EXPERIMENTAL_COREPACK === "1";
|
368
|
+
if (cliType === "npm") {
|
369
|
+
if (typeof lockfileVersion === "number" && lockfileVersion >= 2 && (nodeVersion?.major || 0) < 16 && !oldPath.includes(npm7) && !corepackEnabled) {
|
370
|
+
newEnv.PATH = `${npm7}${import_path.default.delimiter}${oldPath}`;
|
371
|
+
console.log("Detected `package-lock.json` generated by npm 7+...");
|
355
372
|
}
|
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
|
-
}
|
373
|
+
} else if (cliType === "pnpm") {
|
374
|
+
if (typeof lockfileVersion === "number" && lockfileVersion === 5.4 && !oldPath.includes(pnpm7) && !corepackEnabled) {
|
375
|
+
newEnv.PATH = `${pnpm7}${import_path.default.delimiter}${oldPath}`;
|
376
|
+
console.log(
|
377
|
+
`Detected \`pnpm-lock.yaml\` version ${lockfileVersion} generated by pnpm 7...`
|
378
|
+
);
|
379
|
+
} else if (typeof lockfileVersion === "number" && lockfileVersion >= 6 && !oldPath.includes(pnpm8) && !corepackEnabled) {
|
380
|
+
newEnv.PATH = `${pnpm8}${import_path.default.delimiter}${oldPath}`;
|
381
|
+
console.log(
|
382
|
+
`Detected \`pnpm-lock.yaml\` version ${lockfileVersion} generated by pnpm 8...`
|
383
|
+
);
|
373
384
|
}
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
newEnv.YARN_NODE_LINKER = 'node-modules';
|
378
|
-
}
|
385
|
+
} else {
|
386
|
+
if (!env.YARN_NODE_LINKER) {
|
387
|
+
newEnv.YARN_NODE_LINKER = "node-modules";
|
379
388
|
}
|
380
|
-
|
389
|
+
}
|
390
|
+
return newEnv;
|
381
391
|
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
392
|
+
async function runCustomInstallCommand({
|
393
|
+
destPath,
|
394
|
+
installCommand,
|
395
|
+
nodeVersion,
|
396
|
+
spawnOpts
|
397
|
+
}) {
|
398
|
+
console.log(`Running "install" command: \`${installCommand}\`...`);
|
399
|
+
const { cliType, lockfileVersion } = await scanParentDirs(destPath);
|
400
|
+
const env = getEnvForPackageManager({
|
401
|
+
cliType,
|
402
|
+
lockfileVersion,
|
403
|
+
nodeVersion,
|
404
|
+
env: spawnOpts?.env || {}
|
405
|
+
});
|
406
|
+
(0, import_debug.default)(`Running with $PATH:`, env?.PATH || "");
|
407
|
+
await execCommand(installCommand, {
|
408
|
+
...spawnOpts,
|
409
|
+
env,
|
410
|
+
cwd: destPath
|
411
|
+
});
|
398
412
|
}
|
399
|
-
exports.runCustomInstallCommand = runCustomInstallCommand;
|
400
413
|
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
|
-
|
414
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
415
|
+
const { packageJson, cliType, lockfileVersion } = await scanParentDirs(
|
416
|
+
destPath,
|
417
|
+
true
|
418
|
+
);
|
419
|
+
const scriptName = getScriptName(
|
420
|
+
packageJson,
|
421
|
+
typeof scriptNames === "string" ? [scriptNames] : scriptNames
|
422
|
+
);
|
423
|
+
if (!scriptName)
|
424
|
+
return false;
|
425
|
+
(0, import_debug.default)("Running user script...");
|
426
|
+
const runScriptTime = Date.now();
|
427
|
+
const opts = {
|
428
|
+
cwd: destPath,
|
429
|
+
...spawnOpts,
|
430
|
+
env: getEnvForPackageManager({
|
431
|
+
cliType,
|
432
|
+
lockfileVersion,
|
433
|
+
nodeVersion: void 0,
|
434
|
+
env: (0, import_clone_env.cloneEnv)(process.env, spawnOpts?.env)
|
435
|
+
})
|
436
|
+
};
|
437
|
+
if (cliType === "npm") {
|
438
|
+
opts.prettyCommand = `npm run ${scriptName}`;
|
439
|
+
} else if (cliType === "pnpm") {
|
440
|
+
opts.prettyCommand = `pnpm run ${scriptName}`;
|
441
|
+
} else {
|
442
|
+
opts.prettyCommand = `yarn run ${scriptName}`;
|
443
|
+
}
|
444
|
+
console.log(`Running "${opts.prettyCommand}"`);
|
445
|
+
await spawnAsync(cliType, ["run", scriptName], opts);
|
446
|
+
(0, import_debug.default)(`Script complete [${Date.now() - runScriptTime}ms]`);
|
447
|
+
return true;
|
431
448
|
}
|
432
|
-
exports.runPackageJsonScript = runPackageJsonScript;
|
433
449
|
async function runBundleInstall(destPath, args = [], spawnOpts, meta) {
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
450
|
+
if (meta && meta.isDev) {
|
451
|
+
(0, import_debug.default)("Skipping dependency installation because dev mode is enabled");
|
452
|
+
return;
|
453
|
+
}
|
454
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
455
|
+
const opts = { ...spawnOpts, cwd: destPath, prettyCommand: "bundle install" };
|
456
|
+
await spawnAsync("bundle", args.concat(["install"]), opts);
|
441
457
|
}
|
442
|
-
exports.runBundleInstall = runBundleInstall;
|
443
458
|
async function runPipInstall(destPath, args = [], spawnOpts, meta) {
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
459
|
+
if (meta && meta.isDev) {
|
460
|
+
(0, import_debug.default)("Skipping dependency installation because dev mode is enabled");
|
461
|
+
return;
|
462
|
+
}
|
463
|
+
(0, import_assert.default)(import_path.default.isAbsolute(destPath));
|
464
|
+
const opts = { ...spawnOpts, cwd: destPath, prettyCommand: "pip3 install" };
|
465
|
+
await spawnAsync(
|
466
|
+
"pip3",
|
467
|
+
["install", "--disable-pip-version-check", ...args],
|
468
|
+
opts
|
469
|
+
);
|
451
470
|
}
|
452
|
-
exports.runPipInstall = runPipInstall;
|
453
471
|
function getScriptName(pkg, possibleNames) {
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
}
|
472
|
+
if (pkg?.scripts) {
|
473
|
+
for (const name of possibleNames) {
|
474
|
+
if (name in pkg.scripts) {
|
475
|
+
return name;
|
476
|
+
}
|
460
477
|
}
|
461
|
-
|
478
|
+
}
|
479
|
+
return null;
|
462
480
|
}
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
481
|
+
const installDependencies = (0, import_util.deprecate)(
|
482
|
+
runNpmInstall,
|
483
|
+
"installDependencies() is deprecated. Please use runNpmInstall() instead."
|
484
|
+
);
|
485
|
+
// Annotate the CommonJS export names for ESM import in node:
|
486
|
+
0 && (module.exports = {
|
487
|
+
execCommand,
|
488
|
+
getEnvForPackageManager,
|
489
|
+
getNodeBinPath,
|
490
|
+
getNodeBinPaths,
|
491
|
+
getNodeVersion,
|
492
|
+
getScriptName,
|
493
|
+
getSpawnOptions,
|
494
|
+
installDependencies,
|
495
|
+
runBundleInstall,
|
496
|
+
runCustomInstallCommand,
|
497
|
+
runNpmInstall,
|
498
|
+
runPackageJsonScript,
|
499
|
+
runPipInstall,
|
500
|
+
runShellScript,
|
501
|
+
scanParentDirs,
|
502
|
+
spawnAsync,
|
503
|
+
spawnCommand,
|
504
|
+
traverseUpDirectories,
|
505
|
+
walkParentDirs
|
506
|
+
});
|