@zharp/cli 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +94 -3
- package/dist/cli.js +1437 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.mts +292 -0
- package/dist/index.d.ts +292 -0
- package/dist/index.js +850 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +791 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -3
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
// src/api.ts
|
|
2
|
+
import { gzipSync } from "zlib";
|
|
3
|
+
var DEFAULT_URL = "https://api.zharp.io";
|
|
4
|
+
var UploadError = class extends Error {
|
|
5
|
+
constructor(message, status, permanent = false) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.permanent = permanent;
|
|
9
|
+
this.name = "UploadError";
|
|
10
|
+
}
|
|
11
|
+
status;
|
|
12
|
+
permanent;
|
|
13
|
+
};
|
|
14
|
+
function resolveConnection(options) {
|
|
15
|
+
const authToken = options.authToken || process.env.ZHARP_AUTH_TOKEN;
|
|
16
|
+
const app = options.app ?? process.env.ZHARP_APP;
|
|
17
|
+
const missing = [];
|
|
18
|
+
if (!authToken) missing.push('an auth token (ZHARP_AUTH_TOKEN, or the authToken option): a workspace API key with the "artifacts:write" scope');
|
|
19
|
+
if (app === void 0 || app === "") missing.push("the application ID (--app, the app option, or ZHARP_APP)");
|
|
20
|
+
if (missing.length) throw new UploadError(`Cannot upload without ${missing.join(" and ")}.`, void 0, true);
|
|
21
|
+
return { url: (options.url || process.env.ZHARP_URL || DEFAULT_URL).replace(/\/+$/, ""), authToken, app };
|
|
22
|
+
}
|
|
23
|
+
function artifactsUrl(connection) {
|
|
24
|
+
return `${connection.url}/api/v1/applications/${encodeURIComponent(String(connection.app))}/artifacts`;
|
|
25
|
+
}
|
|
26
|
+
var sleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
27
|
+
async function uploadArtifact(connection, artifact, options = {}) {
|
|
28
|
+
const doFetch = options.fetch ?? fetch;
|
|
29
|
+
const retries = options.retries ?? 3;
|
|
30
|
+
const backoff = options.backoffMs ?? 1e3;
|
|
31
|
+
const fileName = (artifact.name.split("/").pop() || "artifact") + (artifact.gzip ? ".gz" : "");
|
|
32
|
+
const payload = artifact.gzip ? gzipSync(artifact.data) : artifact.data;
|
|
33
|
+
for (let attempt = 0; ; attempt++) {
|
|
34
|
+
const form = new FormData();
|
|
35
|
+
form.set("kind", artifact.kind);
|
|
36
|
+
form.set("debugId", artifact.debugId);
|
|
37
|
+
form.set("name", artifact.name);
|
|
38
|
+
if (artifact.release) form.set("release", artifact.release);
|
|
39
|
+
if (artifact.arch) form.set("arch", artifact.arch);
|
|
40
|
+
const type = artifact.gzip ? "application/gzip" : artifact.kind === "sourcemap" ? "application/json" : "application/octet-stream";
|
|
41
|
+
form.set("file", new Blob([payload], { type }), fileName);
|
|
42
|
+
let retryAfter = 0;
|
|
43
|
+
let error;
|
|
44
|
+
try {
|
|
45
|
+
const response = await doFetch(artifactsUrl(connection), {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { Authorization: `Bearer ${connection.authToken}`, "User-Agent": "zharp-cli" },
|
|
48
|
+
body: form
|
|
49
|
+
});
|
|
50
|
+
const text = await response.text().catch(() => "");
|
|
51
|
+
if (response.ok) {
|
|
52
|
+
try {
|
|
53
|
+
return text ? JSON.parse(text) : null;
|
|
54
|
+
} catch {
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
error = describeFailure(response.status, text, connection);
|
|
59
|
+
retryAfter = Number(response.headers.get("retry-after")) * 1e3 || 0;
|
|
60
|
+
} catch (cause) {
|
|
61
|
+
error = new UploadError(`Could not reach ${connection.url}: ${cause?.message ?? cause}`);
|
|
62
|
+
}
|
|
63
|
+
if (error.permanent || attempt >= retries) throw error;
|
|
64
|
+
await sleep(Math.max(retryAfter, backoff * 2 ** attempt));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function serverMessage(text) {
|
|
68
|
+
try {
|
|
69
|
+
const body = JSON.parse(text);
|
|
70
|
+
const message = body?.message ?? body?.error;
|
|
71
|
+
if (typeof message === "string") return message;
|
|
72
|
+
if (Array.isArray(message)) return message.join("; ");
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
return text.slice(0, 300);
|
|
76
|
+
}
|
|
77
|
+
function describeFailure(status, text, connection) {
|
|
78
|
+
const detail = serverMessage(text);
|
|
79
|
+
const retryable = status === 408 || status === 429 || status >= 500;
|
|
80
|
+
const explain = {
|
|
81
|
+
401: "The auth token was rejected \u2014 check ZHARP_AUTH_TOKEN (a workspace API key, not the app key).",
|
|
82
|
+
403: 'The API key cannot upload here \u2014 it needs the "artifacts:write" scope, in the workspace that owns the app.',
|
|
83
|
+
404: `Application ${connection.app} was not found \u2014 check --app (the ID in the app's dashboard URL) and ZHARP_URL.`,
|
|
84
|
+
413: "The file is larger than the server accepts."
|
|
85
|
+
};
|
|
86
|
+
const message = `${explain[status] ?? `Upload failed with HTTP ${status}.`}${detail ? ` Server said: ${detail}` : ""}`;
|
|
87
|
+
return new UploadError(message, status, !retryable);
|
|
88
|
+
}
|
|
89
|
+
async function eachLimit(items, limit, fn) {
|
|
90
|
+
let next = 0;
|
|
91
|
+
let failed;
|
|
92
|
+
const worker = async () => {
|
|
93
|
+
while (failed === void 0 && next < items.length) {
|
|
94
|
+
const index = next++;
|
|
95
|
+
try {
|
|
96
|
+
await fn(items[index], index);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
failed ??= error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
103
|
+
if (failed !== void 0) throw failed;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/debug-id.ts
|
|
107
|
+
import { createHash } from "crypto";
|
|
108
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
109
|
+
import { dirname, isAbsolute, join, resolve } from "path";
|
|
110
|
+
import { fileURLToPath } from "url";
|
|
111
|
+
var DEBUG_ID_COMMENT = "//# debugId=";
|
|
112
|
+
var DEBUG_ID_PATTERN = /^\/\/# debugId=([0-9a-fA-F-]{36})\s*$/m;
|
|
113
|
+
var SOURCE_MAPPING_URL = /^\/\/[#@] sourceMappingURL=(.*?)\s*$/;
|
|
114
|
+
function debugIdFromContent(content) {
|
|
115
|
+
const bytes = createHash("sha256").update(content).digest().subarray(0, 16);
|
|
116
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
117
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
118
|
+
const hex2 = bytes.toString("hex");
|
|
119
|
+
return `${hex2.slice(0, 8)}-${hex2.slice(8, 12)}-${hex2.slice(12, 16)}-${hex2.slice(16, 20)}-${hex2.slice(20)}`;
|
|
120
|
+
}
|
|
121
|
+
function registrationSnippet(debugId) {
|
|
122
|
+
return `;!function(){try{var g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s=(new Error).stack;s&&((g.__zharpDebugIds=g.__zharpDebugIds||{})[s]="${debugId}")}catch(e){}}();`;
|
|
123
|
+
}
|
|
124
|
+
function existingDebugId(code) {
|
|
125
|
+
const lines = code.trimEnd().split("\n");
|
|
126
|
+
for (let i = lines.length - 1; i >= 0 && i >= lines.length - 4; i--) {
|
|
127
|
+
const match = DEBUG_ID_PATTERN.exec(lines[i].trim());
|
|
128
|
+
if (match) return match[1].toLowerCase();
|
|
129
|
+
}
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
function hasRegistration(code) {
|
|
133
|
+
return code.slice(-2e3).includes(".__zharpDebugIds=");
|
|
134
|
+
}
|
|
135
|
+
function sourceMappingUrl(code) {
|
|
136
|
+
const lines = code.trimEnd().split("\n");
|
|
137
|
+
for (let i = lines.length - 1; i >= 0 && i >= lines.length - 3; i--) {
|
|
138
|
+
const match = SOURCE_MAPPING_URL.exec(lines[i].trim());
|
|
139
|
+
if (match) return match[1];
|
|
140
|
+
}
|
|
141
|
+
return void 0;
|
|
142
|
+
}
|
|
143
|
+
function injectCode(code, options = {}) {
|
|
144
|
+
const existing = existingDebugId(code);
|
|
145
|
+
const eol = code.includes("\r\n") ? "\r\n" : "\n";
|
|
146
|
+
if (existing) {
|
|
147
|
+
let out2 = code;
|
|
148
|
+
if (!hasRegistration(code)) {
|
|
149
|
+
const lines2 = code.split(/\r?\n/);
|
|
150
|
+
let at = lines2.length - 1;
|
|
151
|
+
while (at > 0 && !lines2[at].trim().startsWith(DEBUG_ID_COMMENT)) at--;
|
|
152
|
+
lines2.splice(at, 0, registrationSnippet(existing));
|
|
153
|
+
out2 = lines2.join(eol);
|
|
154
|
+
}
|
|
155
|
+
if (options.stripSourceMappingUrl) out2 = withoutSourceMappingUrl(out2);
|
|
156
|
+
return { code: out2, debugId: existing, changed: out2 !== code };
|
|
157
|
+
}
|
|
158
|
+
const debugId = debugIdFromContent(code);
|
|
159
|
+
const lines = code.split(/\r?\n/);
|
|
160
|
+
let tail = [];
|
|
161
|
+
let end = lines.length;
|
|
162
|
+
while (end > 0 && lines[end - 1].trim() === "") end--;
|
|
163
|
+
if (end > 0 && SOURCE_MAPPING_URL.test(lines[end - 1].trim())) {
|
|
164
|
+
tail = options.stripSourceMappingUrl ? [] : [lines[end - 1]];
|
|
165
|
+
end--;
|
|
166
|
+
}
|
|
167
|
+
const body = lines.slice(0, end);
|
|
168
|
+
const out = [...body, registrationSnippet(debugId), `${DEBUG_ID_COMMENT}${debugId}`, ...tail].join(eol) + eol;
|
|
169
|
+
return { code: out, debugId, changed: true };
|
|
170
|
+
}
|
|
171
|
+
function withoutSourceMappingUrl(code) {
|
|
172
|
+
const lines = code.split(/\r?\n/);
|
|
173
|
+
const eol = code.includes("\r\n") ? "\r\n" : "\n";
|
|
174
|
+
let end = lines.length;
|
|
175
|
+
while (end > 0 && lines[end - 1].trim() === "") end--;
|
|
176
|
+
if (end > 0 && SOURCE_MAPPING_URL.test(lines[end - 1].trim())) return lines.slice(0, end - 1).join(eol) + eol;
|
|
177
|
+
return code;
|
|
178
|
+
}
|
|
179
|
+
function injectMap(mapText, debugId, mapPath) {
|
|
180
|
+
const map = JSON.parse(mapText);
|
|
181
|
+
if (!map || typeof map !== "object") throw new Error("not a source map");
|
|
182
|
+
const filled = mapPath ? fillSourcesContent(map, mapPath) : 0;
|
|
183
|
+
const hasSourcesContent = Array.isArray(map.sourcesContent) && map.sourcesContent.some((s) => typeof s === "string");
|
|
184
|
+
if (!filled && map.debugId === debugId && map.debug_id === debugId) return { text: mapText, changed: false, hasSourcesContent };
|
|
185
|
+
map.debugId = debugId;
|
|
186
|
+
map.debug_id = debugId;
|
|
187
|
+
return { text: JSON.stringify(map), changed: true, hasSourcesContent };
|
|
188
|
+
}
|
|
189
|
+
var MAX_SOURCE_BYTES = 1e6;
|
|
190
|
+
function sourcePathCandidates(source, mapPath, sourceRoot = "") {
|
|
191
|
+
const mapDir = dirname(mapPath);
|
|
192
|
+
let stripped = source;
|
|
193
|
+
let projectRelative = false;
|
|
194
|
+
if (/^turbopack:\/\/\/\[project\]\//.test(source)) {
|
|
195
|
+
stripped = source.replace(/^turbopack:\/\/\/\[project\]\//, "");
|
|
196
|
+
projectRelative = true;
|
|
197
|
+
} else if (/^webpack:\/\//.test(source)) {
|
|
198
|
+
stripped = source.replace(/^webpack:\/\/[^/]*\//, "").replace(/^\.\//, "");
|
|
199
|
+
projectRelative = true;
|
|
200
|
+
} else if (/^file:\/\//.test(source)) {
|
|
201
|
+
try {
|
|
202
|
+
return [fileURLToPath(source)];
|
|
203
|
+
} catch {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
} else if (/^[a-z][\w+.-]*:\/\//i.test(source)) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
if (isAbsolute(stripped)) return [stripped];
|
|
210
|
+
const out = [resolve(mapDir, sourceRoot, stripped)];
|
|
211
|
+
if (projectRelative) {
|
|
212
|
+
for (let dir = mapDir, i = 0; i < 12; i++) {
|
|
213
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
214
|
+
out.unshift(join(dir, stripped));
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
const up = dirname(dir);
|
|
218
|
+
if (up === dir) break;
|
|
219
|
+
dir = up;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
function fillSourcesContent(map, mapPath) {
|
|
225
|
+
if (!Array.isArray(map.sources)) return 0;
|
|
226
|
+
const contents = Array.isArray(map.sourcesContent) ? [...map.sourcesContent] : [];
|
|
227
|
+
let filled = 0;
|
|
228
|
+
map.sources.forEach((source, i) => {
|
|
229
|
+
if (typeof contents[i] === "string" || typeof source !== "string") return;
|
|
230
|
+
if (/node_modules|^\[externals\]|\(ignored\)|^webpack\/runtime/.test(source)) return;
|
|
231
|
+
for (const path of sourcePathCandidates(source, mapPath, typeof map.sourceRoot === "string" ? map.sourceRoot : "")) {
|
|
232
|
+
if (/[\\/]node_modules[\\/]/.test(path)) continue;
|
|
233
|
+
try {
|
|
234
|
+
const stat = statSync(path);
|
|
235
|
+
if (!stat.isFile() || stat.size > MAX_SOURCE_BYTES) continue;
|
|
236
|
+
contents[i] = readFileSync(path, "utf8");
|
|
237
|
+
filled++;
|
|
238
|
+
break;
|
|
239
|
+
} catch {
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
if (filled) {
|
|
244
|
+
while (contents.length < map.sources.length) contents.push(null);
|
|
245
|
+
map.sourcesContent = contents.map((c) => typeof c === "string" ? c : null);
|
|
246
|
+
}
|
|
247
|
+
return filled;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/elf.ts
|
|
251
|
+
var NT_GNU_BUILD_ID = 3;
|
|
252
|
+
var SHT_NOTE = 7;
|
|
253
|
+
var PT_NOTE = 4;
|
|
254
|
+
var MACHINES = { 3: "x86", 40: "arm", 62: "x86_64", 183: "arm64", 243: "riscv64" };
|
|
255
|
+
function isElf(data) {
|
|
256
|
+
return data.length >= 16 && data[0] === 127 && data[1] === 69 && data[2] === 76 && data[3] === 70;
|
|
257
|
+
}
|
|
258
|
+
function readElf(data) {
|
|
259
|
+
if (!isElf(data)) throw new Error("not an ELF file");
|
|
260
|
+
const bits = data[4] === 2 ? 64 : 32;
|
|
261
|
+
const littleEndian = data[5] !== 2;
|
|
262
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
263
|
+
const u16 = (o) => view.getUint16(o, littleEndian);
|
|
264
|
+
const u32 = (o) => view.getUint32(o, littleEndian);
|
|
265
|
+
const addr = (o) => bits === 64 ? Number(view.getBigUint64(o, littleEndian)) : u32(o);
|
|
266
|
+
const info = { bits, littleEndian, arch: MACHINES[u16(18)] };
|
|
267
|
+
const notes = (offset, size) => {
|
|
268
|
+
let p = offset;
|
|
269
|
+
const end = Math.min(offset + size, data.length);
|
|
270
|
+
while (p + 12 <= end) {
|
|
271
|
+
const nameSize = u32(p);
|
|
272
|
+
const descSize = u32(p + 4);
|
|
273
|
+
const type = u32(p + 8);
|
|
274
|
+
const nameStart = p + 12;
|
|
275
|
+
const descStart = nameStart + align4(nameSize);
|
|
276
|
+
if (descStart + descSize > end) break;
|
|
277
|
+
const name = String.fromCharCode(...data.subarray(nameStart, nameStart + Math.max(0, nameSize - 1)));
|
|
278
|
+
if (name === "GNU" && type === NT_GNU_BUILD_ID) return hex(data.subarray(descStart, descStart + descSize));
|
|
279
|
+
p = descStart + align4(descSize);
|
|
280
|
+
}
|
|
281
|
+
return void 0;
|
|
282
|
+
};
|
|
283
|
+
const shoff = addr(bits === 64 ? 40 : 32);
|
|
284
|
+
const shentsize = u16(bits === 64 ? 58 : 46);
|
|
285
|
+
const shnum = u16(bits === 64 ? 60 : 48);
|
|
286
|
+
for (let i = 0; i < shnum && shoff > 0; i++) {
|
|
287
|
+
const h = shoff + i * shentsize;
|
|
288
|
+
if (h + shentsize > data.length) break;
|
|
289
|
+
if (u32(h + 4) !== SHT_NOTE) continue;
|
|
290
|
+
const offset = addr(bits === 64 ? h + 24 : h + 16);
|
|
291
|
+
const size = addr(bits === 64 ? h + 32 : h + 20);
|
|
292
|
+
const id = notes(offset, size);
|
|
293
|
+
if (id) return { ...info, buildId: id };
|
|
294
|
+
}
|
|
295
|
+
const phoff = addr(bits === 64 ? 32 : 28);
|
|
296
|
+
const phentsize = u16(bits === 64 ? 54 : 42);
|
|
297
|
+
const phnum = u16(bits === 64 ? 56 : 44);
|
|
298
|
+
for (let i = 0; i < phnum && phoff > 0; i++) {
|
|
299
|
+
const h = phoff + i * phentsize;
|
|
300
|
+
if (h + phentsize > data.length) break;
|
|
301
|
+
if (u32(h) !== PT_NOTE) continue;
|
|
302
|
+
const offset = addr(bits === 64 ? h + 8 : h + 4);
|
|
303
|
+
const size = addr(bits === 64 ? h + 32 : h + 16);
|
|
304
|
+
const id = notes(offset, size);
|
|
305
|
+
if (id) return { ...info, buildId: id };
|
|
306
|
+
}
|
|
307
|
+
return info;
|
|
308
|
+
}
|
|
309
|
+
var align4 = (n) => n + 3 & ~3;
|
|
310
|
+
function hex(bytes) {
|
|
311
|
+
let out = "";
|
|
312
|
+
for (const b of bytes) out += b.toString(16).padStart(2, "0");
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/files.ts
|
|
317
|
+
import { readdirSync, statSync as statSync2 } from "fs";
|
|
318
|
+
import { join as join2, relative, sep } from "path";
|
|
319
|
+
function walk(dir) {
|
|
320
|
+
const out = [];
|
|
321
|
+
const visit = (current) => {
|
|
322
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
323
|
+
const full = join2(current, entry.name);
|
|
324
|
+
if (entry.isDirectory()) {
|
|
325
|
+
if (entry.name !== "node_modules") visit(full);
|
|
326
|
+
} else if (entry.isFile()) out.push(full);
|
|
327
|
+
else if (entry.isSymbolicLink()) {
|
|
328
|
+
try {
|
|
329
|
+
if (statSync2(full).isFile()) out.push(full);
|
|
330
|
+
} catch {
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
visit(dir);
|
|
336
|
+
return out.sort();
|
|
337
|
+
}
|
|
338
|
+
function relativePath(dir, path) {
|
|
339
|
+
return relative(dir, path).split(sep).join("/");
|
|
340
|
+
}
|
|
341
|
+
function globToRegExp(glob) {
|
|
342
|
+
let out = "";
|
|
343
|
+
for (let i = 0; i < glob.length; i++) {
|
|
344
|
+
const c = glob[i];
|
|
345
|
+
if (c === "*") {
|
|
346
|
+
if (glob[i + 1] === "*") {
|
|
347
|
+
const slash = glob[i + 2] === "/";
|
|
348
|
+
out += slash ? "(?:.*/)?" : ".*";
|
|
349
|
+
i += slash ? 2 : 1;
|
|
350
|
+
} else out += "[^/]*";
|
|
351
|
+
} else if (c === "?") out += "[^/]";
|
|
352
|
+
else out += /[.+^${}()|[\]\\]/.test(c) ? `\\${c}` : c;
|
|
353
|
+
}
|
|
354
|
+
return new RegExp(glob.includes("/") ? `^${out}$` : `(?:^|/)${out}$`);
|
|
355
|
+
}
|
|
356
|
+
function toList(pattern) {
|
|
357
|
+
if (pattern === void 0) return [];
|
|
358
|
+
return (Array.isArray(pattern) ? pattern : [pattern]).map((p) => typeof p === "string" ? globToRegExp(p) : p);
|
|
359
|
+
}
|
|
360
|
+
function pathFilter(include, exclude) {
|
|
361
|
+
const inc = toList(include);
|
|
362
|
+
const exc = toList(exclude);
|
|
363
|
+
return (path) => (inc.length === 0 || inc.some((r) => r.test(path))) && !exc.some((r) => r.test(path));
|
|
364
|
+
}
|
|
365
|
+
function formatBytes(bytes) {
|
|
366
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
367
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} kB`;
|
|
368
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/log.ts
|
|
372
|
+
var consoleLogger = (prefix = "[zharp]") => ({
|
|
373
|
+
info: (message) => console.log(`${prefix} ${message}`),
|
|
374
|
+
warn: (message) => console.warn(`${prefix} ${message}`)
|
|
375
|
+
});
|
|
376
|
+
var silentLogger = { info() {
|
|
377
|
+
}, warn() {
|
|
378
|
+
} };
|
|
379
|
+
|
|
380
|
+
// src/macho.ts
|
|
381
|
+
var LC_UUID = 27;
|
|
382
|
+
var MH_MAGIC = 4277009102;
|
|
383
|
+
var MH_MAGIC_64 = 4277009103;
|
|
384
|
+
var FAT_MAGIC = 3405691582;
|
|
385
|
+
var FAT_MAGIC_64 = 3405691583;
|
|
386
|
+
function isMachO(data) {
|
|
387
|
+
if (data.length < 8) return false;
|
|
388
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
389
|
+
const be = view.getUint32(0, false);
|
|
390
|
+
const le = view.getUint32(0, true);
|
|
391
|
+
return be === FAT_MAGIC || be === FAT_MAGIC_64 || [MH_MAGIC, MH_MAGIC_64].includes(le) || [MH_MAGIC, MH_MAGIC_64].includes(be);
|
|
392
|
+
}
|
|
393
|
+
function archName(cpuType, cpuSubtype) {
|
|
394
|
+
const sub = cpuSubtype & 16777215;
|
|
395
|
+
switch (cpuType) {
|
|
396
|
+
case 16777228:
|
|
397
|
+
return sub === 2 ? "arm64e" : "arm64";
|
|
398
|
+
case 33554444:
|
|
399
|
+
return "arm64_32";
|
|
400
|
+
case 12:
|
|
401
|
+
return sub === 9 ? "armv7" : sub === 11 ? "armv7s" : sub === 12 ? "armv7k" : "arm";
|
|
402
|
+
case 16777223:
|
|
403
|
+
return sub === 8 ? "x86_64h" : "x86_64";
|
|
404
|
+
case 7:
|
|
405
|
+
return "i386";
|
|
406
|
+
default:
|
|
407
|
+
return `cpu${cpuType}`;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function readMachO(data) {
|
|
411
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
412
|
+
const magic = view.getUint32(0, false);
|
|
413
|
+
if (magic === FAT_MAGIC || magic === FAT_MAGIC_64) {
|
|
414
|
+
const wide = magic === FAT_MAGIC_64;
|
|
415
|
+
const count = view.getUint32(4, false);
|
|
416
|
+
const images = [];
|
|
417
|
+
for (let i = 0; i < count; i++) {
|
|
418
|
+
const h = 8 + i * (wide ? 32 : 20);
|
|
419
|
+
const offset = wide ? Number(view.getBigUint64(h + 8, false)) : view.getUint32(h + 8, false);
|
|
420
|
+
const size = wide ? Number(view.getBigUint64(h + 16, false)) : view.getUint32(h + 12, false);
|
|
421
|
+
images.push(...readThin(data.subarray(offset, offset + size)).map((image) => ({ ...image, offset })));
|
|
422
|
+
}
|
|
423
|
+
return images;
|
|
424
|
+
}
|
|
425
|
+
return readThin(data);
|
|
426
|
+
}
|
|
427
|
+
function readThin(data) {
|
|
428
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
429
|
+
let little;
|
|
430
|
+
if ([MH_MAGIC, MH_MAGIC_64].includes(view.getUint32(0, true))) little = true;
|
|
431
|
+
else if ([MH_MAGIC, MH_MAGIC_64].includes(view.getUint32(0, false))) little = false;
|
|
432
|
+
else throw new Error("not a Mach-O file");
|
|
433
|
+
const wide = view.getUint32(0, little) === MH_MAGIC_64;
|
|
434
|
+
const cpuType = view.getUint32(4, little);
|
|
435
|
+
const cpuSubtype = view.getUint32(8, little);
|
|
436
|
+
const ncmds = view.getUint32(16, little);
|
|
437
|
+
let p = wide ? 32 : 28;
|
|
438
|
+
for (let i = 0; i < ncmds && p + 8 <= data.length; i++) {
|
|
439
|
+
const cmd = view.getUint32(p, little);
|
|
440
|
+
const size = view.getUint32(p + 4, little);
|
|
441
|
+
if (cmd === LC_UUID && p + 24 <= data.length) {
|
|
442
|
+
return [{ uuid: formatUuid(data.subarray(p + 8, p + 24)), arch: archName(cpuType, cpuSubtype), offset: 0, size: data.length }];
|
|
443
|
+
}
|
|
444
|
+
if (size < 8) break;
|
|
445
|
+
p += size;
|
|
446
|
+
}
|
|
447
|
+
return [];
|
|
448
|
+
}
|
|
449
|
+
function formatUuid(bytes) {
|
|
450
|
+
let hex2 = "";
|
|
451
|
+
for (const b of bytes) hex2 += b.toString(16).padStart(2, "0");
|
|
452
|
+
hex2 = hex2.toUpperCase();
|
|
453
|
+
return `${hex2.slice(0, 8)}-${hex2.slice(8, 12)}-${hex2.slice(12, 16)}-${hex2.slice(16, 20)}-${hex2.slice(20)}`;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/native.ts
|
|
457
|
+
import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync3 } from "fs";
|
|
458
|
+
import { basename, dirname as dirname2, join as join3, resolve as resolve2 } from "path";
|
|
459
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
460
|
+
async function send(connection, artifacts, options) {
|
|
461
|
+
const logger = options.logger ?? consoleLogger();
|
|
462
|
+
let done = 0;
|
|
463
|
+
await eachLimit(artifacts, 2, async (artifact) => {
|
|
464
|
+
if (!options.dryRun) {
|
|
465
|
+
if (!connection) throw new Error("No connection to upload to.");
|
|
466
|
+
await uploadArtifact(connection, artifact, { fetch: options.fetch, retries: options.retries });
|
|
467
|
+
}
|
|
468
|
+
done += 1;
|
|
469
|
+
const extra = artifact.arch ? ` ${artifact.arch}` : "";
|
|
470
|
+
logger.info(` [${done}/${artifacts.length}] ${options.dryRun ? "would upload" : "uploaded"} ${artifact.kind} ${artifact.name}${extra} (${formatBytes(artifact.data.length)}) ${artifact.debugId}`);
|
|
471
|
+
});
|
|
472
|
+
return artifacts;
|
|
473
|
+
}
|
|
474
|
+
async function uploadProguard(mappingFile, uuid, connection, options = {}) {
|
|
475
|
+
if (!UUID.test(uuid)) throw new Error(`--uuid must be a UUID, got "${uuid}".`);
|
|
476
|
+
const data = readFileSync2(mappingFile);
|
|
477
|
+
return send(connection, [{ kind: "proguard", debugId: uuid.toLowerCase(), name: basename(mappingFile), release: options.release, data, gzip: true }], options);
|
|
478
|
+
}
|
|
479
|
+
var DART_ARCH = { x86_64: "x64", x86: "ia32" };
|
|
480
|
+
function findDartSymbols(path, logger = consoleLogger()) {
|
|
481
|
+
const files = statSync3(path).isDirectory() ? walk(resolve2(path)) : [resolve2(path)];
|
|
482
|
+
const out = [];
|
|
483
|
+
for (const file of files) {
|
|
484
|
+
const named = /\.symbols$/.test(file);
|
|
485
|
+
const data = readFileSync2(file);
|
|
486
|
+
if (!isElf(data)) {
|
|
487
|
+
if (named) logger.warn(`Skipped ${basename(file)}: not an ELF file.`);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const elf = readElf(data);
|
|
491
|
+
if (!elf.buildId) {
|
|
492
|
+
logger.warn(`Skipped ${basename(file)}: it has no GNU build ID.`);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const match = /\.([a-z]+)-([a-z0-9_]+)\.symbols$/.exec(basename(file));
|
|
496
|
+
out.push({ path: file, buildId: elf.buildId, os: match?.[1], arch: match?.[2] ?? (elf.arch && (DART_ARCH[elf.arch] ?? elf.arch)) });
|
|
497
|
+
}
|
|
498
|
+
return out;
|
|
499
|
+
}
|
|
500
|
+
function findObfuscationMap(symbolsPath) {
|
|
501
|
+
const dir = statSync3(symbolsPath).isDirectory() ? resolve2(symbolsPath) : dirname2(resolve2(symbolsPath));
|
|
502
|
+
for (const where of [dir, dirname2(dir)]) {
|
|
503
|
+
let names;
|
|
504
|
+
try {
|
|
505
|
+
names = readdirSync2(where).sort();
|
|
506
|
+
} catch {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const found = names.find((n) => n === "obfuscation.json") ?? names.find((n) => n.endsWith(".obfuscation.json"));
|
|
510
|
+
if (found && statSync3(join3(where, found)).isFile()) return join3(where, found);
|
|
511
|
+
}
|
|
512
|
+
return void 0;
|
|
513
|
+
}
|
|
514
|
+
function readObfuscationMap(file) {
|
|
515
|
+
const data = readFileSync2(file);
|
|
516
|
+
let parsed;
|
|
517
|
+
try {
|
|
518
|
+
parsed = JSON.parse(data.toString("utf8"));
|
|
519
|
+
} catch (error) {
|
|
520
|
+
throw new Error(`${file} is not valid JSON (${error.message}).`);
|
|
521
|
+
}
|
|
522
|
+
if (!Array.isArray(parsed)) throw new Error(`${file} is not a Dart obfuscation map: expected a JSON array of [obfuscated, original] names.`);
|
|
523
|
+
return data;
|
|
524
|
+
}
|
|
525
|
+
async function uploadDartSymbols(path, connection, options = {}) {
|
|
526
|
+
const logger = options.logger ?? consoleLogger();
|
|
527
|
+
const files = findDartSymbols(path, logger);
|
|
528
|
+
if (files.length === 0) throw new Error(`No Dart symbol files in ${path} \u2014 build with \`flutter build \u2026 --obfuscate --split-debug-info=<dir>\` and pass that directory.`);
|
|
529
|
+
logger.info(`${options.dryRun ? "Would upload" : "Uploading"} ${files.length} Dart symbol file(s)`);
|
|
530
|
+
const artifacts = files.map((f) => ({
|
|
531
|
+
kind: "dart-symbols",
|
|
532
|
+
debugId: f.buildId,
|
|
533
|
+
name: basename(f.path),
|
|
534
|
+
arch: f.arch,
|
|
535
|
+
release: options.release,
|
|
536
|
+
data: readFileSync2(f.path),
|
|
537
|
+
gzip: true
|
|
538
|
+
}));
|
|
539
|
+
if (options.obfuscationMap && !existsSync2(options.obfuscationMap)) throw new Error(`${options.obfuscationMap} does not exist.`);
|
|
540
|
+
const mapFile = options.obfuscationMap ?? findObfuscationMap(path);
|
|
541
|
+
if (mapFile) {
|
|
542
|
+
const data = readObfuscationMap(mapFile);
|
|
543
|
+
const buildIds = [...new Set(files.map((f) => f.buildId))];
|
|
544
|
+
logger.info(`With obfuscation map ${basename(mapFile)} for ${buildIds.length} build ID(s)`);
|
|
545
|
+
for (const debugId of buildIds) {
|
|
546
|
+
artifacts.push({ kind: "dart-obfuscation-map", debugId, name: basename(mapFile), release: options.release, data, gzip: true });
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
logger.info("No obfuscation map found (build with --extra-gen-snapshot-options=--save-obfuscation-map=build/obfuscation.json, or pass --obfuscation-map): obfuscated names in error messages stay as they are.");
|
|
550
|
+
}
|
|
551
|
+
return send(connection, artifacts, options);
|
|
552
|
+
}
|
|
553
|
+
function findDsymImages(path) {
|
|
554
|
+
const root = resolve2(path);
|
|
555
|
+
const candidates = statSync3(root).isDirectory() ? walk(root).filter((f) => /[\\/]Contents[\\/]Resources[\\/]DWARF[\\/][^\\/]+$/.test(f)) : [root];
|
|
556
|
+
const out = [];
|
|
557
|
+
for (const file of candidates) {
|
|
558
|
+
const data = readFileSync2(file);
|
|
559
|
+
if (!isMachO(data)) continue;
|
|
560
|
+
for (const image of readMachO(data)) out.push({ path: file, ...image });
|
|
561
|
+
}
|
|
562
|
+
return out;
|
|
563
|
+
}
|
|
564
|
+
async function uploadDsyms(path, connection, options = {}) {
|
|
565
|
+
const logger = options.logger ?? consoleLogger();
|
|
566
|
+
const images = findDsymImages(path);
|
|
567
|
+
if (images.length === 0) throw new Error(`No dSYM DWARF files in ${path} \u2014 pass a .dSYM bundle or the folder that holds them ($DWARF_DSYM_FOLDER_PATH).`);
|
|
568
|
+
logger.info(`${options.dryRun ? "Would upload" : "Uploading"} ${images.length} dSYM image(s)`);
|
|
569
|
+
const cache = /* @__PURE__ */ new Map();
|
|
570
|
+
const artifacts = images.map((image) => {
|
|
571
|
+
let data = cache.get(image.path);
|
|
572
|
+
if (!data) cache.set(image.path, data = readFileSync2(image.path));
|
|
573
|
+
return {
|
|
574
|
+
kind: "dsym",
|
|
575
|
+
debugId: image.uuid,
|
|
576
|
+
name: basename(image.path),
|
|
577
|
+
arch: image.arch,
|
|
578
|
+
release: options.release,
|
|
579
|
+
// One architecture's slice of a universal file is a complete Mach-O file on its own.
|
|
580
|
+
data: data.subarray(image.offset, image.offset + image.size),
|
|
581
|
+
gzip: true
|
|
582
|
+
};
|
|
583
|
+
});
|
|
584
|
+
return send(connection, artifacts, options);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/sourcemaps.ts
|
|
588
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, unlinkSync, writeFileSync } from "fs";
|
|
589
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
590
|
+
var JS_FILE = /\.(?:js|mjs|cjs)$/;
|
|
591
|
+
function mapFor(file, code) {
|
|
592
|
+
const sibling = `${file}.map`;
|
|
593
|
+
if (existsSync3(sibling)) return sibling;
|
|
594
|
+
const url = sourceMappingUrl(code ?? readFileSync3(file, "utf8"));
|
|
595
|
+
if (!url || /^[a-z][a-z0-9+.-]*:/i.test(url)) return void 0;
|
|
596
|
+
let path;
|
|
597
|
+
try {
|
|
598
|
+
path = decodeURIComponent(url.split(/[?#]/)[0]);
|
|
599
|
+
} catch {
|
|
600
|
+
return void 0;
|
|
601
|
+
}
|
|
602
|
+
const full = isAbsolute2(path) ? path : resolve3(dirname3(file), path);
|
|
603
|
+
return existsSync3(full) ? full : void 0;
|
|
604
|
+
}
|
|
605
|
+
function findSourceFiles(dir, options = {}) {
|
|
606
|
+
const root = resolve3(dir);
|
|
607
|
+
const keep = pathFilter(options.include, options.exclude);
|
|
608
|
+
const candidates = options.files ? options.files.map((f) => resolve3(f)) : walk(root);
|
|
609
|
+
const out = [];
|
|
610
|
+
for (const file of candidates) {
|
|
611
|
+
if (!JS_FILE.test(file) || !existsSync3(file)) continue;
|
|
612
|
+
const name = relativePath(root, file);
|
|
613
|
+
if (!keep(name)) continue;
|
|
614
|
+
const map = mapFor(file);
|
|
615
|
+
if (map) out.push({ file, map, name, mapName: relativePath(root, map) });
|
|
616
|
+
}
|
|
617
|
+
return out;
|
|
618
|
+
}
|
|
619
|
+
function injectDirectory(dir, options = {}) {
|
|
620
|
+
const logger = options.logger ?? consoleLogger();
|
|
621
|
+
const files = findSourceFiles(dir, options);
|
|
622
|
+
const out = [];
|
|
623
|
+
const noSourcesContent = [];
|
|
624
|
+
for (const source of files) {
|
|
625
|
+
const code = readFileSync3(source.file, "utf8");
|
|
626
|
+
const injected = injectCode(code, { stripSourceMappingUrl: options.stripSourceMappingUrl });
|
|
627
|
+
let map;
|
|
628
|
+
try {
|
|
629
|
+
map = injectMap(readFileSync3(source.map, "utf8"), injected.debugId, source.map);
|
|
630
|
+
} catch (error) {
|
|
631
|
+
logger.warn(`Skipped ${source.name}: ${source.mapName} is not a readable source map (${error.message}).`);
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (!options.dryRun) {
|
|
635
|
+
if (injected.changed) writeFileSync(source.file, injected.code);
|
|
636
|
+
if (map.changed) writeFileSync(source.map, map.text);
|
|
637
|
+
}
|
|
638
|
+
if (!map.hasSourcesContent) noSourcesContent.push(source.mapName);
|
|
639
|
+
const changed = injected.changed || map.changed;
|
|
640
|
+
out.push({ ...source, debugId: injected.debugId, changed });
|
|
641
|
+
logger.info(`${changed ? options.dryRun ? "would inject" : "injected" : "already has"} ${injected.debugId} ${source.name}`);
|
|
642
|
+
}
|
|
643
|
+
if (noSourcesContent.length) {
|
|
644
|
+
logger.warn(
|
|
645
|
+
`${noSourcesContent.length} source map(s) have no sourcesContent, so Zharp can show original names and lines but not the code around them: ${noSourcesContent.slice(0, 3).join(", ")}${noSourcesContent.length > 3 ? ", \u2026" : ""}`
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
if (out.length === 0) logger.warn(`No JavaScript files with source maps found in ${dir}.`);
|
|
649
|
+
return out;
|
|
650
|
+
}
|
|
651
|
+
async function uploadSourcemaps(dir, connection, options = {}) {
|
|
652
|
+
const logger = options.logger ?? consoleLogger();
|
|
653
|
+
const files = findSourceFiles(dir, options);
|
|
654
|
+
const result = { files: 0, artifacts: 0, bytes: 0, deleted: [], skipped: [] };
|
|
655
|
+
const work = [];
|
|
656
|
+
for (const source of files) {
|
|
657
|
+
const code = readFileSync3(source.file);
|
|
658
|
+
const debugId = existingDebugId(code.toString("utf8"));
|
|
659
|
+
if (!debugId) {
|
|
660
|
+
result.skipped.push(source.name);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
work.push({ source, debugId, code, map: readFileSync3(source.map) });
|
|
664
|
+
}
|
|
665
|
+
if (result.skipped.length) {
|
|
666
|
+
logger.warn(`${result.skipped.length} file(s) have a source map but no debug ID \u2014 run \`zharp sourcemaps inject\` first: ${result.skipped.slice(0, 3).join(", ")}${result.skipped.length > 3 ? ", \u2026" : ""}`);
|
|
667
|
+
}
|
|
668
|
+
if (work.length === 0) {
|
|
669
|
+
logger.warn(`Nothing to upload in ${dir}.`);
|
|
670
|
+
return result;
|
|
671
|
+
}
|
|
672
|
+
const total = work.length;
|
|
673
|
+
logger.info(`${options.dryRun ? "Would upload" : "Uploading"} ${total} file(s) and their source maps${options.release ? ` for release ${options.release}` : ""}${connection ? ` to ${connection.url}, app ${connection.app}` : ""}`);
|
|
674
|
+
let done = 0;
|
|
675
|
+
await eachLimit(work, options.concurrency ?? 4, async ({ source, debugId, code, map }) => {
|
|
676
|
+
const size = code.length + map.length;
|
|
677
|
+
if (!options.dryRun) {
|
|
678
|
+
if (!connection) throw new Error("No connection to upload to.");
|
|
679
|
+
const common = { debugId, release: options.release };
|
|
680
|
+
const opts = { fetch: options.fetch, retries: options.retries };
|
|
681
|
+
await uploadArtifact(connection, { ...common, kind: "minified-source", name: source.name, data: code }, opts);
|
|
682
|
+
await uploadArtifact(connection, { ...common, kind: "sourcemap", name: source.mapName, data: map }, opts);
|
|
683
|
+
}
|
|
684
|
+
done += 1;
|
|
685
|
+
result.files += 1;
|
|
686
|
+
result.artifacts += 2;
|
|
687
|
+
result.bytes += size;
|
|
688
|
+
logger.info(` [${done}/${total}] ${options.dryRun ? "would upload" : "uploaded"} ${source.name} + ${source.mapName} (${formatBytes(size)}) ${debugId}`);
|
|
689
|
+
});
|
|
690
|
+
if (options.deleteAfter && !options.dryRun) {
|
|
691
|
+
result.deleted = deleteSourcemaps(work.map((w) => w.source), { stripSourceMappingUrl: options.stripSourceMappingUrl });
|
|
692
|
+
logger.info(`Deleted ${result.deleted.length} source map(s) from the output.`);
|
|
693
|
+
}
|
|
694
|
+
logger.info(`${options.dryRun ? "Dry run: would have uploaded" : "Uploaded"} ${result.artifacts} artifact(s), ${formatBytes(result.bytes)}.`);
|
|
695
|
+
return result;
|
|
696
|
+
}
|
|
697
|
+
function deleteSourcemaps(files, options = {}) {
|
|
698
|
+
const deleted = [];
|
|
699
|
+
for (const source of files) {
|
|
700
|
+
if (options.stripSourceMappingUrl && existsSync3(source.file)) {
|
|
701
|
+
const code = readFileSync3(source.file, "utf8");
|
|
702
|
+
const stripped = withoutSourceMappingUrl(code);
|
|
703
|
+
if (stripped !== code) writeFileSync(source.file, stripped);
|
|
704
|
+
}
|
|
705
|
+
if (existsSync3(source.map)) {
|
|
706
|
+
unlinkSync(source.map);
|
|
707
|
+
deleted.push(source.mapName);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return deleted;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/version.ts
|
|
714
|
+
var VERSION = "0.2.0";
|
|
715
|
+
|
|
716
|
+
// src/build.ts
|
|
717
|
+
function defaultRelease(options) {
|
|
718
|
+
const env = process.env;
|
|
719
|
+
return options.release || env.ZHARP_RELEASE || env.VERCEL_GIT_COMMIT_SHA || env.GITHUB_SHA || env.CI_COMMIT_SHA || env.CF_PAGES_COMMIT_SHA || env.COMMIT_REF || env.RENDER_GIT_COMMIT || void 0;
|
|
720
|
+
}
|
|
721
|
+
function pluginLogger(name, options) {
|
|
722
|
+
const base = consoleLogger(`[${name}]`);
|
|
723
|
+
return options.silent ? { info: silentLogger.info, warn: base.warn } : base;
|
|
724
|
+
}
|
|
725
|
+
async function processBuildOutput(dir, options, context = {}) {
|
|
726
|
+
const logger = context.logger ?? pluginLogger("zharp", options);
|
|
727
|
+
const result = { injected: [], uploaded: false, deleted: [] };
|
|
728
|
+
if (options.disabled) return result;
|
|
729
|
+
result.injected = injectDirectory(dir, { files: context.files, include: options.include, exclude: options.exclude, dryRun: false, logger: quiet(logger) });
|
|
730
|
+
if (result.injected.length === 0) return result;
|
|
731
|
+
logger.info(`Injected debug IDs into ${result.injected.length} file(s) in ${dir}`);
|
|
732
|
+
const release = defaultRelease(options);
|
|
733
|
+
if (options.dryRun) {
|
|
734
|
+
await uploadSourcemaps(dir, null, { files: result.injected.map((f) => f.file), release, dryRun: true, logger });
|
|
735
|
+
return result;
|
|
736
|
+
}
|
|
737
|
+
try {
|
|
738
|
+
const connection = resolveConnection(options);
|
|
739
|
+
await uploadSourcemaps(dir, connection, { files: result.injected.map((f) => f.file), release, logger });
|
|
740
|
+
result.uploaded = true;
|
|
741
|
+
} catch (error) {
|
|
742
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
743
|
+
if (options.failOnError) throw error;
|
|
744
|
+
logger.warn(`Source maps were not uploaded: ${message}${error instanceof UploadError && error.permanent ? "" : " Errors from this build will show minified stacks."}`);
|
|
745
|
+
}
|
|
746
|
+
if (options.deleteSourcemapsAfterUpload !== false) {
|
|
747
|
+
result.deleted = deleteSourcemaps(result.injected, { stripSourceMappingUrl: true });
|
|
748
|
+
logger.info(`Deleted ${result.deleted.length} source map(s) from the output.`);
|
|
749
|
+
}
|
|
750
|
+
return result;
|
|
751
|
+
}
|
|
752
|
+
function quiet(logger) {
|
|
753
|
+
return { info() {
|
|
754
|
+
}, warn: (m) => logger.warn(m) };
|
|
755
|
+
}
|
|
756
|
+
export {
|
|
757
|
+
DEBUG_ID_COMMENT,
|
|
758
|
+
DEFAULT_URL,
|
|
759
|
+
UploadError,
|
|
760
|
+
VERSION,
|
|
761
|
+
artifactsUrl,
|
|
762
|
+
consoleLogger,
|
|
763
|
+
debugIdFromContent,
|
|
764
|
+
defaultRelease,
|
|
765
|
+
deleteSourcemaps,
|
|
766
|
+
existingDebugId,
|
|
767
|
+
findDartSymbols,
|
|
768
|
+
findDsymImages,
|
|
769
|
+
findObfuscationMap,
|
|
770
|
+
findSourceFiles,
|
|
771
|
+
globToRegExp,
|
|
772
|
+
injectCode,
|
|
773
|
+
injectDirectory,
|
|
774
|
+
injectMap,
|
|
775
|
+
mapFor,
|
|
776
|
+
pathFilter,
|
|
777
|
+
pluginLogger,
|
|
778
|
+
processBuildOutput,
|
|
779
|
+
readElf,
|
|
780
|
+
readMachO,
|
|
781
|
+
registrationSnippet,
|
|
782
|
+
resolveConnection,
|
|
783
|
+
silentLogger,
|
|
784
|
+
uploadArtifact,
|
|
785
|
+
uploadDartSymbols,
|
|
786
|
+
uploadDsyms,
|
|
787
|
+
uploadProguard,
|
|
788
|
+
uploadSourcemaps,
|
|
789
|
+
withoutSourceMappingUrl
|
|
790
|
+
};
|
|
791
|
+
//# sourceMappingURL=index.mjs.map
|