bugstack-sdk 2.1.0 → 2.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/CHANGELOG.md +87 -0
- package/README.md +75 -0
- package/bin/bugstack.cjs +6 -0
- package/dist/adapters/express/index.d.mts +2 -2
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/express/index.mjs +1 -1
- package/dist/adapters/generic/index.d.mts +2 -2
- package/dist/adapters/generic/index.d.ts +2 -2
- package/dist/adapters/generic/index.js +1 -1
- package/dist/adapters/generic/index.mjs +1 -1
- package/dist/adapters/nextjs/index.d.mts +2 -2
- package/dist/adapters/nextjs/index.d.ts +2 -2
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/nextjs/index.mjs +1 -1
- package/dist/build/cli.d.mts +2 -0
- package/dist/build/cli.d.ts +2 -0
- package/dist/build/cli.js +256 -0
- package/dist/build/cli.js.map +1 -0
- package/dist/build/cli.mjs +254 -0
- package/dist/build/cli.mjs.map +1 -0
- package/dist/build/upload.d.mts +82 -0
- package/dist/build/upload.d.ts +82 -0
- package/dist/build/upload.js +163 -0
- package/dist/build/upload.js.map +1 -0
- package/dist/build/upload.mjs +161 -0
- package/dist/build/upload.mjs.map +1 -0
- package/dist/{client-BVW9UrBu.d.mts → client-DoqE7sNh.d.mts} +1 -1
- package/dist/{client-BVW9UrBu.d.ts → client-DoqE7sNh.d.ts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/next-config/index.d.mts +56 -0
- package/dist/next-config/index.d.ts +56 -0
- package/dist/next-config/index.js +28 -0
- package/dist/next-config/index.js.map +1 -0
- package/dist/next-config/index.mjs +23 -0
- package/dist/next-config/index.mjs.map +1 -0
- package/package.json +17 -2
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { parseArgs } from 'util';
|
|
2
|
+
import { readdir, stat, readFile } from 'fs/promises';
|
|
3
|
+
import { join, relative, sep } from 'path';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
|
|
6
|
+
// src/build/cli.ts
|
|
7
|
+
var DEFAULT_SERVER_DIR = ".next/server";
|
|
8
|
+
var DEFAULT_CONCURRENCY = 6;
|
|
9
|
+
var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
var ENDPOINT_PATH = "/api/sourcemaps/upload";
|
|
11
|
+
function resolveRelease(explicit) {
|
|
12
|
+
if (explicit !== void 0) return explicit;
|
|
13
|
+
const fromEnv = process.env.BUGSTACK_RELEASE || process.env.RENDER_GIT_COMMIT || process.env.VERCEL_GIT_COMMIT_SHA || process.env.GITHUB_SHA;
|
|
14
|
+
if (fromEnv) return fromEnv;
|
|
15
|
+
try {
|
|
16
|
+
return execSync("git rev-parse HEAD", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function resolveEndpoint(explicit) {
|
|
22
|
+
const base = explicit || process.env.BUGSTACK_ENDPOINT || (process.env.ERROR_SERVICE_URL ? process.env.ERROR_SERVICE_URL : null);
|
|
23
|
+
if (!base) return null;
|
|
24
|
+
const normalised = base.replace(/\/+$/, "").replace(/\/api\/capture$/, "").replace(/\/capture$/, "");
|
|
25
|
+
return normalised + ENDPOINT_PATH;
|
|
26
|
+
}
|
|
27
|
+
async function walk(dir) {
|
|
28
|
+
let entries;
|
|
29
|
+
try {
|
|
30
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err.code === "ENOENT") return [];
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
const path = join(dir, entry.name);
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
out.push(...await walk(path));
|
|
40
|
+
} else if (entry.name.endsWith(".map")) {
|
|
41
|
+
out.push(path);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
async function pool(items, workers, fn) {
|
|
47
|
+
const results = new Array(items.length);
|
|
48
|
+
let i = 0;
|
|
49
|
+
const runners = Array.from({ length: Math.min(workers, items.length) }, async () => {
|
|
50
|
+
while (i < items.length) {
|
|
51
|
+
const idx = i++;
|
|
52
|
+
results[idx] = await fn(items[idx]);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
await Promise.all(runners);
|
|
56
|
+
return results;
|
|
57
|
+
}
|
|
58
|
+
function bundleFileFor(mapPath, serverDir) {
|
|
59
|
+
return relative(serverDir, mapPath).replace(/\.map$/, "").split(sep).join("/");
|
|
60
|
+
}
|
|
61
|
+
async function uploadSourceMaps(options = {}) {
|
|
62
|
+
const apiKey = options.apiKey || process.env.BUGSTACK_PROJECT_API_KEY || process.env.BUGSTACK_API_KEY;
|
|
63
|
+
const endpoint = resolveEndpoint(options.endpoint);
|
|
64
|
+
const release = resolveRelease(options.release);
|
|
65
|
+
const serverDir = options.serverDir || DEFAULT_SERVER_DIR;
|
|
66
|
+
const concurrency = Math.max(1, options.concurrency ?? DEFAULT_CONCURRENCY);
|
|
67
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
68
|
+
const log = options.log || ((m) => console.log(m));
|
|
69
|
+
const warn = options.warn || ((m) => console.warn(m));
|
|
70
|
+
if (!apiKey) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"uploadSourceMaps: missing project API key. Set BUGSTACK_PROJECT_API_KEY or pass {apiKey} explicitly."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (!endpoint) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"uploadSourceMaps: missing endpoint. Set BUGSTACK_ENDPOINT (or ERROR_SERVICE_URL) or pass {endpoint} explicitly."
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const start = Date.now();
|
|
81
|
+
const mapFiles = await walk(serverDir);
|
|
82
|
+
if (mapFiles.length === 0) {
|
|
83
|
+
log(
|
|
84
|
+
`[bugstack] No .map files found under ${serverDir}. Make sure withBugstack() is wrapping your next.config or that source-map emission is otherwise enabled.`
|
|
85
|
+
);
|
|
86
|
+
return { uploaded: 0, skipped: 0, failed: 0, totalBytes: 0, elapsedMs: 0, failures: [] };
|
|
87
|
+
}
|
|
88
|
+
log(
|
|
89
|
+
`[bugstack] Uploading ${mapFiles.length} source map(s) to ${endpoint} (release=${release || "none"})...`
|
|
90
|
+
);
|
|
91
|
+
const results = await pool(mapFiles, concurrency, async (mapPath) => {
|
|
92
|
+
const bundleFile = bundleFileFor(mapPath, serverDir);
|
|
93
|
+
const stats = await stat(mapPath);
|
|
94
|
+
if (stats.size > maxBytes) {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
bundleFile,
|
|
98
|
+
bytes: 0,
|
|
99
|
+
skipped: true,
|
|
100
|
+
error: `Skipped \u2014 ${(stats.size / 1024 / 1024).toFixed(1)}MB exceeds maxBytes`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const mapJson = await readFile(mapPath, "utf8");
|
|
104
|
+
try {
|
|
105
|
+
const res = await fetch(endpoint, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
headers: {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
"X-BugStack-API-Key": apiKey
|
|
110
|
+
},
|
|
111
|
+
body: JSON.stringify({ bundleFile, mapJson, release })
|
|
112
|
+
});
|
|
113
|
+
if (!res.ok) {
|
|
114
|
+
const text = await res.text().catch(() => "");
|
|
115
|
+
return {
|
|
116
|
+
ok: false,
|
|
117
|
+
bundleFile,
|
|
118
|
+
bytes: 0,
|
|
119
|
+
skipped: false,
|
|
120
|
+
error: `HTTP ${res.status} ${text.slice(0, 200)}`
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return { ok: true, bundleFile, bytes: stats.size, skipped: false };
|
|
124
|
+
} catch (err) {
|
|
125
|
+
return {
|
|
126
|
+
ok: false,
|
|
127
|
+
bundleFile,
|
|
128
|
+
bytes: 0,
|
|
129
|
+
skipped: false,
|
|
130
|
+
error: err instanceof Error ? err.message : String(err)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const uploaded = results.filter((r) => r.ok).length;
|
|
135
|
+
const skipped = results.filter((r) => !r.ok && r.skipped).length;
|
|
136
|
+
const failed = results.length - uploaded - skipped;
|
|
137
|
+
const totalBytes = results.reduce((n, r) => n + (r.ok ? r.bytes : 0), 0);
|
|
138
|
+
const failures = results.filter((r) => !r.ok && !r.skipped).map((r) => ({ bundleFile: r.bundleFile, error: r.error }));
|
|
139
|
+
const elapsedMs = Date.now() - start;
|
|
140
|
+
log(
|
|
141
|
+
`[bugstack] Uploaded ${uploaded}/${results.length} maps (${(totalBytes / 1024 / 1024).toFixed(
|
|
142
|
+
1
|
|
143
|
+
)}MB) in ${(elapsedMs / 1e3).toFixed(1)}s.`
|
|
144
|
+
);
|
|
145
|
+
if (skipped > 0) {
|
|
146
|
+
warn(`[bugstack] Skipped ${skipped} map(s) over the size cap.`);
|
|
147
|
+
}
|
|
148
|
+
if (failures.length > 0) {
|
|
149
|
+
warn(`[bugstack] ${failures.length} upload(s) failed:`);
|
|
150
|
+
for (const f of failures.slice(0, 10)) {
|
|
151
|
+
warn(` - ${f.bundleFile}: ${f.error}`);
|
|
152
|
+
}
|
|
153
|
+
if (failures.length > 10) {
|
|
154
|
+
warn(` \u2026and ${failures.length - 10} more`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { uploaded, skipped, failed, totalBytes, elapsedMs, failures };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/build/cli.ts
|
|
161
|
+
function printHelp() {
|
|
162
|
+
console.log(`bugstack \u2014 source-map upload + maintenance CLI
|
|
163
|
+
|
|
164
|
+
USAGE
|
|
165
|
+
bugstack sourcemaps upload [options]
|
|
166
|
+
bugstack --help
|
|
167
|
+
|
|
168
|
+
OPTIONS (sourcemaps upload)
|
|
169
|
+
--api-key <key> Project SDK key. Default: BUGSTACK_PROJECT_API_KEY env.
|
|
170
|
+
--endpoint <url> Base URL of the bugstack ingest service. Default:
|
|
171
|
+
BUGSTACK_ENDPOINT env, or ERROR_SERVICE_URL.
|
|
172
|
+
--release <id> Release identifier (commit SHA / version). Default:
|
|
173
|
+
BUGSTACK_RELEASE env, RENDER_GIT_COMMIT,
|
|
174
|
+
VERCEL_GIT_COMMIT_SHA, GITHUB_SHA, or git rev-parse HEAD.
|
|
175
|
+
--server-dir <path> Directory to walk for .map files. Default: .next/server.
|
|
176
|
+
--concurrency <n> Max concurrent uploads. Default: 6.
|
|
177
|
+
--max-bytes <n> Per-file size cap in bytes. Default: 8388608 (8 MiB).
|
|
178
|
+
--quiet Suppress info logs (warnings still printed).
|
|
179
|
+
|
|
180
|
+
EXIT CODES
|
|
181
|
+
0 Always \u2014 upload failures are reported but never fail the build by
|
|
182
|
+
design. Source maps are an optimisation, not a release gate.
|
|
183
|
+
`);
|
|
184
|
+
}
|
|
185
|
+
async function runSourceMapsUpload(argv) {
|
|
186
|
+
let parsed;
|
|
187
|
+
try {
|
|
188
|
+
parsed = parseArgs({
|
|
189
|
+
args: argv,
|
|
190
|
+
options: {
|
|
191
|
+
"api-key": { type: "string" },
|
|
192
|
+
endpoint: { type: "string" },
|
|
193
|
+
release: { type: "string" },
|
|
194
|
+
"server-dir": { type: "string" },
|
|
195
|
+
concurrency: { type: "string" },
|
|
196
|
+
"max-bytes": { type: "string" },
|
|
197
|
+
quiet: { type: "boolean", default: false },
|
|
198
|
+
help: { type: "boolean", short: "h", default: false }
|
|
199
|
+
},
|
|
200
|
+
strict: true
|
|
201
|
+
});
|
|
202
|
+
} catch (err) {
|
|
203
|
+
console.error(`bugstack: ${err.message}`);
|
|
204
|
+
return 2;
|
|
205
|
+
}
|
|
206
|
+
if (parsed.values.help) {
|
|
207
|
+
printHelp();
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
const opts = {
|
|
211
|
+
apiKey: parsed.values["api-key"],
|
|
212
|
+
endpoint: parsed.values.endpoint,
|
|
213
|
+
release: parsed.values.release,
|
|
214
|
+
serverDir: parsed.values["server-dir"],
|
|
215
|
+
concurrency: parsed.values.concurrency ? Number(parsed.values.concurrency) : void 0,
|
|
216
|
+
maxBytes: parsed.values["max-bytes"] ? Number(parsed.values["max-bytes"]) : void 0
|
|
217
|
+
};
|
|
218
|
+
if (parsed.values.quiet) {
|
|
219
|
+
opts.log = () => {
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
await uploadSourceMaps(opts);
|
|
224
|
+
return 0;
|
|
225
|
+
} catch (err) {
|
|
226
|
+
console.warn(
|
|
227
|
+
`[bugstack] Skipping source-map upload: ${err instanceof Error ? err.message : String(err)}`
|
|
228
|
+
);
|
|
229
|
+
console.warn(`[bugstack] (This is a soft skip \u2014 your build will still succeed.)`);
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function main() {
|
|
234
|
+
const [, , command, subcommand, ...rest] = process.argv;
|
|
235
|
+
if (!command || command === "--help" || command === "-h" || command === "help") {
|
|
236
|
+
printHelp();
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
if (command === "sourcemaps" && subcommand === "upload") {
|
|
240
|
+
return runSourceMapsUpload(rest);
|
|
241
|
+
}
|
|
242
|
+
console.error(`bugstack: unknown command "${[command, subcommand].filter(Boolean).join(" ")}"`);
|
|
243
|
+
printHelp();
|
|
244
|
+
return 2;
|
|
245
|
+
}
|
|
246
|
+
main().then(
|
|
247
|
+
(code) => process.exit(code),
|
|
248
|
+
(err) => {
|
|
249
|
+
console.error(`bugstack: unexpected error \u2014 ${err instanceof Error ? err.stack : err}`);
|
|
250
|
+
process.exit(1);
|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,CAAA;AAAA,EACT;AACF;AAEA,eAAe,IAAA,GAAwB;AACrC,EAAA,MAAM,KAAK,OAAA,EAAS,YAAY,GAAG,IAAI,IAAI,OAAA,CAAQ,IAAA;AAEnD,EAAA,IAAI,CAAC,OAAA,IAAW,OAAA,KAAY,YAAY,OAAA,KAAY,IAAA,IAAQ,YAAY,MAAA,EAAQ;AAC9E,IAAA,SAAA,EAAU;AACV,IAAA,OAAO,CAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAA,KAAY,YAAA,IAAgB,UAAA,KAAe,QAAA,EAAU;AACvD,IAAA,OAAO,oBAAoB,IAAI,CAAA;AAAA,EACjC;AAEA,EAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,2BAAA,EAA8B,CAAC,OAAA,EAAS,UAAU,CAAA,CAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAG,CAAA;AAC9F,EAAA,SAAA,EAAU;AACV,EAAA,OAAO,CAAA;AACT;AAEA,IAAA,EAAK,CAAE,IAAA;AAAA,EACL,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA;AAAA,EAC3B,CAAC,GAAA,KAAQ;AACP,IAAA,OAAA,CAAQ,MAAM,CAAA,kCAAA,EAAgC,GAAA,YAAe,QAAQ,GAAA,CAAI,KAAA,GAAQ,GAAG,CAAA,CAAE,CAAA;AACtF,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAA","file":"cli.mjs","sourcesContent":["/**\r\n * Build-time source map uploader.\r\n *\r\n * Walks a directory of compiled output looking for `.map` files and POSTs\r\n * each one to the bugstack source-map ingest endpoint. The companion\r\n * `bugstack-sdk/next-config` wrapper enables emission of these maps for\r\n * Next.js server bundles; once uploaded, the orchestrator can resolve\r\n * production stack frames like \".next/server/chunks/8393.js:1:8734\" back\r\n * to source-file positions (\"app/api/orders/route.ts:42:5\") and actually\r\n * generate fixes for bundled errors.\r\n *\r\n * This module is import-safe in any Node 18+ environment. It uses no\r\n * runtime dependencies — `node:fs/promises` + global `fetch`.\r\n */\r\n\r\nimport { readdir, readFile, stat } from \"node:fs/promises\";\r\nimport { join, relative, sep } from \"node:path\";\r\nimport { execSync } from \"node:child_process\";\r\n\r\nexport interface UploadSourceMapsOptions {\r\n /**\r\n * Project SDK key. Required. Reads BUGSTACK_PROJECT_API_KEY or\r\n * BUGSTACK_API_KEY when not supplied explicitly.\r\n */\r\n apiKey?: string;\r\n\r\n /**\r\n * Base URL of the bugstack ingest service. Reads BUGSTACK_ENDPOINT or\r\n * derives from ERROR_SERVICE_URL when not supplied. The uploader appends\r\n * `/api/sourcemaps/upload` to whatever base it gets.\r\n */\r\n endpoint?: string;\r\n\r\n /**\r\n * Release identifier (typically a commit SHA). Lets multiple deploys\r\n * coexist in the source-map table so old errors still resolve against\r\n * old maps. Auto-detected in this order:\r\n * 1. BUGSTACK_RELEASE\r\n * 2. RENDER_GIT_COMMIT\r\n * 3. VERCEL_GIT_COMMIT_SHA\r\n * 4. GITHUB_SHA\r\n * 5. `git rev-parse HEAD` (when a git checkout is present)\r\n */\r\n release?: string | null;\r\n\r\n /**\r\n * Directory to walk for `.map` files. Defaults to `.next/server`.\r\n * Override for non-Next projects (e.g. `dist` for tsc, `build` for CRA).\r\n */\r\n serverDir?: string;\r\n\r\n /**\r\n * Max concurrent uploads. Higher means faster builds, more pressure on\r\n * the ingest endpoint. Default 6 — tuned for Render's typical bandwidth.\r\n */\r\n concurrency?: number;\r\n\r\n /**\r\n * Per-file size cap in bytes. Maps larger than this are skipped with a\r\n * warning rather than failing. Default 8 MiB — covers typical\r\n * `.next/server/chunks/*.js.map` outputs comfortably.\r\n */\r\n maxBytes?: number;\r\n\r\n /**\r\n * Logger. Defaults to console. Pass a no-op logger to silence the\r\n * \"[bugstack] …\" lines in scripted environments.\r\n */\r\n log?: (message: string) => void;\r\n warn?: (message: string) => void;\r\n}\r\n\r\nexport interface UploadResult {\r\n uploaded: number;\r\n skipped: number;\r\n failed: number;\r\n totalBytes: number;\r\n elapsedMs: number;\r\n failures: Array<{ bundleFile: string; error: string }>;\r\n}\r\n\r\nconst DEFAULT_SERVER_DIR = \".next/server\";\r\nconst DEFAULT_CONCURRENCY = 6;\r\nconst DEFAULT_MAX_BYTES = 8 * 1024 * 1024;\r\nconst ENDPOINT_PATH = \"/api/sourcemaps/upload\";\r\n\r\nfunction resolveRelease(explicit?: string | null): string | null {\r\n if (explicit !== undefined) return explicit;\r\n const fromEnv =\r\n process.env.BUGSTACK_RELEASE ||\r\n process.env.RENDER_GIT_COMMIT ||\r\n process.env.VERCEL_GIT_COMMIT_SHA ||\r\n process.env.GITHUB_SHA;\r\n if (fromEnv) return fromEnv;\r\n try {\r\n return execSync(\"git rev-parse HEAD\", { stdio: [\"ignore\", \"pipe\", \"ignore\"] })\r\n .toString()\r\n .trim();\r\n } catch {\r\n return null;\r\n }\r\n}\r\n\r\nfunction resolveEndpoint(explicit?: string): string | null {\r\n const base =\r\n explicit ||\r\n process.env.BUGSTACK_ENDPOINT ||\r\n (process.env.ERROR_SERVICE_URL ? process.env.ERROR_SERVICE_URL : null);\r\n if (!base) return null;\r\n // Strip trailing slashes + any trailing /api/capture or /capture so the\r\n // same env var that points the SDK at ingestion also works for sourcemaps.\r\n const normalised = base\r\n .replace(/\\/+$/, \"\")\r\n .replace(/\\/api\\/capture$/, \"\")\r\n .replace(/\\/capture$/, \"\");\r\n return normalised + ENDPOINT_PATH;\r\n}\r\n\r\nasync function walk(dir: string): Promise<string[]> {\r\n let entries;\r\n try {\r\n entries = await readdir(dir, { withFileTypes: true });\r\n } catch (err) {\r\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\r\n throw err;\r\n }\r\n const out: string[] = [];\r\n for (const entry of entries) {\r\n const path = join(dir, entry.name);\r\n if (entry.isDirectory()) {\r\n out.push(...(await walk(path)));\r\n } else if (entry.name.endsWith(\".map\")) {\r\n out.push(path);\r\n }\r\n }\r\n return out;\r\n}\r\n\r\nasync function pool<T, R>(\r\n items: T[],\r\n workers: number,\r\n fn: (item: T) => Promise<R>,\r\n): Promise<R[]> {\r\n const results: R[] = new Array(items.length);\r\n let i = 0;\r\n const runners = Array.from({ length: Math.min(workers, items.length) }, async () => {\r\n while (i < items.length) {\r\n const idx = i++;\r\n results[idx] = await fn(items[idx]);\r\n }\r\n });\r\n await Promise.all(runners);\r\n return results;\r\n}\r\n\r\nfunction bundleFileFor(mapPath: string, serverDir: string): string {\r\n // Strip the serverDir prefix and the .map suffix; normalise Windows\r\n // backslashes so the bundleFile key stored on the server is portable\r\n // regardless of where the build ran.\r\n return relative(serverDir, mapPath)\r\n .replace(/\\.map$/, \"\")\r\n .split(sep)\r\n .join(\"/\");\r\n}\r\n\r\n/**\r\n * Upload every `.map` file under `serverDir` to the bugstack source-map\r\n * endpoint. Tolerant: never throws on individual file failures, returns\r\n * a summary the caller can decide what to do with.\r\n *\r\n * Throws only on hard configuration errors (no API key, no resolvable\r\n * endpoint, serverDir totally missing).\r\n */\r\nexport async function uploadSourceMaps(\r\n options: UploadSourceMapsOptions = {},\r\n): Promise<UploadResult> {\r\n const apiKey =\r\n options.apiKey ||\r\n process.env.BUGSTACK_PROJECT_API_KEY ||\r\n process.env.BUGSTACK_API_KEY;\r\n const endpoint = resolveEndpoint(options.endpoint);\r\n const release = resolveRelease(options.release);\r\n const serverDir = options.serverDir || DEFAULT_SERVER_DIR;\r\n const concurrency = Math.max(1, options.concurrency ?? DEFAULT_CONCURRENCY);\r\n const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\r\n const log = options.log || ((m: string) => console.log(m));\r\n const warn = options.warn || ((m: string) => console.warn(m));\r\n\r\n if (!apiKey) {\r\n throw new Error(\r\n \"uploadSourceMaps: missing project API key. Set BUGSTACK_PROJECT_API_KEY or pass {apiKey} explicitly.\",\r\n );\r\n }\r\n if (!endpoint) {\r\n throw new Error(\r\n \"uploadSourceMaps: missing endpoint. Set BUGSTACK_ENDPOINT (or ERROR_SERVICE_URL) or pass {endpoint} explicitly.\",\r\n );\r\n }\r\n\r\n const start = Date.now();\r\n const mapFiles = await walk(serverDir);\r\n\r\n if (mapFiles.length === 0) {\r\n log(\r\n `[bugstack] No .map files found under ${serverDir}. Make sure withBugstack() is wrapping your next.config or that source-map emission is otherwise enabled.`,\r\n );\r\n return { uploaded: 0, skipped: 0, failed: 0, totalBytes: 0, elapsedMs: 0, failures: [] };\r\n }\r\n\r\n log(\r\n `[bugstack] Uploading ${mapFiles.length} source map(s) to ${endpoint} (release=${release || \"none\"})...`,\r\n );\r\n\r\n const results = await pool(mapFiles, concurrency, async (mapPath) => {\r\n const bundleFile = bundleFileFor(mapPath, serverDir);\r\n const stats = await stat(mapPath);\r\n if (stats.size > maxBytes) {\r\n return {\r\n ok: false as const,\r\n bundleFile,\r\n bytes: 0,\r\n skipped: true,\r\n error: `Skipped — ${(stats.size / 1024 / 1024).toFixed(1)}MB exceeds maxBytes`,\r\n };\r\n }\r\n const mapJson = await readFile(mapPath, \"utf8\");\r\n try {\r\n const res = await fetch(endpoint, {\r\n method: \"POST\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"X-BugStack-API-Key\": apiKey,\r\n },\r\n body: JSON.stringify({ bundleFile, mapJson, release }),\r\n });\r\n if (!res.ok) {\r\n const text = await res.text().catch(() => \"\");\r\n return {\r\n ok: false as const,\r\n bundleFile,\r\n bytes: 0,\r\n skipped: false,\r\n error: `HTTP ${res.status} ${text.slice(0, 200)}`,\r\n };\r\n }\r\n return { ok: true as const, bundleFile, bytes: stats.size, skipped: false };\r\n } catch (err) {\r\n return {\r\n ok: false as const,\r\n bundleFile,\r\n bytes: 0,\r\n skipped: false,\r\n error: err instanceof Error ? err.message : String(err),\r\n };\r\n }\r\n });\r\n\r\n const uploaded = results.filter((r) => r.ok).length;\r\n const skipped = results.filter((r) => !r.ok && r.skipped).length;\r\n const failed = results.length - uploaded - skipped;\r\n const totalBytes = results.reduce((n, r) => n + (r.ok ? r.bytes : 0), 0);\r\n const failures = results\r\n .filter((r): r is Extract<typeof r, { ok: false }> => !r.ok && !r.skipped)\r\n .map((r) => ({ bundleFile: r.bundleFile, error: r.error }));\r\n const elapsedMs = Date.now() - start;\r\n\r\n log(\r\n `[bugstack] Uploaded ${uploaded}/${results.length} maps (${(totalBytes / 1024 / 1024).toFixed(\r\n 1,\r\n )}MB) in ${(elapsedMs / 1000).toFixed(1)}s.`,\r\n );\r\n if (skipped > 0) {\r\n warn(`[bugstack] Skipped ${skipped} map(s) over the size cap.`);\r\n }\r\n if (failures.length > 0) {\r\n warn(`[bugstack] ${failures.length} upload(s) failed:`);\r\n for (const f of failures.slice(0, 10)) {\r\n warn(` - ${f.bundleFile}: ${f.error}`);\r\n }\r\n if (failures.length > 10) {\r\n warn(` …and ${failures.length - 10} more`);\r\n }\r\n }\r\n\r\n return { uploaded, skipped, failed, totalBytes, elapsedMs, failures };\r\n}\r\n","/**\r\n * `bugstack` CLI entry point.\r\n *\r\n * One command for now — `bugstack sourcemaps upload` — but the dispatch\r\n * is structured so additional subcommands can land without a breaking\r\n * change. Reads config from flags first, env vars second; everything has\r\n * a sensible default so the typical CI invocation is just:\r\n *\r\n * bugstack sourcemaps upload\r\n */\r\n\r\nimport { parseArgs } from \"node:util\";\r\nimport { uploadSourceMaps, type UploadSourceMapsOptions } from \"./upload\";\r\n\r\nfunction printHelp(): void {\r\n console.log(`bugstack — source-map upload + maintenance CLI\r\n\r\nUSAGE\r\n bugstack sourcemaps upload [options]\r\n bugstack --help\r\n\r\nOPTIONS (sourcemaps upload)\r\n --api-key <key> Project SDK key. Default: BUGSTACK_PROJECT_API_KEY env.\r\n --endpoint <url> Base URL of the bugstack ingest service. Default:\r\n BUGSTACK_ENDPOINT env, or ERROR_SERVICE_URL.\r\n --release <id> Release identifier (commit SHA / version). Default:\r\n BUGSTACK_RELEASE env, RENDER_GIT_COMMIT,\r\n VERCEL_GIT_COMMIT_SHA, GITHUB_SHA, or git rev-parse HEAD.\r\n --server-dir <path> Directory to walk for .map files. Default: .next/server.\r\n --concurrency <n> Max concurrent uploads. Default: 6.\r\n --max-bytes <n> Per-file size cap in bytes. Default: 8388608 (8 MiB).\r\n --quiet Suppress info logs (warnings still printed).\r\n\r\nEXIT CODES\r\n 0 Always — upload failures are reported but never fail the build by\r\n design. Source maps are an optimisation, not a release gate.\r\n`);\r\n}\r\n\r\nasync function runSourceMapsUpload(argv: string[]): Promise<number> {\r\n let parsed;\r\n try {\r\n parsed = parseArgs({\r\n args: argv,\r\n options: {\r\n \"api-key\": { type: \"string\" },\r\n endpoint: { type: \"string\" },\r\n release: { type: \"string\" },\r\n \"server-dir\": { type: \"string\" },\r\n concurrency: { type: \"string\" },\r\n \"max-bytes\": { type: \"string\" },\r\n quiet: { type: \"boolean\", default: false },\r\n help: { type: \"boolean\", short: \"h\", default: false },\r\n },\r\n strict: true,\r\n });\r\n } catch (err) {\r\n console.error(`bugstack: ${(err as Error).message}`);\r\n return 2;\r\n }\r\n\r\n if (parsed.values.help) {\r\n printHelp();\r\n return 0;\r\n }\r\n\r\n const opts: UploadSourceMapsOptions = {\r\n apiKey: parsed.values[\"api-key\"],\r\n endpoint: parsed.values.endpoint,\r\n release: parsed.values.release,\r\n serverDir: parsed.values[\"server-dir\"],\r\n concurrency: parsed.values.concurrency ? Number(parsed.values.concurrency) : undefined,\r\n maxBytes: parsed.values[\"max-bytes\"] ? Number(parsed.values[\"max-bytes\"]) : undefined,\r\n };\r\n if (parsed.values.quiet) {\r\n opts.log = () => {};\r\n }\r\n\r\n try {\r\n await uploadSourceMaps(opts);\r\n return 0;\r\n } catch (err) {\r\n // Distinguish hard config errors (missing key, bad endpoint) from per-\r\n // file failures: only the former should surface as a non-zero exit.\r\n // Per-file failures stay inside uploadSourceMaps and resolve with a\r\n // logged summary.\r\n console.warn(\r\n `[bugstack] Skipping source-map upload: ${err instanceof Error ? err.message : String(err)}`,\r\n );\r\n console.warn(`[bugstack] (This is a soft skip — your build will still succeed.)`);\r\n return 0;\r\n }\r\n}\r\n\r\nasync function main(): Promise<number> {\r\n const [, , command, subcommand, ...rest] = process.argv;\r\n\r\n if (!command || command === \"--help\" || command === \"-h\" || command === \"help\") {\r\n printHelp();\r\n return 0;\r\n }\r\n\r\n if (command === \"sourcemaps\" && subcommand === \"upload\") {\r\n return runSourceMapsUpload(rest);\r\n }\r\n\r\n console.error(`bugstack: unknown command \"${[command, subcommand].filter(Boolean).join(\" \")}\"`);\r\n printHelp();\r\n return 2;\r\n}\r\n\r\nmain().then(\r\n (code) => process.exit(code),\r\n (err) => {\r\n console.error(`bugstack: unexpected error — ${err instanceof Error ? err.stack : err}`);\r\n process.exit(1);\r\n },\r\n);\r\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time source map uploader.
|
|
3
|
+
*
|
|
4
|
+
* Walks a directory of compiled output looking for `.map` files and POSTs
|
|
5
|
+
* each one to the bugstack source-map ingest endpoint. The companion
|
|
6
|
+
* `bugstack-sdk/next-config` wrapper enables emission of these maps for
|
|
7
|
+
* Next.js server bundles; once uploaded, the orchestrator can resolve
|
|
8
|
+
* production stack frames like ".next/server/chunks/8393.js:1:8734" back
|
|
9
|
+
* to source-file positions ("app/api/orders/route.ts:42:5") and actually
|
|
10
|
+
* generate fixes for bundled errors.
|
|
11
|
+
*
|
|
12
|
+
* This module is import-safe in any Node 18+ environment. It uses no
|
|
13
|
+
* runtime dependencies — `node:fs/promises` + global `fetch`.
|
|
14
|
+
*/
|
|
15
|
+
interface UploadSourceMapsOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Project SDK key. Required. Reads BUGSTACK_PROJECT_API_KEY or
|
|
18
|
+
* BUGSTACK_API_KEY when not supplied explicitly.
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Base URL of the bugstack ingest service. Reads BUGSTACK_ENDPOINT or
|
|
23
|
+
* derives from ERROR_SERVICE_URL when not supplied. The uploader appends
|
|
24
|
+
* `/api/sourcemaps/upload` to whatever base it gets.
|
|
25
|
+
*/
|
|
26
|
+
endpoint?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Release identifier (typically a commit SHA). Lets multiple deploys
|
|
29
|
+
* coexist in the source-map table so old errors still resolve against
|
|
30
|
+
* old maps. Auto-detected in this order:
|
|
31
|
+
* 1. BUGSTACK_RELEASE
|
|
32
|
+
* 2. RENDER_GIT_COMMIT
|
|
33
|
+
* 3. VERCEL_GIT_COMMIT_SHA
|
|
34
|
+
* 4. GITHUB_SHA
|
|
35
|
+
* 5. `git rev-parse HEAD` (when a git checkout is present)
|
|
36
|
+
*/
|
|
37
|
+
release?: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Directory to walk for `.map` files. Defaults to `.next/server`.
|
|
40
|
+
* Override for non-Next projects (e.g. `dist` for tsc, `build` for CRA).
|
|
41
|
+
*/
|
|
42
|
+
serverDir?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Max concurrent uploads. Higher means faster builds, more pressure on
|
|
45
|
+
* the ingest endpoint. Default 6 — tuned for Render's typical bandwidth.
|
|
46
|
+
*/
|
|
47
|
+
concurrency?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Per-file size cap in bytes. Maps larger than this are skipped with a
|
|
50
|
+
* warning rather than failing. Default 8 MiB — covers typical
|
|
51
|
+
* `.next/server/chunks/*.js.map` outputs comfortably.
|
|
52
|
+
*/
|
|
53
|
+
maxBytes?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Logger. Defaults to console. Pass a no-op logger to silence the
|
|
56
|
+
* "[bugstack] …" lines in scripted environments.
|
|
57
|
+
*/
|
|
58
|
+
log?: (message: string) => void;
|
|
59
|
+
warn?: (message: string) => void;
|
|
60
|
+
}
|
|
61
|
+
interface UploadResult {
|
|
62
|
+
uploaded: number;
|
|
63
|
+
skipped: number;
|
|
64
|
+
failed: number;
|
|
65
|
+
totalBytes: number;
|
|
66
|
+
elapsedMs: number;
|
|
67
|
+
failures: Array<{
|
|
68
|
+
bundleFile: string;
|
|
69
|
+
error: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Upload every `.map` file under `serverDir` to the bugstack source-map
|
|
74
|
+
* endpoint. Tolerant: never throws on individual file failures, returns
|
|
75
|
+
* a summary the caller can decide what to do with.
|
|
76
|
+
*
|
|
77
|
+
* Throws only on hard configuration errors (no API key, no resolvable
|
|
78
|
+
* endpoint, serverDir totally missing).
|
|
79
|
+
*/
|
|
80
|
+
declare function uploadSourceMaps(options?: UploadSourceMapsOptions): Promise<UploadResult>;
|
|
81
|
+
|
|
82
|
+
export { type UploadResult, type UploadSourceMapsOptions, uploadSourceMaps };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time source map uploader.
|
|
3
|
+
*
|
|
4
|
+
* Walks a directory of compiled output looking for `.map` files and POSTs
|
|
5
|
+
* each one to the bugstack source-map ingest endpoint. The companion
|
|
6
|
+
* `bugstack-sdk/next-config` wrapper enables emission of these maps for
|
|
7
|
+
* Next.js server bundles; once uploaded, the orchestrator can resolve
|
|
8
|
+
* production stack frames like ".next/server/chunks/8393.js:1:8734" back
|
|
9
|
+
* to source-file positions ("app/api/orders/route.ts:42:5") and actually
|
|
10
|
+
* generate fixes for bundled errors.
|
|
11
|
+
*
|
|
12
|
+
* This module is import-safe in any Node 18+ environment. It uses no
|
|
13
|
+
* runtime dependencies — `node:fs/promises` + global `fetch`.
|
|
14
|
+
*/
|
|
15
|
+
interface UploadSourceMapsOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Project SDK key. Required. Reads BUGSTACK_PROJECT_API_KEY or
|
|
18
|
+
* BUGSTACK_API_KEY when not supplied explicitly.
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Base URL of the bugstack ingest service. Reads BUGSTACK_ENDPOINT or
|
|
23
|
+
* derives from ERROR_SERVICE_URL when not supplied. The uploader appends
|
|
24
|
+
* `/api/sourcemaps/upload` to whatever base it gets.
|
|
25
|
+
*/
|
|
26
|
+
endpoint?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Release identifier (typically a commit SHA). Lets multiple deploys
|
|
29
|
+
* coexist in the source-map table so old errors still resolve against
|
|
30
|
+
* old maps. Auto-detected in this order:
|
|
31
|
+
* 1. BUGSTACK_RELEASE
|
|
32
|
+
* 2. RENDER_GIT_COMMIT
|
|
33
|
+
* 3. VERCEL_GIT_COMMIT_SHA
|
|
34
|
+
* 4. GITHUB_SHA
|
|
35
|
+
* 5. `git rev-parse HEAD` (when a git checkout is present)
|
|
36
|
+
*/
|
|
37
|
+
release?: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Directory to walk for `.map` files. Defaults to `.next/server`.
|
|
40
|
+
* Override for non-Next projects (e.g. `dist` for tsc, `build` for CRA).
|
|
41
|
+
*/
|
|
42
|
+
serverDir?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Max concurrent uploads. Higher means faster builds, more pressure on
|
|
45
|
+
* the ingest endpoint. Default 6 — tuned for Render's typical bandwidth.
|
|
46
|
+
*/
|
|
47
|
+
concurrency?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Per-file size cap in bytes. Maps larger than this are skipped with a
|
|
50
|
+
* warning rather than failing. Default 8 MiB — covers typical
|
|
51
|
+
* `.next/server/chunks/*.js.map` outputs comfortably.
|
|
52
|
+
*/
|
|
53
|
+
maxBytes?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Logger. Defaults to console. Pass a no-op logger to silence the
|
|
56
|
+
* "[bugstack] …" lines in scripted environments.
|
|
57
|
+
*/
|
|
58
|
+
log?: (message: string) => void;
|
|
59
|
+
warn?: (message: string) => void;
|
|
60
|
+
}
|
|
61
|
+
interface UploadResult {
|
|
62
|
+
uploaded: number;
|
|
63
|
+
skipped: number;
|
|
64
|
+
failed: number;
|
|
65
|
+
totalBytes: number;
|
|
66
|
+
elapsedMs: number;
|
|
67
|
+
failures: Array<{
|
|
68
|
+
bundleFile: string;
|
|
69
|
+
error: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Upload every `.map` file under `serverDir` to the bugstack source-map
|
|
74
|
+
* endpoint. Tolerant: never throws on individual file failures, returns
|
|
75
|
+
* a summary the caller can decide what to do with.
|
|
76
|
+
*
|
|
77
|
+
* Throws only on hard configuration errors (no API key, no resolvable
|
|
78
|
+
* endpoint, serverDir totally missing).
|
|
79
|
+
*/
|
|
80
|
+
declare function uploadSourceMaps(options?: UploadSourceMapsOptions): Promise<UploadResult>;
|
|
81
|
+
|
|
82
|
+
export { type UploadResult, type UploadSourceMapsOptions, uploadSourceMaps };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('fs/promises');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var child_process = require('child_process');
|
|
6
|
+
|
|
7
|
+
// src/build/upload.ts
|
|
8
|
+
var DEFAULT_SERVER_DIR = ".next/server";
|
|
9
|
+
var DEFAULT_CONCURRENCY = 6;
|
|
10
|
+
var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
|
|
11
|
+
var ENDPOINT_PATH = "/api/sourcemaps/upload";
|
|
12
|
+
function resolveRelease(explicit) {
|
|
13
|
+
if (explicit !== void 0) return explicit;
|
|
14
|
+
const fromEnv = process.env.BUGSTACK_RELEASE || process.env.RENDER_GIT_COMMIT || process.env.VERCEL_GIT_COMMIT_SHA || process.env.GITHUB_SHA;
|
|
15
|
+
if (fromEnv) return fromEnv;
|
|
16
|
+
try {
|
|
17
|
+
return child_process.execSync("git rev-parse HEAD", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function resolveEndpoint(explicit) {
|
|
23
|
+
const base = explicit || process.env.BUGSTACK_ENDPOINT || (process.env.ERROR_SERVICE_URL ? process.env.ERROR_SERVICE_URL : null);
|
|
24
|
+
if (!base) return null;
|
|
25
|
+
const normalised = base.replace(/\/+$/, "").replace(/\/api\/capture$/, "").replace(/\/capture$/, "");
|
|
26
|
+
return normalised + ENDPOINT_PATH;
|
|
27
|
+
}
|
|
28
|
+
async function walk(dir) {
|
|
29
|
+
let entries;
|
|
30
|
+
try {
|
|
31
|
+
entries = await promises.readdir(dir, { withFileTypes: true });
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err.code === "ENOENT") return [];
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
const path$1 = path.join(dir, entry.name);
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
out.push(...await walk(path$1));
|
|
41
|
+
} else if (entry.name.endsWith(".map")) {
|
|
42
|
+
out.push(path$1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
async function pool(items, workers, fn) {
|
|
48
|
+
const results = new Array(items.length);
|
|
49
|
+
let i = 0;
|
|
50
|
+
const runners = Array.from({ length: Math.min(workers, items.length) }, async () => {
|
|
51
|
+
while (i < items.length) {
|
|
52
|
+
const idx = i++;
|
|
53
|
+
results[idx] = await fn(items[idx]);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
await Promise.all(runners);
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
function bundleFileFor(mapPath, serverDir) {
|
|
60
|
+
return path.relative(serverDir, mapPath).replace(/\.map$/, "").split(path.sep).join("/");
|
|
61
|
+
}
|
|
62
|
+
async function uploadSourceMaps(options = {}) {
|
|
63
|
+
const apiKey = options.apiKey || process.env.BUGSTACK_PROJECT_API_KEY || process.env.BUGSTACK_API_KEY;
|
|
64
|
+
const endpoint = resolveEndpoint(options.endpoint);
|
|
65
|
+
const release = resolveRelease(options.release);
|
|
66
|
+
const serverDir = options.serverDir || DEFAULT_SERVER_DIR;
|
|
67
|
+
const concurrency = Math.max(1, options.concurrency ?? DEFAULT_CONCURRENCY);
|
|
68
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
69
|
+
const log = options.log || ((m) => console.log(m));
|
|
70
|
+
const warn = options.warn || ((m) => console.warn(m));
|
|
71
|
+
if (!apiKey) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"uploadSourceMaps: missing project API key. Set BUGSTACK_PROJECT_API_KEY or pass {apiKey} explicitly."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (!endpoint) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"uploadSourceMaps: missing endpoint. Set BUGSTACK_ENDPOINT (or ERROR_SERVICE_URL) or pass {endpoint} explicitly."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const start = Date.now();
|
|
82
|
+
const mapFiles = await walk(serverDir);
|
|
83
|
+
if (mapFiles.length === 0) {
|
|
84
|
+
log(
|
|
85
|
+
`[bugstack] No .map files found under ${serverDir}. Make sure withBugstack() is wrapping your next.config or that source-map emission is otherwise enabled.`
|
|
86
|
+
);
|
|
87
|
+
return { uploaded: 0, skipped: 0, failed: 0, totalBytes: 0, elapsedMs: 0, failures: [] };
|
|
88
|
+
}
|
|
89
|
+
log(
|
|
90
|
+
`[bugstack] Uploading ${mapFiles.length} source map(s) to ${endpoint} (release=${release || "none"})...`
|
|
91
|
+
);
|
|
92
|
+
const results = await pool(mapFiles, concurrency, async (mapPath) => {
|
|
93
|
+
const bundleFile = bundleFileFor(mapPath, serverDir);
|
|
94
|
+
const stats = await promises.stat(mapPath);
|
|
95
|
+
if (stats.size > maxBytes) {
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
bundleFile,
|
|
99
|
+
bytes: 0,
|
|
100
|
+
skipped: true,
|
|
101
|
+
error: `Skipped \u2014 ${(stats.size / 1024 / 1024).toFixed(1)}MB exceeds maxBytes`
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const mapJson = await promises.readFile(mapPath, "utf8");
|
|
105
|
+
try {
|
|
106
|
+
const res = await fetch(endpoint, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: {
|
|
109
|
+
"Content-Type": "application/json",
|
|
110
|
+
"X-BugStack-API-Key": apiKey
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify({ bundleFile, mapJson, release })
|
|
113
|
+
});
|
|
114
|
+
if (!res.ok) {
|
|
115
|
+
const text = await res.text().catch(() => "");
|
|
116
|
+
return {
|
|
117
|
+
ok: false,
|
|
118
|
+
bundleFile,
|
|
119
|
+
bytes: 0,
|
|
120
|
+
skipped: false,
|
|
121
|
+
error: `HTTP ${res.status} ${text.slice(0, 200)}`
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return { ok: true, bundleFile, bytes: stats.size, skipped: false };
|
|
125
|
+
} catch (err) {
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
bundleFile,
|
|
129
|
+
bytes: 0,
|
|
130
|
+
skipped: false,
|
|
131
|
+
error: err instanceof Error ? err.message : String(err)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const uploaded = results.filter((r) => r.ok).length;
|
|
136
|
+
const skipped = results.filter((r) => !r.ok && r.skipped).length;
|
|
137
|
+
const failed = results.length - uploaded - skipped;
|
|
138
|
+
const totalBytes = results.reduce((n, r) => n + (r.ok ? r.bytes : 0), 0);
|
|
139
|
+
const failures = results.filter((r) => !r.ok && !r.skipped).map((r) => ({ bundleFile: r.bundleFile, error: r.error }));
|
|
140
|
+
const elapsedMs = Date.now() - start;
|
|
141
|
+
log(
|
|
142
|
+
`[bugstack] Uploaded ${uploaded}/${results.length} maps (${(totalBytes / 1024 / 1024).toFixed(
|
|
143
|
+
1
|
|
144
|
+
)}MB) in ${(elapsedMs / 1e3).toFixed(1)}s.`
|
|
145
|
+
);
|
|
146
|
+
if (skipped > 0) {
|
|
147
|
+
warn(`[bugstack] Skipped ${skipped} map(s) over the size cap.`);
|
|
148
|
+
}
|
|
149
|
+
if (failures.length > 0) {
|
|
150
|
+
warn(`[bugstack] ${failures.length} upload(s) failed:`);
|
|
151
|
+
for (const f of failures.slice(0, 10)) {
|
|
152
|
+
warn(` - ${f.bundleFile}: ${f.error}`);
|
|
153
|
+
}
|
|
154
|
+
if (failures.length > 10) {
|
|
155
|
+
warn(` \u2026and ${failures.length - 10} more`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { uploaded, skipped, failed, totalBytes, elapsedMs, failures };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
exports.uploadSourceMaps = uploadSourceMaps;
|
|
162
|
+
//# sourceMappingURL=upload.js.map
|
|
163
|
+
//# sourceMappingURL=upload.js.map
|