@vercel/build-utils 8.5.0 → 8.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 8.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Support splitting archive deployments in parts. ([#12671](https://github.com/vercel/vercel/pull/12671))
8
+
9
+ ## 8.6.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Add support for `NOW_EPHEMERAL_FILES_S3_URL`, `NOW_FILES_CLOUDFRONT_URL` and `NOW_FILES_S3_URL` environment variables ([#12643](https://github.com/vercel/vercel/pull/12643))
14
+
3
15
  ## 8.5.0
4
16
 
5
17
  ### Minor Changes
@@ -13,6 +13,25 @@ export default class FileRef implements FileBase {
13
13
  contentType: string | undefined;
14
14
  private mutable;
15
15
  constructor({ mode, digest, contentType, mutable, }: FileRefOptions);
16
+ /**
17
+ * Retrieves the URL of the CloudFront distribution for the S3
18
+ * bucket represented by {@link getNowFilesS3Url}.
19
+ *
20
+ * @returns The URL of the CloudFront distribution
21
+ */
22
+ private getNowFilesCloudfrontUrl;
23
+ /**
24
+ * Retrieves the URL of the S3 bucket for storing ephemeral files.
25
+ *
26
+ * @returns The URL of the S3 bucket
27
+ */
28
+ private getNowEphemeralFilesS3Url;
29
+ /**
30
+ * Retrieves the URL of the S3 bucket for storing files.
31
+ *
32
+ * @returns The URL of the S3 bucket
33
+ */
34
+ private getNowFilesS3Url;
16
35
  toStreamAsync(): Promise<NodeJS.ReadableStream>;
17
36
  toStream(): NodeJS.ReadableStream;
18
37
  }
package/dist/file-ref.js CHANGED
@@ -58,13 +58,38 @@ class FileRef {
58
58
  this.contentType = contentType;
59
59
  this.mutable = mutable;
60
60
  }
61
+ /**
62
+ * Retrieves the URL of the CloudFront distribution for the S3
63
+ * bucket represented by {@link getNowFilesS3Url}.
64
+ *
65
+ * @returns The URL of the CloudFront distribution
66
+ */
67
+ getNowFilesCloudfrontUrl() {
68
+ return getEnvAsUrlOrThrow("NOW_FILES_CLOUDFRONT_URL") || "https://dmmcy0pwk6bqi.cloudfront.net";
69
+ }
70
+ /**
71
+ * Retrieves the URL of the S3 bucket for storing ephemeral files.
72
+ *
73
+ * @returns The URL of the S3 bucket
74
+ */
75
+ getNowEphemeralFilesS3Url() {
76
+ return getEnvAsUrlOrThrow("NOW_EPHEMERAL_FILES_S3_URL") || "https://now-ephemeral-files.s3.amazonaws.com";
77
+ }
78
+ /**
79
+ * Retrieves the URL of the S3 bucket for storing files.
80
+ *
81
+ * @returns The URL of the S3 bucket
82
+ */
83
+ getNowFilesS3Url() {
84
+ return getEnvAsUrlOrThrow("NOW_FILES_S3_URL") || "https://now-files.s3.amazonaws.com";
85
+ }
61
86
  async toStreamAsync() {
62
87
  let url = "";
63
88
  const [digestType, digestHash] = this.digest.split(":");
64
89
  if (digestType === "sha") {
65
- url = this.mutable ? `https://now-files.s3.amazonaws.com/${digestHash}` : `https://dmmcy0pwk6bqi.cloudfront.net/${digestHash}`;
90
+ url = this.mutable ? `${this.getNowFilesS3Url()}/${digestHash}` : `${this.getNowFilesCloudfrontUrl()}/${digestHash}`;
66
91
  } else if (digestType === "sha+ephemeral") {
67
- url = `https://now-ephemeral-files.s3.amazonaws.com/${digestHash}`;
92
+ url = `${this.getNowEphemeralFilesS3Url()}/${digestHash}`;
68
93
  } else {
69
94
  throw new Error("Expected digest to be sha");
70
95
  }
@@ -103,3 +128,20 @@ class FileRef {
103
128
  });
104
129
  }
105
130
  }
