@vercel/build-utils 4.2.1 → 5.0.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.
@@ -61,7 +61,7 @@ export declare function spawnCommand(command: string, options?: SpawnOptions): i
61
61
  export declare function execCommand(command: string, options?: SpawnOptions): Promise<boolean>;
62
62
  export declare function getNodeBinPath({ cwd, }: {
63
63
  cwd: string;
64
- }): Promise<string | undefined>;
64
+ }): Promise<string>;
65
65
  export declare function runShellScript(fsPath: string, args?: string[], spawnOpts?: SpawnOptions): Promise<boolean>;
66
66
  export declare function getSpawnOptions(meta: Meta, nodeVersion: NodeVersion): SpawnOptions;
67
67
  export declare function getNodeVersion(destPath: string, _nodeVersion?: string, config?: Config, meta?: Meta): Promise<NodeVersion>;
@@ -138,8 +138,20 @@ function getSpawnOptions(meta, nodeVersion) {
138
138
  env: { ...process.env },
139
139
  };
140
140
  if (!meta.isDev) {
141
- // Ensure that the selected Node version is at the beginning of the `$PATH`
142
- opts.env.PATH = `/node${nodeVersion.major}/bin${path_1.default.delimiter}${opts.env.PATH || process.env.PATH}`;
141
+ let found = false;
142
+ const oldPath = opts.env.PATH || process.env.PATH || '';
143
+ const pathSegments = oldPath.split(path_1.default.delimiter).map(segment => {
144
+ if (/^\/node[0-9]+\/bin/.test(segment)) {
145
+ found = true;
146
+ return `/node${nodeVersion.major}/bin`;
147
+ }
148
+ return segment;
149
+ });
150
+ if (!found) {
151
+ // If we didn't find & replace, prepend at beginning of PATH
152
+ pathSegments.unshift(`/node${nodeVersion.major}/bin`);
153
+ }
154
+ opts.env.PATH = pathSegments.filter(Boolean).join(path_1.default.delimiter);
143
155
  }
144
156
  return opts;
145
157
  }
@@ -323,19 +335,28 @@ async function runNpmInstall(destPath, args = [], spawnOpts, meta, nodeVersion)
323
335
  exports.runNpmInstall = runNpmInstall;
324
336
  function getEnvForPackageManager({ cliType, lockfileVersion, nodeVersion, env, }) {
325
337
  const newEnv = { ...env };
338
+ const oldPath = env.PATH + '';
339
+ const npm7 = '/node16/bin-npm7';
340
+ const pnpm7 = '/pnpm7/node_modules/.bin';
341
+ const corepackEnabled = env.ENABLE_EXPERIMENTAL_COREPACK === '1';
326
342
  if (cliType === 'npm') {
327
343
  if (typeof lockfileVersion === 'number' &&
328
344
  lockfileVersion >= 2 &&
329
- (nodeVersion?.major || 0) < 16) {
345
+ (nodeVersion?.major || 0) < 16 &&
346
+ !oldPath.includes(npm7) &&
347
+ !corepackEnabled) {
330
348
  // Ensure that npm 7 is at the beginning of the `$PATH`
331
- newEnv.PATH = `/node16/bin-npm7${path_1.default.delimiter}${env.PATH}`;
332
- console.log('Detected `package-lock.json` generated by npm 7...');
349
+ newEnv.PATH = `${npm7}${path_1.default.delimiter}${oldPath}`;
350
+ console.log('Detected `package-lock.json` generated by npm 7+...');
333
351
  }
334
352
  }
335
353
  else if (cliType === 'pnpm') {
336
- if (typeof lockfileVersion === 'number' && lockfileVersion === 5.4) {
354
+ if (typeof lockfileVersion === 'number' &&
355
+ lockfileVersion === 5.4 &&
356
+ !oldPath.includes(pnpm7) &&
357
+ !corepackEnabled) {
337
358
  // Ensure that pnpm 7 is at the beginning of the `$PATH`
338
- newEnv.PATH = `/pnpm7/node_modules/.bin${path_1.default.delimiter}${env.PATH}`;
359
+ newEnv.PATH = `${pnpm7}${path_1.default.delimiter}${oldPath}`;
339
360
  console.log('Detected `pnpm-lock.yaml` generated by pnpm 7...');
340
361
  }
341
362
  }
package/dist/index.d.ts CHANGED
@@ -16,23 +16,9 @@ import getIgnoreFilter from './get-ignore-filter';
16
16
  import { getPlatformEnv } from './get-platform-env';
17
17
  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, debug, isSymbolicLink, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, };
18
18
  export { EdgeFunction } from './edge-function';
19
- export { detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExtensions, } from './detect-builders';
20
- export { detectFileSystemAPI } from './detect-file-system-api';
21
- export { detectFramework } from './detect-framework';
22
- export { getProjectPaths } from './get-project-paths';
23
- export { DetectorFilesystem } from './detectors/filesystem';
24
19
  export { readConfigFile } from './fs/read-config-file';
25
20
  export { normalizePath } from './fs/normalize-path';
26
21
  export * from './should-serve';
27
22
  export * from './schemas';
28
23
  export * from './types';
29
24
  export * from './errors';
30
- /**
31
- * Helper function to support both `@vercel` and legacy `@now` official Runtimes.
32
- */
33
- export declare const isOfficialRuntime: (desired: string, name?: string | undefined) => boolean;
34
- export declare const isStaticRuntime: (name?: string | undefined) => boolean;
35
- export { workspaceManagers } from './workspaces/workspace-managers';
36
- export { getWorkspaces, GetWorkspaceOptions, Workspace, WorkspaceType, } from './workspaces/get-workspaces';
37
- export { getWorkspacePackagePaths, GetWorkspacePackagePathsOptions, } from './workspaces/get-workspace-package-paths';
38
- export { monorepoManagers } from './monorepos/monorepo-managers';