@vercel/build-utils 2.13.1-canary.0 → 2.14.1-canary.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.
@@ -3,8 +3,8 @@ ncc: Version 0.24.0
3
3
  ncc: Compiling file index.js
4
4
  ncc: Using typescript@4.3.4 (local user-provided)
5
5
  0kB dist/main/should-serve.d.ts
6
+ 0kB dist/main/get-platform-env.d.ts
6
7
  0kB dist/main/get-ignore-filter.d.ts
7
- 0kB dist/main/detect-framework.d.ts
8
8
  0kB dist/main/fs/stream-to-buffer.d.ts
9
9
  0kB dist/main/fs/rename.d.ts
10
10
  0kB dist/main/fs/read-config-file.d.ts
@@ -13,9 +13,11 @@ ncc: Using typescript@4.3.4 (local user-provided)
13
13
  0kB dist/main/fs/glob.d.ts
14
14
  0kB dist/main/fs/get-writable-directory.d.ts
15
15
  0kB dist/main/fs/download.d.ts
16
+ 0kB dist/main/detect-framework.d.ts
16
17
  0kB dist/main/debug.d.ts
17
18
  1kB dist/main/schemas.d.ts
18
19
  1kB dist/main/prerender.d.ts
20
+ 1kB dist/main/nodejs-lambda.d.ts
19
21
  1kB dist/main/lambda.d.ts
20
22
  1kB dist/main/file-ref.d.ts
21
23
  1kB dist/main/file-fs-ref.d.ts
@@ -23,10 +25,9 @@ ncc: Using typescript@4.3.4 (local user-provided)
23
25
  1kB dist/main/errors.d.ts
24
26
  1kB dist/main/detect-file-system-api.d.ts
25
27
  1kB dist/main/detect-builders.d.ts
28
+ 2kB dist/main/index.d.ts
26
29
  2kB dist/main/detectors/filesystem.d.ts
27
- 2kB dist/main/convert-runtime-to-plugin.d.ts
28
- 3kB dist/main/index.d.ts
29
- 3kB dist/main/fs/run-user-scripts.d.ts
30
- 9kB dist/main/types.d.ts
31
- 1244kB dist/main/index.js
32
- 1272kB [8092ms] - ncc 0.24.0
30
+ 4kB dist/main/fs/run-user-scripts.d.ts
31
+ 10kB dist/main/types.d.ts
32
+ 1231kB dist/main/index.js
33
+ 1259kB [7510ms] - ncc 0.24.0
package/dist/debug.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require("./");
3
+ const get_platform_env_1 = require("./get-platform-env");
4
4
  function debug(message, ...additional) {
5
- if (_1.getPlatformEnv('BUILDER_DEBUG')) {
5
+ if (get_platform_env_1.getPlatformEnv('BUILDER_DEBUG')) {
6
6
  console.log(message, ...additional);
7
7
  }
8
8
  }
@@ -57,6 +57,22 @@ export declare function getNodeVersion(destPath: string, _nodeVersion?: string,
57
57
  export declare function scanParentDirs(destPath: string, readPackageJson?: boolean): Promise<ScanParentDirsResult>;
58
58
  export declare function walkParentDirs({ base, start, filename, }: WalkParentDirsProps): Promise<string | null>;
59
59
  export declare function runNpmInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta, nodeVersion?: NodeVersion): Promise<void>;
60
+ export declare function getEnvForPackageManager({ cliType, lockfileVersion, nodeVersion, env, }: {
61
+ cliType: CliType;
62
+ lockfileVersion: number | undefined;
63
+ nodeVersion: NodeVersion | undefined;
64
+ env: {
65
+ [x: string]: string | undefined;
66
+ };
67
+ }): {
68
+ [x: string]: string | undefined;
69
+ };
70
+ export declare function runCustomInstallCommand({ destPath, installCommand, nodeVersion, spawnOpts, }: {
71
+ destPath: string;
72
+ installCommand: string;
73
+ nodeVersion: NodeVersion;
74
+ spawnOpts?: SpawnOptions;
75
+ }): Promise<void>;
60
76
  export declare function runPackageJsonScript(destPath: string, scriptNames: string | Iterable<string>, spawnOpts?: SpawnOptions): Promise<boolean>;
61
77
  export declare function runBundleInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta): Promise<void>;
62
78
  export declare function runPipInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta): Promise<void>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.installDependencies = exports.getScriptName = exports.runPipInstall = exports.runBundleInstall = exports.runPackageJsonScript = exports.runNpmInstall = exports.walkParentDirs = exports.scanParentDirs = exports.getNodeVersion = exports.getSpawnOptions = exports.runShellScript = exports.getNodeBinPath = exports.execCommand = exports.spawnCommand = exports.execAsync = exports.spawnAsync = void 0;