131
+ function getEnvAsUrlOrThrow(key) {
132
+ const value = process.env[key];
133
+ if (value === void 0)
134
+ return void 0;
135
+ try {
136
+ new URL(value);
137
+ return value;
138
+ } catch (e) {
139
+ if (e instanceof TypeError && "code" in e && e.code === "ERR_INVALID_URL") {
140
+ throw new Error(
141
+ `A non-URL value was supplied to the ${key} environment variable`
142
+ );
143
+ } else {
144
+ throw e;
145
+ }
146
+ }
147
+ }
@@ -1,2 +1,3 @@
1
1
  /// <reference types="node" />
2
2
  export default function streamToBuffer(stream: NodeJS.ReadableStream): Promise<Buffer>;
3
+ export declare function streamToBufferChunks(stream: NodeJS.ReadableStream, chunkSize?: number): Promise<Buffer[]>;
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var stream_to_buffer_exports = {};
30
30
  __export(stream_to_buffer_exports, {
31
- default: () => streamToBuffer
31
+ default: () => streamToBuffer,
32
+ streamToBufferChunks: () => streamToBufferChunks
32
33
  });
33
34
  module.exports = __toCommonJS(stream_to_buffer_exports);
34
35
  var import_end_of_stream = __toESM(require("end-of-stream"));
@@ -54,3 +55,33 @@ function streamToBuffer(stream) {
54
55
  });
55
56
  });
56
57
  }
58
+ const MB = 1024 * 1024;
59
+ async function streamToBufferChunks(stream, chunkSize = 100 * MB) {
60
+ const chunks = [];
61
+ let currentChunk = [];
62
+ let currentSize = 0;
63
+ for await (const chunk of stream) {
64
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
65
+ let offset = 0;
66
+ while (offset < buffer.length) {
67
+ const remainingSpace = chunkSize - currentSize;
68
+ const sliceSize = Math.min(remainingSpace, buffer.length - offset);
69
+ currentChunk.push(buffer.slice(offset, offset + sliceSize));
70
+ currentSize += sliceSize;
71
+ offset += sliceSize;
72
+ if (currentSize >= chunkSize) {
73
+ chunks.push(Buffer.concat(currentChunk));
74
+ currentChunk = [];
75
+ currentSize = 0;
76
+ }
77
+ }
78
+ }
79
+ if (currentChunk.length > 0) {
80
+ chunks.push(Buffer.concat(currentChunk));
81
+ }
82
+ return chunks;
83
+ }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ streamToBufferChunks
87
+ });
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ import glob, { GlobOptions } from './fs/glob';
10
10
  import rename from './fs/rename';
11
11
  import { spawnAsync, execCommand, spawnCommand, walkParentDirs, getScriptName, installDependencies, runPackageJsonScript, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getSpawnOptions, getNodeBinPath, getNodeBinPaths, scanParentDirs, traverseUpDirectories } from './fs/run-user-scripts';
12
12
  import { getLatestNodeVersion, getDiscontinuedNodeVersions, getSupportedNodeVersion } from './fs/node-version';
13
- import streamToBuffer from './fs/stream-to-buffer';
13
+ import streamToBuffer, { streamToBufferChunks } 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';
@@ -18,7 +18,7 @@ import { getPrefixedEnvVars } from './get-prefixed-env-vars';
18
18
  import { cloneEnv } from './clone-env';
19
19
  import { hardLinkDir } from './hard-link-dir';
20
20
  import { validateNpmrc } from './validate-npmrc';
21
- export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, downloadFile, DownloadedFiles, getWriteableDirectory, glob, GlobOptions, rename, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, getNodeBinPaths, getSupportedNodeVersion, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, streamToBuffer, debug, isSymbolicLink, isDirectory, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, };
21
+ export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, downloadFile, DownloadedFiles, getWriteableDirectory, glob, GlobOptions, rename, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, getNodeBinPaths, getSupportedNodeVersion, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, streamToBuffer, streamToBufferChunks, debug, isSymbolicLink, isDirectory, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, };
22
22
  export { EdgeFunction } from './edge-function';
23
23
  export { readConfigFile } from './fs/read-config-file';
24
24
  export { normalizePath } from './fs/normalize-path';
