@vercel/client 17.6.1 → 17.6.2

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/upload.js CHANGED
@@ -35,6 +35,7 @@ __export(upload_exports, {
35
35
  module.exports = __toCommonJS(upload_exports);
36
36
  var import_http = __toESM(require("http"));
37
37
  var import_https = __toESM(require("https"));
38
+ var import_fs = require("fs");
38
39
  var import_stream = require("stream");
39
40
  var import_node_events = require("node:events");
40
41
  var import_async_retry = __toESM(require("async-retry"));
@@ -137,27 +138,46 @@ async function* uploadFiles(options) {
137
138
  semaphore.release();
138
139
  return bail(new Error("Upload aborted"));
139
140
  }
140
- const { data } = file;
141
- if (typeof data === "undefined") {
142
- return;
143
- }
141
+ const { data, size, names } = file;
144
142
  uploadProgress.bytesUploaded = 0;
145
- const body = new import_stream.Readable();
146
- const originalRead = body.read.bind(body);
147
- body.read = function(...args) {
148
- const chunk = originalRead(...args);
149
- if (chunk) {
150
- uploadProgress.bytesUploaded += chunk.length;
151
- uploadProgress.emit("progress");
143
+ let body;
144
+ let contentLength;
145
+ if (typeof data !== "undefined") {
146
+ contentLength = data.length;
147
+ const buffered = new import_stream.Readable();
148
+ const originalRead = buffered.read.bind(buffered);
149
+ buffered.read = function(...args) {
150
+ const chunk = originalRead(...args);
151
+ if (chunk) {
152
+ uploadProgress.bytesUploaded += chunk.length;
153
+ uploadProgress.emit("progress");
154
+ }
155
+ return chunk;
156
+ };
157
+ const chunkSize = 16384;
158
+ for (let i = 0; i < data.length; i += chunkSize) {
159
+ const chunk = data.slice(i, i + chunkSize);
160
+ buffered.push(chunk);
152
161
  }
153
- return chunk;
154
- };
155
- const chunkSize = 16384;
156
- for (let i = 0; i < data.length; i += chunkSize) {
157
- const chunk = data.slice(i, i + chunkSize);
158
- body.push(chunk);
162
+ buffered.push(null);
163
+ body = buffered;
164
+ } else if (typeof size === "number") {
165
+ contentLength = size;
166
+ const fileStream = (0, import_fs.createReadStream)(names[0]);
167
+ const counter = new import_stream.Transform({
168
+ transform(chunk, _encoding, callback) {
169
+ uploadProgress.bytesUploaded += chunk.length;
170
+ uploadProgress.emit("progress");
171
+ callback(null, chunk);
172
+ }
173
+ });
174
+ fileStream.on("error", (err2) => counter.destroy(err2));
175
+ counter.on("close", () => fileStream.destroy());
176
+ body = fileStream.pipe(counter);
177
+ } else {
178
+ semaphore.release();
179
+ return;
159
180
  }
160
- body.push(null);
161
181
  let err;
162
182
  let result;
163
183
  const abortController = new AbortController();
@@ -171,9 +191,9 @@ async function* uploadFiles(options) {
171
191
  method: "POST",
172
192
  headers: {
173
193
  "Content-Type": "application/octet-stream",
174
- "Content-Length": data.length,
194
+ "Content-Length": contentLength,
175
195
  "x-now-digest": sha,
176
- "x-now-size": data.length
196
+ "x-now-size": contentLength
177
197
  },
178
198
  body,
179
199
  teamId: options.teamId,
@@ -2,6 +2,11 @@ export interface DeploymentFile {
2
2
  names: string[];
3
3
  data?: Buffer;
4
4
  mode: number;
5
+ /**
6
+ * Byte length of the file's content. Always set for real files; used to send
7
+ * `Content-Length` when a file is streamed (i.e. has no in-memory `data`).
8
+ */
9
+ size?: number;
5
10
  }
6
11
  export type FilesMap = Map<string | undefined, DeploymentFile>;
7
12
  /**
@@ -36,9 +36,17 @@ module.exports = __toCommonJS(hashes_exports);
36
36
  var import_crypto = require("crypto");
37
37
  var import_fs_extra = __toESM(require("fs-extra"));
38
38
  var import_async_sema = require("async-sema");
39
+ const MAX_BUFFER_FILE_SIZE = 2 ** 31 - 1;
39
40
  function hash(buf) {
40
41
  return (0, import_crypto.createHash)("sha1").update(Uint8Array.from(buf)).digest("hex");
41
42
  }
43
+ async function hashFile(path) {
44
+ const digest = (0, import_crypto.createHash)("sha1");
45
+ for await (const chunk of import_fs_extra.default.createReadStream(path)) {
46
+ digest.update(Uint8Array.from(chunk));
47
+ }
48
+ return digest.digest("hex");
49
+ }
42
50
  const mapToObject = (map) => {
43
51
  const obj = {};
44
52
  for (const [key, value] of map) {
@@ -56,16 +64,23 @@ async function hashes(files, map = /* @__PURE__ */ new Map()) {
56
64
  const stat = await import_fs_extra.default.lstat(name);
57
65
  const mode = stat.mode;
58
66
  let data;
67
+ let size;
59
68
  const isDirectory = stat.isDirectory();
60
69
  let h;
61
70
  if (!isDirectory) {
62
71
  if (stat.isSymbolicLink()) {
63
72
  const link = await import_fs_extra.default.readlink(name);
64
73
  data = Buffer.from(link, "utf8");
74
+ size = data.length;
75
+ h = hash(data);
76
+ } else if (stat.size > MAX_BUFFER_FILE_SIZE) {
77
+ size = stat.size;
78
+ h = await hashFile(name);
65
79
  } else {
66
80
  data = await import_fs_extra.default.readFile(name);
81
+ size = data.length;
82
+ h = hash(data);
67
83
  }
68
- h = hash(data);
69
84
  }
70
85
  const entry = map.get(h);
71
86
  if (entry) {
@@ -73,7 +88,7 @@ async function hashes(files, map = /* @__PURE__ */ new Map()) {
73
88
  names.add(name);
74
89
  entry.names = [...names];
75
90
  } else {
76
- map.set(h, { names: [name], data, mode });
91
+ map.set(h, { names: [name], data, mode, size });
77
92
  }
78
93
  semaphore.release();
79
94
  })
@@ -341,7 +341,7 @@ const prepareFiles = (files, clientOptions) => {
341
341
  }
342
342
  preparedFiles.push({
343
343
  file: isWin ? fileName.replace(/\\/g, "/") : fileName,
344
- size: file.data?.byteLength || file.data?.length,
344
+ size: file.data?.byteLength ?? file.size,
345
345
  mode: file.mode,
346
346
  sha: sha || void 0
347
347
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/client",
3
- "version": "17.6.1",
3
+ "version": "17.6.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "homepage": "https://vercel.com",
@@ -39,8 +39,8 @@
39
39
  "querystring": "^0.2.0",
40
40
  "sleep-promise": "8.0.1",
41
41
  "tar-fs": "1.16.3",
42
+ "@vercel/routing-utils": "6.4.0",
42
43
  "@vercel/build-utils": "13.32.1",
43
- "@vercel/routing-utils": "6.3.1",
44
44
  "@vercel/error-utils": "2.2.0"
45
45
  },
46
46
  "scripts": {