6
+ exports.installDependencies = exports.getScriptName = exports.runPipInstall = exports.runBundleInstall = exports.runPackageJsonScript = exports.runCustomInstallCommand = exports.getEnvForPackageManager = exports.runNpmInstall = exports.walkParentDirs = exports.scanParentDirs = exports.getNodeVersion = exports.getSpawnOptions = exports.runShellScript = exports.getNodeBinPath = exports.execCommand = exports.spawnCommand = exports.execAsync = exports.spawnAsync = void 0;
7
7
  const assert_1 = __importDefault(require("assert"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -221,36 +221,66 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
221
221
  const opts = { cwd: destPath, ...spawnOpts };
222
222
  const env = opts.env ? { ...opts.env } : { ...process.env };
223
223
  delete env.NODE_ENV;
224
- opts.env = env;
224
+ opts.env = getEnvForPackageManager({
225
+ cliType,
226
+ lockfileVersion,
227
+ nodeVersion,
228
+ env,
229
+ });
225
230
  let commandArgs;
226
231
  if (cliType === 'npm') {
227
232
  opts.prettyCommand = 'npm install';
228
233
  commandArgs = args
229
234
  .filter(a => a !== '--prefer-offline')
230
235
  .concat(['install', '--no-audit', '--unsafe-perm']);
231
- // If the lockfile version is 2 or greater and the node version is less than 16 than we will force npm7 to be used
236
+ }
237
+ else {
238
+ opts.prettyCommand = 'yarn install';
239
+ commandArgs = ['install', ...args];
240
+ }
241
+ if (process.env.NPM_ONLY_PRODUCTION) {
242
+ commandArgs.push('--production');
243
+ }
244
+ return spawnAsync(cliType, commandArgs, opts);
245
+ }
246
+ exports.runNpmInstall = runNpmInstall;
247
+ function getEnvForPackageManager({ cliType, lockfileVersion, nodeVersion, env, }) {
248
+ const newEnv = { ...env };
249
+ if (cliType === 'npm') {
232
250
  if (typeof lockfileVersion === 'number' &&
233
251
  lockfileVersion >= 2 &&
234
252
  ((nodeVersion === null || nodeVersion === void 0 ? void 0 : nodeVersion.major) || 0) < 16) {
235
253
  // Ensure that npm 7 is at the beginning of the `$PATH`
236
- env.PATH = `/node16/bin-npm7:${env.PATH}`;
254
+ newEnv.PATH = `/node16/bin-npm7:${env.PATH}`;
237
255
  console.log('Detected `package-lock.json` generated by npm 7...');
238
256
  }
239
257
  }
240
258
  else {
241
- opts.prettyCommand = 'yarn install';
242
- commandArgs = ['install', ...args];
243
259
  // Yarn v2 PnP mode may be activated, so force "node-modules" linker style
244
260
  if (!env.YARN_NODE_LINKER) {
245
- env.YARN_NODE_LINKER = 'node-modules';
261
+ newEnv.YARN_NODE_LINKER = 'node-modules';
246
262
  }
247
263
  }
248
- if (process.env.NPM_ONLY_PRODUCTION) {
249
- commandArgs.push('--production');
250
- }
251
- return spawnAsync(cliType, commandArgs, opts);
264
+ return newEnv;
252
265
  }
253
- exports.runNpmInstall = runNpmInstall;
266
+ exports.getEnvForPackageManager = getEnvForPackageManager;
267
+ async function runCustomInstallCommand({ destPath, installCommand, nodeVersion, spawnOpts, }) {
268
+ console.log(`Running "install" command: \`${installCommand}\`...`);
269
+ const { cliType, lockfileVersion } = await scanParentDirs(destPath);
270
+ const env = getEnvForPackageManager({
271
+ cliType,
272
+ lockfileVersion,
273
+ nodeVersion,
274
+ env: (spawnOpts === null || spawnOpts === void 0 ? void 0 : spawnOpts.env) || {},
275
+ });
276
+ debug_1.default(`Running with $PATH:`, (env === null || env === void 0 ? void 0 : env.PATH) || '');
277
+ await execCommand(installCommand, {
278
+ ...spawnOpts,
279
+ env,
280
+ cwd: destPath,
281
+ });
282
+ }
283
+ exports.runCustomInstallCommand = runCustomInstallCommand;
254
284
  async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
255
285
  assert_1.default(path_1.default.isAbsolute(destPath));
256
286
  const { packageJson, cliType, lockfileVersion } = await scanParentDirs(destPath, true);
@@ -259,21 +289,24 @@ async function runPackageJsonScript(destPath, scriptNames, spawnOpts) {
259
289
  return false;
260
290
  debug_1.default('Running user script...');
261
291
  const runScriptTime = Date.now();
262
- const opts = { cwd: destPath, ...spawnOpts };
263
- const env = (opts.env = { ...process.env, ...opts.env });
292
+ const opts = {
293
+ cwd: destPath,
294
+ ...spawnOpts,
295
+ env: getEnvForPackageManager({
296
+ cliType,
297
+ lockfileVersion,
298
+ nodeVersion: undefined,
299
+ env: {
300
+ ...process.env,
301
+ ...spawnOpts === null || spawnOpts === void 0 ? void 0 : spawnOpts.env,
302
+ },
303
+ }),
304
+ };
264
305
  if (cliType === 'npm') {
265
306
  opts.prettyCommand = `npm run ${scriptName}`;
266
- if (typeof lockfileVersion === 'number' && lockfileVersion >= 2) {
267
- // Ensure that npm 7 is at the beginning of the `$PATH`
268
- env.PATH = `/node16/bin-npm7:${env.PATH}`;
269
- }
270
307
  }
271
308
  else {
272
309
  opts.prettyCommand = `yarn run ${scriptName}`;
273
- // Yarn v2 PnP mode may be activated, so force "node-modules" linker style
274
- if (!env.YARN_NODE_LINKER) {
275
- env.YARN_NODE_LINKER = 'node-modules';
276
- }
277
310
  }
278
311
  console.log(`Running "${opts.prettyCommand}"`);
279
312
  await spawnAsync(cliType, ['run', scriptName], opts);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Helper function to support both `VERCEL_` and legacy `NOW_` env vars.
3
+ * Throws an error if *both* env vars are defined.
4
+ */
5
+ export declare const getPlatformEnv: (name: string) => string | undefined;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPlatformEnv = void 0;
4
+ const errors_1 = require("./errors");
5
+ /**
6
+ * Helper function to support both `VERCEL_` and legacy `NOW_` env vars.
7
+ * Throws an error if *both* env vars are defined.
8
+ */
9
+ const getPlatformEnv = (name) => {
10
+ const vName = `VERCEL_${name}`;
11
+ const nName = `NOW_${name}`;
12
+ const v = process.env[vName];
13
+ const n = process.env[nName];
14
+ if (typeof v === 'string') {
15
+ if (typeof n === 'string') {
16
+ throw new errors_1.NowBuildError({
17
+ code: 'CONFLICTING_ENV_VAR_NAMES',
18
+ message: `Both "${vName}" and "${nName}" env vars are defined. Please only define the "${vName}" env var.`,
19
+ link: 'https://vercel.link/combining-old-and-new-config',
20
+ });
21
+ }
22
+ return v;
23
+ }
24
+ return n;
25
+ };
26
+ exports.getPlatformEnv = getPlatformEnv;
package/dist/index.d.ts CHANGED
@@ -2,25 +2,26 @@ import FileBlob from './file-blob';
2
2
  import FileFsRef from './file-fs-ref';
3
3
  import FileRef from './file-ref';
4
4
  import { Lambda, createLambda, getLambdaOptionsFromFunction } from './lambda';
5
+ import { NodejsLambda } from './nodejs-lambda';
5
6
  import { Prerender } from './prerender';
6
7
  import download, { DownloadedFiles, isSymbolicLink } from './fs/download';
7
8
  import getWriteableDirectory from './fs/get-writable-directory';
8
9
  import glob, { GlobOptions } from './fs/glob';
9
10
  import rename from './fs/rename';
10
- import { execAsync, spawnAsync, execCommand, spawnCommand, walkParentDirs, getScriptName, installDependencies, runPackageJsonScript, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, getNodeVersion, getSpawnOptions, getNodeBinPath, scanParentDirs } from './fs/run-user-scripts';
11
+ import { execAsync, spawnAsync, execCommand, spawnCommand, walkParentDirs, getScriptName, installDependencies, runPackageJsonScript, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getSpawnOptions, getNodeBinPath, scanParentDirs } from './fs/run-user-scripts';
11
12
  import { getLatestNodeVersion, getDiscontinuedNodeVersions } from './fs/node-version';
12
13
  import streamToBuffer from './fs/stream-to-buffer';
13
14
  import shouldServe from './should-serve';
14
15
  import debug from './debug';
15
16
  import getIgnoreFilter from './get-ignore-filter';
16
- export { FileBlob, FileFsRef, FileRef, Lambda, createLambda, Prerender, download, DownloadedFiles, getWriteableDirectory, glob, GlobOptions, rename, execAsync, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, getNodeVersion, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, streamToBuffer, shouldServe, debug, isSymbolicLink, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, };
17
+ import { getPlatformEnv } from './get-platform-env';
18
+ export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, 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, streamToBuffer, shouldServe, debug, isSymbolicLink, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, };
17
19
  export { detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExtensions, } from './detect-builders';
18
20
  export { detectFileSystemAPI } from './detect-file-system-api';
19
21
  export { detectFramework } from './detect-framework';
20
22
  export { DetectorFilesystem } from './detectors/filesystem';
21
23
  export { readConfigFile } from './fs/read-config-file';
22
24
  export { normalizePath } from './fs/normalize-path';
23
- export { _experimental_convertRuntimeToPlugin, _experimental_updateFunctionsManifest, _experimental_updateRoutesManifest, } from './convert-runtime-to-plugin';
24
25
  export * from './schemas';
25
26
  export * from './types';
26
27
  export * from './errors';
@@ -29,8 +30,3 @@ export * from './errors';
29
30
  */
30
31
  export declare const isOfficialRuntime: (desired: string, name?: string | undefined) => boolean;
31
32
  export declare const isStaticRuntime: (name?: string | undefined) => boolean;
32
- /**
33
- * Helper function to support both `VERCEL_` and legacy `NOW_` env vars.
34
- * Throws an error if *both* env vars are defined.
35
- */
36
- export declare const getPlatformEnv: (name: string) => string | undefined;