@vercel/build-utils 5.0.7 → 5.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.
@@ -1,7 +1,8 @@
1
1
  import FileFsRef from '../file-fs-ref';
2
- import { Files, Meta } from '../types';
2
+ import { File, Files, Meta } from '../types';
3
3
  export interface DownloadedFiles {
4
4
  [filePath: string]: FileFsRef;
5
5
  }
6
6
  export declare function isSymbolicLink(mode: number): boolean;
7
+ export declare function downloadFile(file: File, fsPath: string): Promise<FileFsRef>;
7
8
  export default function download(files: Files, basePath: string, meta?: Meta): Promise<DownloadedFiles>;
@@ -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.isSymbolicLink = void 0;
6
+ exports.downloadFile = exports.isSymbolicLink = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const debug_1 = __importDefault(require("../debug"));
9
9
  const file_fs_ref_1 = __importDefault(require("../file-fs-ref"));
@@ -22,7 +22,7 @@ async function prepareSymlinkTarget(file, fsPath) {
22
22
  return target;
23
23
  }
24
24
  if (file.type === 'FileRef' || file.type === 'FileBlob') {
25
- const targetPathBufferPromise = await stream_to_buffer_1.default(await file.toStreamAsync());
25
+ const targetPathBufferPromise = stream_to_buffer_1.default(await file.toStreamAsync());
26
26
  const [targetPathBuffer] = await Promise.all([
27
27
  targetPathBufferPromise,
28
28
  mkdirPromise,
@@ -33,6 +33,9 @@ async function prepareSymlinkTarget(file, fsPath) {
33
33
  }
34
34
  async function downloadFile(file, fsPath) {
35
35
  const { mode } = file;
36
+ // If the source is a symlink, try to create it instead of copying the file.
37
+ // Note: creating symlinks on Windows requires admin priviliges or symlinks
38
+ // enabled in the group policy. We may want to improve the error message.
36
39
  if (isSymbolicLink(mode)) {
37
40
  const target = await prepareSymlinkTarget(file, fsPath);
38
41
  await fs_extra_1.symlink(target, fsPath);
@@ -41,6 +44,7 @@ async function downloadFile(file, fsPath) {
41
44
  const stream = file.toStream();
42
45
  return file_fs_ref_1.default.fromStream({ mode, stream, fsPath });
43
46
  }
47
+ exports.downloadFile = downloadFile;
44
48
  async function removeFile(basePath, fileMatched) {
45
49
  const file = path_1.default.join(basePath, fileMatched);
46
50
  await fs_extra_1.remove(file);
@@ -67,6 +71,20 @@ async function download(files, basePath, meta) {
67
71
  if (Array.isArray(filesChanged) && !filesChanged.includes(name)) {
68
72
  return;
69
73
  }
74
+ // Some builders resolve symlinks and return both
75
+ // a file, node_modules/<symlink>/package.json, and
76
+ // node_modules/<symlink>, a symlink.
77
+ // Removing the file matches how the yazl lambda zip
78
+ // behaves so we can use download() with `vercel build`.
79
+ const parts = name.split('/');
80
+ for (let i = 1; i < parts.length; i++) {
81
+ const dir = parts.slice(0, i).join('/');
82
+ const parent = files[dir];
83
+ if (parent && isSymbolicLink(parent.mode)) {
84
+ console.warn(`Warning: file "${name}" is within a symlinked directory "${dir}" and will be ignored`);
85
+ return;
86
+ }
87
+ }
70
88
  const file = files[name];
71
89
  const fsPath = path_1.default.join(basePath, name);
72
90
  files2[name] = await downloadFile(file, fsPath);
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import FileRef from './file-ref';
4
4
  import { Lambda, createLambda, getLambdaOptionsFromFunction } from './lambda';
5
5
  import { NodejsLambda } from './nodejs-lambda';
6
6
  import { Prerender } from './prerender';
7
- import download, { DownloadedFiles, isSymbolicLink } from './fs/download';
7
+ import download, { downloadFile, DownloadedFiles, isSymbolicLink } from './fs/download';
8
8
  import getWriteableDirectory from './fs/get-writable-directory';
9
9
  import glob, { GlobOptions } from './fs/glob';
10
10
  import rename from './fs/rename';
@@ -14,7 +14,7 @@ import streamToBuffer from './fs/stream-to-buffer';
14
14
  import debug from './debug';
15
15
  import getIgnoreFilter from './get-ignore-filter';
16
16
  import { getPlatformEnv } from './get-platform-env';
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, };
17
+ 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, streamToBuffer, debug, isSymbolicLink, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, };
18
18
  export { EdgeFunction } from './edge-function';
19
19
  export { readConfigFile } from './fs/read-config-file';
20
20
  export { normalizePath } from './fs/normalize-path';
package/dist/index.js CHANGED
@@ -30471,7 +30471,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30471
30471
  return (mod && mod.__esModule) ? mod : { "default": mod };
30472
30472
  };
30473
30473
  Object.defineProperty(exports, "__esModule", ({ value: true }));
30474
- exports.isSymbolicLink = void 0;
30474
+ exports.downloadFile = exports.isSymbolicLink = void 0;
30475
30475
  const path_1 = __importDefault(__webpack_require__(5622));
30476
30476
  const debug_1 = __importDefault(__webpack_require__(1868));
30477
30477
  const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
@@ -30490,7 +30490,7 @@ async function prepareSymlinkTarget(file, fsPath) {
30490
30490
  return target;
30491
30491
  }
30492
30492
  if (file.type === 'FileRef' || file.type === 'FileBlob') {
30493
- const targetPathBufferPromise = await stream_to_buffer_1.default(await file.toStreamAsync());
30493
+ const targetPathBufferPromise = stream_to_buffer_1.default(await file.toStreamAsync());
30494
30494
  const [targetPathBuffer] = await Promise.all([
30495
30495
  targetPathBufferPromise,
30496
30496
  mkdirPromise,
@@ -30501,6 +30501,9 @@ async function prepareSymlinkTarget(file, fsPath) {
30501
30501
  }
30502
30502
  async function downloadFile(file, fsPath) {
30503
30503
  const { mode } = file;
30504
+ // If the source is a symlink, try to create it instead of copying the file.
30505
+ // Note: creating symlinks on Windows requires admin priviliges or symlinks
30506
+ // enabled in the group policy. We may want to improve the error message.
30504
30507
  if (isSymbolicLink(mode)) {
30505
30508
  const target = await prepareSymlinkTarget(file, fsPath);
30506
30509
  await fs_extra_1.symlink(target, fsPath);
@@ -30509,6 +30512,7 @@ async function downloadFile(file, fsPath) {
30509
30512
  const stream = file.toStream();
30510
30513
  return file_fs_ref_1.default.fromStream({ mode, stream, fsPath });
30511
30514
  }
30515
+ exports.downloadFile = downloadFile;
30512
30516
  async function removeFile(basePath, fileMatched) {
30513
30517
  const file = path_1.default.join(basePath, fileMatched);
30514
30518
  await fs_extra_1.remove(file);
@@ -30535,6 +30539,20 @@ async function download(files, basePath, meta) {
30535
30539
  if (Array.isArray(filesChanged) && !filesChanged.includes(name)) {
30536
30540
  return;
30537
30541
  }
30542
+ // Some builders resolve symlinks and return both
30543
+ // a file, node_modules/<symlink>/package.json, and
30544
+ // node_modules/<symlink>, a symlink.
30545
+ // Removing the file matches how the yazl lambda zip
30546
+ // behaves so we can use download() with `vercel build`.
30547
+ const parts = name.split('/');
30548
+ for (let i = 1; i < parts.length; i++) {
30549
+ const dir = parts.slice(0, i).join('/');
30550
+ const parent = files[dir];
30551
+ if (parent && isSymbolicLink(parent.mode)) {
30552
+ console.warn(`Warning: file "${name}" is within a symlinked directory "${dir}" and will be ignored`);
30553
+ return;
30554
+ }
30555
+ }
30538
30556
  const file = files[name];
30539
30557
  const fsPath = path_1.default.join(basePath, name);
30540
30558
  files2[name] = await downloadFile(file, fsPath);
@@ -31444,7 +31462,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31444
31462
  return (mod && mod.__esModule) ? mod : { "default": mod };
31445
31463
  };
31446
31464
  Object.defineProperty(exports, "__esModule", ({ value: true }));
31447
- exports.normalizePath = exports.readConfigFile = exports.EdgeFunction = exports.getIgnoreFilter = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.streamToBuffer = 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.download = exports.Prerender = exports.createLambda = exports.NodejsLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
31465
+ exports.normalizePath = exports.readConfigFile = exports.EdgeFunction = exports.getIgnoreFilter = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.streamToBuffer = 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;
31448
31466
  const file_blob_1 = __importDefault(__webpack_require__(2397));
31449
31467
  exports.FileBlob = file_blob_1.default;
31450
31468
  const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
@@ -31461,6 +31479,7 @@ const prerender_1 = __webpack_require__(2850);
31461
31479
  Object.defineProperty(exports, "Prerender", ({ enumerable: true, get: function () { return prerender_1.Prerender; } }));
31462
31480
  const download_1 = __importStar(__webpack_require__(1611));
31463
31481
  exports.download = download_1.default;
31482
+ Object.defineProperty(exports, "downloadFile", ({ enumerable: true, get: function () { return download_1.downloadFile; } }));
31464
31483
  Object.defineProperty(exports, "isSymbolicLink", ({ enumerable: true, get: function () { return download_1.isSymbolicLink; } }));
31465
31484
  const get_writable_directory_1 = __importDefault(__webpack_require__(3838));
31466
31485
  exports.getWriteableDirectory = get_writable_directory_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "5.0.7",
3
+ "version": "5.1.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -14,8 +14,7 @@
14
14
  "build": "node build",
15
15
  "test": "jest --env node --verbose --runInBand --bail",
16
16
  "test-unit": "yarn test test/unit.*test.*",
17
- "test-integration-once": "yarn test test/integration.test.ts",
18
- "prepublishOnly": "node build"
17
+ "test-integration-once": "yarn test test/integration.test.ts"
19
18
  },
20
19
  "devDependencies": {
21
20
  "@iarna/toml": "2.2.3",
@@ -48,5 +47,5 @@
48
47
  "typescript": "4.3.4",
49
48
  "yazl": "2.5.1"
50
49
  },
51
- "gitHead": "e8c7db59cf2746422f1f7e14cc6b7f901c243d50"
50
+ "gitHead": "5eb8b16cbdf6215618b4b8125673941757fa1a8e"
52
51
  }