package/dist/index.js CHANGED
@@ -8619,8 +8619,8 @@ var require_URL = __commonJS({
8619
8619
  var utils = require_utils3();
8620
8620
  var Impl = require_URL_impl();
8621
8621
  var impl = utils.implSymbol;
8622
- function URL(url) {
8623
- if (!this || this[impl] || !(this instanceof URL)) {
8622
+ function URL2(url) {
8623
+ if (!this || this[impl] || !(this instanceof URL2)) {
8624
8624
  throw new TypeError("Failed to construct 'URL': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
8625
8625
  }
8626
8626
  if (arguments.length < 1) {
@@ -8636,7 +8636,7 @@ var require_URL = __commonJS({
8636
8636
  }
8637
8637
  module2.exports.setup(this, args);
8638
8638
  }
8639
- URL.prototype.toJSON = function toJSON() {
8639
+ URL2.prototype.toJSON = function toJSON() {
8640
8640
  if (!this || !module2.exports.is(this)) {
8641
8641
  throw new TypeError("Illegal invocation");
8642
8642
  }
@@ -8646,7 +8646,7 @@ var require_URL = __commonJS({
8646
8646
  }
8647
8647
  return this[impl].toJSON.apply(this[impl], args);
8648
8648
  };
8649
- Object.defineProperty(URL.prototype, "href", {
8649
+ Object.defineProperty(URL2.prototype, "href", {
8650
8650
  get() {
8651
8651
  return this[impl].href;
8652
8652
  },
@@ -8657,20 +8657,20 @@ var require_URL = __commonJS({
8657
8657
  enumerable: true,
8658
8658
  configurable: true
8659
8659
  });
8660
- URL.prototype.toString = function() {
8660
+ URL2.prototype.toString = function() {
8661
8661
  if (!this || !module2.exports.is(this)) {
8662
8662
  throw new TypeError("Illegal invocation");
8663
8663
  }
8664
8664
  return this.href;
8665
8665
  };
8666
- Object.defineProperty(URL.prototype, "origin", {
8666
+ Object.defineProperty(URL2.prototype, "origin", {
8667
8667
  get() {
8668
8668
  return this[impl].origin;
8669
8669
  },
8670
8670
  enumerable: true,
8671
8671
  configurable: true
8672
8672
  });
8673
- Object.defineProperty(URL.prototype, "protocol", {
8673
+ Object.defineProperty(URL2.prototype, "protocol", {
8674
8674
  get() {
8675
8675
  return this[impl].protocol;
8676
8676
  },
@@ -8681,7 +8681,7 @@ var require_URL = __commonJS({
8681
8681
  enumerable: true,
8682
8682
  configurable: true
8683
8683
  });
8684
- Object.defineProperty(URL.prototype, "username", {
8684
+ Object.defineProperty(URL2.prototype, "username", {
8685
8685
  get() {
8686
8686
  return this[impl].username;
8687
8687
  },
@@ -8692,7 +8692,7 @@ var require_URL = __commonJS({
8692
8692
  enumerable: true,
8693
8693
  configurable: true
8694
8694
  });
8695
- Object.defineProperty(URL.prototype, "password", {
8695
+ Object.defineProperty(URL2.prototype, "password", {
8696
8696
  get() {
8697
8697
  return this[impl].password;
8698
8698
  },
@@ -8703,7 +8703,7 @@ var require_URL = __commonJS({
8703
8703
  enumerable: true,
8704
8704
  configurable: true
8705
8705
  });
8706
- Object.defineProperty(URL.prototype, "host", {
8706
+ Object.defineProperty(URL2.prototype, "host", {
8707
8707
  get() {
8708
8708
  return this[impl].host;
8709
8709
  },
@@ -8714,7 +8714,7 @@ var require_URL = __commonJS({
8714
8714
  enumerable: true,
8715
8715
  configurable: true
8716
8716
  });
8717
- Object.defineProperty(URL.prototype, "hostname", {
8717
+ Object.defineProperty(URL2.prototype, "hostname", {
8718
8718
  get() {
8719
8719
  return this[impl].hostname;
8720
8720
  },
@@ -8725,7 +8725,7 @@ var require_URL = __commonJS({
8725
8725
  enumerable: true,
8726
8726
  configurable: true
8727
8727
  });
8728
- Object.defineProperty(URL.prototype, "port", {
8728
+ Object.defineProperty(URL2.prototype, "port", {
8729
8729
  get() {
8730
8730
  return this[impl].port;
8731
8731
  },
@@ -8736,7 +8736,7 @@ var require_URL = __commonJS({
8736
8736
  enumerable: true,
8737
8737
  configurable: true
8738
8738
  });
8739
- Object.defineProperty(URL.prototype, "pathname", {
8739
+ Object.defineProperty(URL2.prototype, "pathname", {
8740
8740
  get() {
8741
8741
  return this[impl].pathname;
8742
8742
  },
@@ -8747,7 +8747,7 @@ var require_URL = __commonJS({
8747
8747
  enumerable: true,
8748
8748
  configurable: true
8749
8749
  });
8750
- Object.defineProperty(URL.prototype, "search", {
8750
+ Object.defineProperty(URL2.prototype, "search", {
8751
8751
  get() {
8752
8752
  return this[impl].search;
8753
8753
  },
@@ -8758,7 +8758,7 @@ var require_URL = __commonJS({
8758
8758
  enumerable: true,
8759
8759
  configurable: true
8760
8760
  });
8761
- Object.defineProperty(URL.prototype, "hash", {
8761
+ Object.defineProperty(URL2.prototype, "hash", {
8762
8762
  get() {
8763
8763
  return this[impl].hash;
8764
8764
  },
@@ -8774,7 +8774,7 @@ var require_URL = __commonJS({
8774
8774
  return !!obj && obj[impl] instanceof Impl.implementation;
8775
8775
  },
8776
8776
  create(constructorArgs, privateData) {
8777
- let obj = Object.create(URL.prototype);
8777
+ let obj = Object.create(URL2.prototype);
8778
8778
  this.setup(obj, constructorArgs, privateData);
8779
8779
  return obj;
8780
8780
  },
@@ -8785,10 +8785,10 @@ var require_URL = __commonJS({
8785
8785
  obj[impl] = new Impl.implementation(constructorArgs, privateData);
8786
8786
  obj[impl][utils.wrapperSymbol] = obj;
8787
8787
  },
8788
- interface: URL,
8788
+ interface: URL2,
8789
8789
  expose: {
8790
- Window: { URL },
8791
- Worker: { URL }
8790
+ Window: { URL: URL2 },
8791
+ Worker: { URL: URL2 }
8792
8792
  }
8793
8793
  };
8794
8794
  }
@@ -9639,12 +9639,12 @@ var require_lib3 = __commonJS({
9639
9639
  configurable: true
9640
9640
  });
9641
9641
  var INTERNALS$2 = Symbol("Request internals");
9642
- var URL = Url.URL || whatwgUrl.URL;
9642
+ var URL2 = Url.URL || whatwgUrl.URL;
9643
9643
  var parse_url = Url.parse;
9644
9644
  var format_url = Url.format;
9645
9645
  function parseURL(urlStr) {
9646
9646
  if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
9647
- urlStr = new URL(urlStr).toString();
9647
+ urlStr = new URL2(urlStr).toString();
9648
9648
  }
9649
9649
  return parse_url(urlStr);
9650
9650
  }
@@ -23499,6 +23499,7 @@ __export(src_exports, {
23499
23499
  spawnAsync: () => spawnAsync,
23500
23500
  spawnCommand: () => spawnCommand,
23501
23501
  streamToBuffer: () => streamToBuffer,
23502
+ streamToBufferChunks: () => streamToBufferChunks,
23502
23503
  traverseUpDirectories: () => traverseUpDirectories,
23503
23504
  validateNpmrc: () => validateNpmrc,
23504
23505
  walkParentDirs: () => walkParentDirs
@@ -23651,13 +23652,38 @@ var FileRef = class {
23651
23652
  this.contentType = contentType;
23652
23653
  this.mutable = mutable;
23653
23654
  }
23655
+ /**
23656
+ * Retrieves the URL of the CloudFront distribution for the S3
23657
+ * bucket represented by {@link getNowFilesS3Url}.
23658
+ *
23659
+ * @returns The URL of the CloudFront distribution
23660
+ */
23661
+ getNowFilesCloudfrontUrl() {
23662
+ return getEnvAsUrlOrThrow("NOW_FILES_CLOUDFRONT_URL") || "https://dmmcy0pwk6bqi.cloudfront.net";
23663
+ }
23664
+ /**
23665
+ * Retrieves the URL of the S3 bucket for storing ephemeral files.
23666
+ *
23667
+ * @returns The URL of the S3 bucket
23668
+ */
23669
+ getNowEphemeralFilesS3Url() {
23670
+ return getEnvAsUrlOrThrow("NOW_EPHEMERAL_FILES_S3_URL") || "https://now-ephemeral-files.s3.amazonaws.com";
23671
+ }
23672
+ /**
23673
+ * Retrieves the URL of the S3 bucket for storing files.
23674
+ *
23675
+ * @returns The URL of the S3 bucket
23676
+ */
23677
+ getNowFilesS3Url() {
23678
+ return getEnvAsUrlOrThrow("NOW_FILES_S3_URL") || "https://now-files.s3.amazonaws.com";
23679
+ }
23654
23680
  async toStreamAsync() {
23655
23681
  let url = "";
23656
23682
  const [digestType, digestHash] = this.digest.split(":");
23657
23683
  if (digestType === "sha") {
23658
- url = this.mutable ? `https://now-files.s3.amazonaws.com/${digestHash}` : `https://dmmcy0pwk6bqi.cloudfront.net/${digestHash}`;
23684
+ url = this.mutable ? `${this.getNowFilesS3Url()}/${digestHash}` : `${this.getNowFilesCloudfrontUrl()}/${digestHash}`;
23659
23685
  } else if (digestType === "sha+ephemeral") {
23660
- url = `https://now-ephemeral-files.s3.amazonaws.com/${digestHash}`;
23686
+ url = `${this.getNowEphemeralFilesS3Url()}/${digestHash}`;
23661
23687
  } else {
23662
23688
  throw new Error("Expected digest to be sha");
23663
23689
  }
@@ -23696,6 +23722,23 @@ var FileRef = class {
23696
23722
  });
23697
23723
  }
23698
23724
  };
23725
+ function getEnvAsUrlOrThrow(key) {
23726
+ const value = process.env[key];
23727
+ if (value === void 0)
23728
+ return void 0;
23729
+ try {
23730
+ new URL(value);
23731
+ return value;
23732
+ } catch (e) {
23733
+ if (e instanceof TypeError && "code" in e && e.code === "ERR_INVALID_URL") {
23734
+ throw new Error(
23735
+ `A non-URL value was supplied to the ${key} environment variable`
23736
+ );
23737
+ } else {
23738
+ throw e;
23739
+ }
23740
+ }
23741
+ }
23699
23742
 
23700
23743
  // src/lambda.ts
23701
23744
  var import_assert4 = __toESM(require("assert"));
@@ -23830,6 +23873,32 @@ function streamToBuffer(stream) {
23830
23873
  });
23831
23874
  });
23832
23875
  }
23876
+ var MB = 1024 * 1024;
23877
+ async function streamToBufferChunks(stream, chunkSize = 100 * MB) {
23878
+ const chunks = [];
23879
+ let currentChunk = [];
23880
+ let currentSize = 0;
23881
+ for await (const chunk of stream) {
23882
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
23883
+ let offset = 0;
23884
+ while (offset < buffer.length) {
23885
+ const remainingSpace = chunkSize - currentSize;
23886
+ const sliceSize = Math.min(remainingSpace, buffer.length - offset);
23887
+ currentChunk.push(buffer.slice(offset, offset + sliceSize));
23888
+ currentSize += sliceSize;
23889
+ offset += sliceSize;
23890
+ if (currentSize >= chunkSize) {
23891
+ chunks.push(Buffer.concat(currentChunk));
23892
+ currentChunk = [];
23893
+ currentSize = 0;
23894
+ }
23895
+ }
23896
+ }
23897
+ if (currentChunk.length > 0) {
23898
+ chunks.push(Buffer.concat(currentChunk));
23899
+ }
23900
+ return chunks;
23901
+ }
23833
23902
 
23834
23903
  // src/fs/download.ts
23835
23904
  var S_IFDIR = 16384;
@@ -25770,6 +25839,7 @@ async function getInstalledPackageVersion(packageName, path7) {
25770
25839
  spawnAsync,
25771
25840
  spawnCommand,
25772
25841
  streamToBuffer,
25842
+ streamToBufferChunks,
25773
25843
  traverseUpDirectories,
25774
25844
  validateNpmrc,
25775
25845
  walkParentDirs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "8.5.0",
3
+ "version": "8.7.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",