@vercel/build-utils 5.4.2 → 5.4.4
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/dist/clone-env.d.ts +10 -0
- package/dist/clone-env.js +32 -0
- package/dist/fs/run-user-scripts.js +31 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.js +74 -8
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { Env } from './types';
|
2
|
+
/**
|
3
|
+
* Clones zero or more objects into a single new object while ensuring that the
|
4
|
+
* `PATH` environment variable is defined when the `PATH` or `Path` environment
|
5
|
+
* variables are defined.
|
6
|
+
*
|
7
|
+
* @param {Object} [...envs] Objects and/or `process.env` to clone and merge
|
8
|
+
* @returns {Object} The new object
|
9
|
+
*/
|
10
|
+
export declare function cloneEnv(...envs: (Env | undefined)[]): Env;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.cloneEnv = void 0;
|
4
|
+
const { hasOwnProperty } = Object.prototype;
|
5
|
+
/**
|
6
|
+
* Clones zero or more objects into a single new object while ensuring that the
|
7
|
+
* `PATH` environment variable is defined when the `PATH` or `Path` environment
|
8
|
+
* variables are defined.
|
9
|
+
*
|
10
|
+
* @param {Object} [...envs] Objects and/or `process.env` to clone and merge
|
11
|
+
* @returns {Object} The new object
|
12
|
+
*/
|
13
|
+
function cloneEnv(...envs) {
|
14
|
+
return envs.reduce((obj, env) => {
|
15
|
+
if (env === undefined || env === null) {
|
16
|
+
return obj;
|
17
|
+
}
|
18
|
+
// mixin the env first
|
19
|
+
obj = Object.assign(obj, env);
|
20
|
+
if (hasOwnProperty.call(env, 'Path')) {
|
21
|
+
// the system path is called `Path` on Windows and Node.js will
|
22
|
+
// automatically return the system path when accessing `PATH`,
|
23
|
+
// however we lose this proxied value when we destructure and
|
24
|
+
// thus we must explicitly copy it, but we must also remove the
|
25
|
+
// `Path` property since we can't have both a `PATH` and `Path`
|
26
|
+
obj.PATH = obj.Path;
|
27
|
+
delete obj.Path;
|
28
|
+
}
|
29
|
+
return obj;
|
30
|
+
}, {});
|
31
|
+
}
|
32
|
+
exports.cloneEnv = cloneEnv;
|
@@ -15,6 +15,7 @@ const debug_1 = __importDefault(require("../debug"));
|
|
15
15
|
const errors_1 = require("../errors");
|
16
16
|
const node_version_1 = require("./node-version");
|
17
17
|
const read_config_file_1 = require("./read-config-file");
|
18
|
+
const clone_env_1 = require("../clone-env");
|
18
19
|
// Only allow one `runNpmInstall()` invocation to run concurrently
|
19
20
|
const runNpmInstallSema = new async_sema_1.default(1);
|
20
21
|
function spawnAsync(command, args, opts = {}) {
|
@@ -123,7 +124,7 @@ async function runShellScript(fsPath, args = [], spawnOpts) {
|
|
123
124
|
exports.runShellScript = runShellScript;
|
124
125
|
function getSpawnOptions(meta, nodeVersion) {
|
125
126
|
const opts = {
|
126
|
-
env:
|
127
|
+
env: clone_env_1.cloneEnv(process.env),
|
127
128
|
};
|
128
129
|
if (!meta.isDev) {
|
129
130
|
let found = false;
|
@@ -294,7 +295,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
294
295
|
console.log('Installing dependencies...');
|
295
296
|
debug_1.default(`Installing to ${destPath}`);
|
296
297
|
const opts = { cwd: destPath, ...spawnOpts };
|
297
|
-
const env =
|
298
|
+
const env = clone_env_1.cloneEnv(opts.env || process.env);
|
298
299
|
delete env.NODE_ENV;
|
299
300
|
opts.env = getEnvForPackageManager({
|
300
301
|
cliType,
|
@@ -303,11 +304,25 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
303
304
|
env,
|
304
305
|
});
|
305
306
|
let commandArgs;
|
307
|
+
const isPotentiallyBrokenNpm = cliType === 'npm' &&
|
308
|
+
nodeVersion?.major === 16 &&
|
309
|
+
!args.includes('--legacy-peer-deps') &&
|
310
|
+
spawnOpts?.env?.ENABLE_EXPERIMENTAL_COREPACK !== '1';
|
306
311
|
if (cliType === 'npm') {
|
307
312
|
opts.prettyCommand = 'npm install';
|
308
313
|
commandArgs = args
|
309
314
|
.filter(a => a !== '--prefer-offline')
|
310
315
|
.concat(['install', '--no-audit', '--unsafe-perm']);
|
316
|
+
if (isPotentiallyBrokenNpm &&
|
317
|
+
spawnOpts?.env?.VERCEL_NPM_LEGACY_PEER_DEPS === '1') {
|
318
|
+
// Starting in npm@8.6.0, if you ran `npm install --legacy-peer-deps`,
|
319
|
+
// and then later ran `npm install`, it would fail. So the only way
|
320
|
+
// to safely upgrade npm from npm@8.5.0 is to set this flag. The docs
|
321
|
+
// say this flag is not recommended so its is behind a feature flag
|
322
|
+
// so we can remove it in node@18, which can introduce breaking changes.
|
323
|
+
// See https://docs.npmjs.com/cli/v8/using-npm/config#legacy-peer-deps
|
324
|
+
commandArgs.push('--legacy-peer-deps');
|
325
|
+
}
|
311
326
|
}
|
312
327
|
else if (cliType === 'pnpm') {
|
313
328
|
// PNPM's install command is similar to NPM's but without the audit nonsense
|
@@ -324,7 +339,19 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
324
339
|
if (process.env.NPM_ONLY_PRODUCTION) {
|
325
340
|
commandArgs.push('--production');
|
326
341
|
}
|
327
|
-
|
342
|
+
try {
|
343
|
+
await spawnAsync(cliType, commandArgs, opts);
|
344
|
+
}
|
345
|
+
catch (_) {
|
346
|
+
const potentialErrorPath = path_1.default.join(process.env.HOME || '/', '.npm', 'eresolve-report.txt');
|
347
|
+
if (isPotentiallyBrokenNpm &&
|
348
|
+
!commandArgs.includes('--legacy-peer-deps') &&
|
349
|
+
fs_extra_1.default.existsSync(potentialErrorPath)) {
|
350
|
+
console.warn('Warning: Retrying "Install Command" with `--legacy-peer-deps` which may accept a potentially broken dependency and slow install time.');
|
351
|
+
commandArgs.push('--legacy-peer-deps');
|
352
|
+
await spawnAsync(cliType, commandArgs, opts);
|
353
|
+
}
|
354
|
+
}
|
328
355
|
debug_1.default(`Install complete [${Date.now() - installTime}ms]`);
|
329
356
|
return true;
|
330
357
|
}
|
@@ -401,10 +428,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
401
428
|
cliType,
|
402
429
|
lockfileVersion,
|
403
430
|
nodeVersion: undefined,
|
404
|
-
env:
|
405
|
-
...process.env,
|
406
|
-
...spawnOpts?.env,
|
407
|
-
},
|
431
|
+
env: clone_env_1.cloneEnv(process.env, spawnOpts?.env),
|
408
432
|
}),
|
409
433
|
};
|
410
434
|
if (cliType === 'npm') {
|
package/dist/index.d.ts
CHANGED
@@ -15,7 +15,8 @@ import debug from './debug';
|
|
15
15
|
import getIgnoreFilter from './get-ignore-filter';
|
16
16
|
import { getPlatformEnv } from './get-platform-env';
|
17
17
|
import { getPrefixedEnvVars } from './get-prefixed-env-vars';
|
18
|
-
|
18
|
+
import { cloneEnv } from './clone-env';
|
19
|
+
export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, downloadFile, DownloadedFiles, getWriteableDirectory, glob, GlobOptions, rename, execAsync, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, streamToBuffer, debug, isSymbolicLink, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, cloneEnv, };
|
19
20
|
export { EdgeFunction } from './edge-function';
|
20
21
|
export { readConfigFile } from './fs/read-config-file';
|
21
22
|
export { normalizePath } from './fs/normalize-path';
|
package/dist/index.js
CHANGED
@@ -30108,6 +30108,46 @@ exports.fromPromise = function (fn) {
|
|
30108
30108
|
}
|
30109
30109
|
|
30110
30110
|
|
30111
|
+
/***/ }),
|
30112
|
+
|
30113
|
+
/***/ 6548:
|
30114
|
+
/***/ ((__unused_webpack_module, exports) => {
|
30115
|
+
|
30116
|
+
"use strict";
|
30117
|
+
|
30118
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
30119
|
+
exports.cloneEnv = void 0;
|
30120
|
+
const { hasOwnProperty } = Object.prototype;
|
30121
|
+
/**
|
30122
|
+
* Clones zero or more objects into a single new object while ensuring that the
|
30123
|
+
* `PATH` environment variable is defined when the `PATH` or `Path` environment
|
30124
|
+
* variables are defined.
|
30125
|
+
*
|
30126
|
+
* @param {Object} [...envs] Objects and/or `process.env` to clone and merge
|
30127
|
+
* @returns {Object} The new object
|
30128
|
+
*/
|
30129
|
+
function cloneEnv(...envs) {
|
30130
|
+
return envs.reduce((obj, env) => {
|
30131
|
+
if (env === undefined || env === null) {
|
30132
|
+
return obj;
|
30133
|
+
}
|
30134
|
+
// mixin the env first
|
30135
|
+
obj = Object.assign(obj, env);
|
30136
|
+
if (hasOwnProperty.call(env, 'Path')) {
|
30137
|
+
// the system path is called `Path` on Windows and Node.js will
|
30138
|
+
// automatically return the system path when accessing `PATH`,
|
30139
|
+
// however we lose this proxied value when we destructure and
|
30140
|
+
// thus we must explicitly copy it, but we must also remove the
|
30141
|
+
// `Path` property since we can't have both a `PATH` and `Path`
|
30142
|
+
obj.PATH = obj.Path;
|
30143
|
+
delete obj.Path;
|
30144
|
+
}
|
30145
|
+
return obj;
|
30146
|
+
}, {});
|
30147
|
+
}
|
30148
|
+
exports.cloneEnv = cloneEnv;
|
30149
|
+
|
30150
|
+
|
30111
30151
|
/***/ }),
|
30112
30152
|
|
30113
30153
|
/***/ 1868:
|
@@ -30847,6 +30887,7 @@ const debug_1 = __importDefault(__webpack_require__(1868));
|
|
30847
30887
|
const errors_1 = __webpack_require__(3983);
|
30848
30888
|
const node_version_1 = __webpack_require__(7903);
|
30849
30889
|
const read_config_file_1 = __webpack_require__(7792);
|
30890
|
+
const clone_env_1 = __webpack_require__(6548);
|
30850
30891
|
// Only allow one `runNpmInstall()` invocation to run concurrently
|
30851
30892
|
const runNpmInstallSema = new async_sema_1.default(1);
|
30852
30893
|
function spawnAsync(command, args, opts = {}) {
|
@@ -30955,7 +30996,7 @@ async function runShellScript(fsPath, args = [], spawnOpts) {
|
|
30955
30996
|
exports.runShellScript = runShellScript;
|
30956
30997
|
function getSpawnOptions(meta, nodeVersion) {
|
30957
30998
|
const opts = {
|
30958
|
-
env:
|
30999
|
+
env: clone_env_1.cloneEnv(process.env),
|
30959
31000
|
};
|
30960
31001
|
if (!meta.isDev) {
|
30961
31002
|
let found = false;
|
@@ -31126,7 +31167,7 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
31126
31167
|
console.log('Installing dependencies...');
|
31127
31168
|
debug_1.default(`Installing to ${destPath}`);
|
31128
31169
|
const opts = { cwd: destPath, ...spawnOpts };
|
31129
|
-
const env =
|
31170
|
+
const env = clone_env_1.cloneEnv(opts.env || process.env);
|
31130
31171
|
delete env.NODE_ENV;
|
31131
31172
|
opts.env = getEnvForPackageManager({
|
31132
31173
|
cliType,
|
@@ -31135,11 +31176,25 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
31135
31176
|
env,
|
31136
31177
|
});
|
31137
31178
|
let commandArgs;
|
31179
|
+
const isPotentiallyBrokenNpm = cliType === 'npm' &&
|
31180
|
+
nodeVersion?.major === 16 &&
|
31181
|
+
!args.includes('--legacy-peer-deps') &&
|
31182
|
+
spawnOpts?.env?.ENABLE_EXPERIMENTAL_COREPACK !== '1';
|
31138
31183
|
if (cliType === 'npm') {
|
31139
31184
|
opts.prettyCommand = 'npm install';
|
31140
31185
|
commandArgs = args
|
31141
31186
|
.filter(a => a !== '--prefer-offline')
|
31142
31187
|
.concat(['install', '--no-audit', '--unsafe-perm']);
|
31188
|
+
if (isPotentiallyBrokenNpm &&
|
31189
|
+
spawnOpts?.env?.VERCEL_NPM_LEGACY_PEER_DEPS === '1') {
|
31190
|
+
// Starting in npm@8.6.0, if you ran `npm install --legacy-peer-deps`,
|
31191
|
+
// and then later ran `npm install`, it would fail. So the only way
|
31192
|
+
// to safely upgrade npm from npm@8.5.0 is to set this flag. The docs
|
31193
|
+
// say this flag is not recommended so its is behind a feature flag
|
31194
|
+
// so we can remove it in node@18, which can introduce breaking changes.
|
31195
|
+
// See https://docs.npmjs.com/cli/v8/using-npm/config#legacy-peer-deps
|
31196
|
+
commandArgs.push('--legacy-peer-deps');
|
31197
|
+
}
|
31143
31198
|
}
|
31144
31199
|
else if (cliType === 'pnpm') {
|
31145
31200
|
// PNPM's install command is similar to NPM's but without the audit nonsense
|
@@ -31156,7 +31211,19 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
|
|
31156
31211
|
if (process.env.NPM_ONLY_PRODUCTION) {
|
31157
31212
|
commandArgs.push('--production');
|
31158
31213
|
}
|
31159
|
-
|
31214
|
+
try {
|
31215
|
+
await spawnAsync(cliType, commandArgs, opts);
|
31216
|
+
}
|
31217
|
+
catch (_) {
|
31218
|
+
const potentialErrorPath = path_1.default.join(process.env.HOME || '/', '.npm', 'eresolve-report.txt');
|
31219
|
+
if (isPotentiallyBrokenNpm &&
|
31220
|
+
!commandArgs.includes('--legacy-peer-deps') &&
|
31221
|
+
fs_extra_1.default.existsSync(potentialErrorPath)) {
|
31222
|
+
console.warn('Warning: Retrying "Install Command" with `--legacy-peer-deps` which may accept a potentially broken dependency and slow install time.');
|
31223
|
+
commandArgs.push('--legacy-peer-deps');
|
31224
|
+
await spawnAsync(cliType, commandArgs, opts);
|
31225
|
+
}
|
31226
|
+
}
|
31160
31227
|
debug_1.default(`Install complete [${Date.now() - installTime}ms]`);
|
31161
31228
|
return true;
|
31162
31229
|
}
|
@@ -31233,10 +31300,7 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
|
|
31233
31300
|
cliType,
|
31234
31301
|
lockfileVersion,
|
31235
31302
|
nodeVersion: undefined,
|
31236
|
-
env:
|
31237
|
-
...process.env,
|
31238
|
-
...spawnOpts?.env,
|
31239
|
-
},
|
31303
|
+
env: clone_env_1.cloneEnv(process.env, spawnOpts?.env),
|
31240
31304
|
}),
|
31241
31305
|
};
|
31242
31306
|
if (cliType === 'npm') {
|
@@ -31499,7 +31563,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31499
31563
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
31500
31564
|
};
|
31501
31565
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
31502
|
-
exports.normalizePath = exports.readConfigFile = exports.EdgeFunction = exports.getIgnoreFilter = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.streamToBuffer = exports.getPrefixedEnvVars = exports.getPlatformEnv = exports.getSpawnOptions = exports.getDiscontinuedNodeVersions = exports.getLatestNodeVersion = exports.getNodeVersion = exports.getEnvForPackageManager = exports.runCustomInstallCommand = exports.runShellScript = exports.runPipInstall = exports.runBundleInstall = exports.runNpmInstall = exports.getNodeBinPath = exports.walkParentDirs = exports.spawnCommand = exports.execCommand = exports.runPackageJsonScript = exports.installDependencies = exports.getScriptName = exports.spawnAsync = exports.execAsync = exports.rename = exports.glob = exports.getWriteableDirectory = exports.downloadFile = exports.download = exports.Prerender = exports.createLambda = exports.NodejsLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
|
31566
|
+
exports.normalizePath = exports.readConfigFile = exports.EdgeFunction = exports.cloneEnv = exports.getIgnoreFilter = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.streamToBuffer = exports.getPrefixedEnvVars = exports.getPlatformEnv = exports.getSpawnOptions = exports.getDiscontinuedNodeVersions = exports.getLatestNodeVersion = exports.getNodeVersion = exports.getEnvForPackageManager = exports.runCustomInstallCommand = exports.runShellScript = exports.runPipInstall = exports.runBundleInstall = exports.runNpmInstall = exports.getNodeBinPath = exports.walkParentDirs = exports.spawnCommand = exports.execCommand = exports.runPackageJsonScript = exports.installDependencies = exports.getScriptName = exports.spawnAsync = exports.execAsync = exports.rename = exports.glob = exports.getWriteableDirectory = exports.downloadFile = exports.download = exports.Prerender = exports.createLambda = exports.NodejsLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
|
31503
31567
|
const file_blob_1 = __importDefault(__webpack_require__(2397));
|
31504
31568
|
exports.FileBlob = file_blob_1.default;
|
31505
31569
|
const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
|
@@ -31556,6 +31620,8 @@ const get_platform_env_1 = __webpack_require__(4678);
|
|
31556
31620
|
Object.defineProperty(exports, "getPlatformEnv", ({ enumerable: true, get: function () { return get_platform_env_1.getPlatformEnv; } }));
|
31557
31621
|
const get_prefixed_env_vars_1 = __webpack_require__(6838);
|
31558
31622
|
Object.defineProperty(exports, "getPrefixedEnvVars", ({ enumerable: true, get: function () { return get_prefixed_env_vars_1.getPrefixedEnvVars; } }));
|
31623
|
+
const clone_env_1 = __webpack_require__(6548);
|
31624
|
+
Object.defineProperty(exports, "cloneEnv", ({ enumerable: true, get: function () { return clone_env_1.cloneEnv; } }));
|
31559
31625
|
var edge_function_1 = __webpack_require__(8038);
|
31560
31626
|
Object.defineProperty(exports, "EdgeFunction", ({ enumerable: true, get: function () { return edge_function_1.EdgeFunction; } }));
|
31561
31627
|
var read_config_file_1 = __webpack_require__(7792);
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/build-utils",
|
3
|
-
"version": "5.4.
|
3
|
+
"version": "5.4.4",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.js",
|
@@ -47,5 +47,5 @@
|
|
47
47
|
"typescript": "4.3.4",
|
48
48
|
"yazl": "2.5.1"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "27f4034bdce427953fea094b1c4dfbfb00342b54"
|
51
51
|
}
|