@vercel/client 17.6.1 → 17.6.3
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 +40 -20
- package/dist/utils/hashes.d.ts +5 -0
- package/dist/utils/hashes.js +17 -2
- package/dist/utils/index.js +1 -1
- package/package.json +3 -3
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
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":
|
|
194
|
+
"Content-Length": contentLength,
|
|
175
195
|
"x-now-digest": sha,
|
|
176
|
-
"x-now-size":
|
|
196
|
+
"x-now-size": contentLength
|
|
177
197
|
},
|
|
178
198
|
body,
|
|
179
199
|
teamId: options.teamId,
|
package/dist/utils/hashes.d.ts
CHANGED
|
@@ -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
|
/**
|
package/dist/utils/hashes.js
CHANGED
|
@@ -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
|
})
|
package/dist/utils/index.js
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "17.6.3",
|
|
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/build-utils": "13.32.
|
|
43
|
-
"@vercel/routing-utils": "6.
|
|
42
|
+
"@vercel/build-utils": "13.32.2",
|
|
43
|
+
"@vercel/routing-utils": "6.4.0",
|
|
44
44
|
"@vercel/error-utils": "2.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|