bugstack-sdk 2.1.0 → 2.2.1
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 +96 -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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/build/upload.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QAAA,CAAS,SAAS,EAAA,EAAI;AACxB,MAAA,IAAA,CAAK,CAAA,YAAA,EAAU,QAAA,CAAS,MAAA,GAAS,EAAE,CAAA,KAAA,CAAO,CAAA;AAAA,IAC5C;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,MAAA,EAAQ,UAAA,EAAY,WAAW,QAAA,EAAS;AACtE","file":"upload.js","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"]}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { readdir, stat, readFile } from 'fs/promises';
|
|
2
|
+
import { join, relative, sep } from 'path';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
|
|
5
|
+
// src/build/upload.ts
|
|
6
|
+
var DEFAULT_SERVER_DIR = ".next/server";
|
|
7
|
+
var DEFAULT_CONCURRENCY = 6;
|
|
8
|
+
var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
|
|
9
|
+
var ENDPOINT_PATH = "/api/sourcemaps/upload";
|
|
10
|
+
function resolveRelease(explicit) {
|
|
11
|
+
if (explicit !== void 0) return explicit;
|
|
12
|
+
const fromEnv = process.env.BUGSTACK_RELEASE || process.env.RENDER_GIT_COMMIT || process.env.VERCEL_GIT_COMMIT_SHA || process.env.GITHUB_SHA;
|
|
13
|
+
if (fromEnv) return fromEnv;
|
|
14
|
+
try {
|
|
15
|
+
return execSync("git rev-parse HEAD", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function resolveEndpoint(explicit) {
|
|
21
|
+
const base = explicit || process.env.BUGSTACK_ENDPOINT || (process.env.ERROR_SERVICE_URL ? process.env.ERROR_SERVICE_URL : null);
|
|
22
|
+
if (!base) return null;
|
|
23
|
+
const normalised = base.replace(/\/+$/, "").replace(/\/api\/capture$/, "").replace(/\/capture$/, "");
|
|
24
|
+
return normalised + ENDPOINT_PATH;
|
|
25
|
+
}
|
|
26
|
+
async function walk(dir) {
|
|
27
|
+
let entries;
|
|
28
|
+
try {
|
|
29
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
if (err.code === "ENOENT") return [];
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
const path = join(dir, entry.name);
|
|
37
|
+
if (entry.isDirectory()) {
|
|
38
|
+
out.push(...await walk(path));
|
|
39
|
+
} else if (entry.name.endsWith(".map")) {
|
|
40
|
+
out.push(path);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
async function pool(items, workers, fn) {
|
|
46
|
+
const results = new Array(items.length);
|
|
47
|
+
let i = 0;
|
|
48
|
+
const runners = Array.from({ length: Math.min(workers, items.length) }, async () => {
|
|
49
|
+
while (i < items.length) {
|
|
50
|
+
const idx = i++;
|
|
51
|
+
results[idx] = await fn(items[idx]);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
await Promise.all(runners);
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
function bundleFileFor(mapPath, serverDir) {
|
|
58
|
+
return relative(serverDir, mapPath).replace(/\.map$/, "").split(sep).join("/");
|
|
59
|
+
}
|
|
60
|
+
async function uploadSourceMaps(options = {}) {
|
|
61
|
+
const apiKey = options.apiKey || process.env.BUGSTACK_PROJECT_API_KEY || process.env.BUGSTACK_API_KEY;
|
|
62
|
+
const endpoint = resolveEndpoint(options.endpoint);
|
|
63
|
+
const release = resolveRelease(options.release);
|
|
64
|
+
const serverDir = options.serverDir || DEFAULT_SERVER_DIR;
|
|
65
|
+
const concurrency = Math.max(1, options.concurrency ?? DEFAULT_CONCURRENCY);
|
|
66
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
67
|
+
const log = options.log || ((m) => console.log(m));
|
|
68
|
+
const warn = options.warn || ((m) => console.warn(m));
|
|
69
|
+
if (!apiKey) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"uploadSourceMaps: missing project API key. Set BUGSTACK_PROJECT_API_KEY or pass {apiKey} explicitly."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (!endpoint) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"uploadSourceMaps: missing endpoint. Set BUGSTACK_ENDPOINT (or ERROR_SERVICE_URL) or pass {endpoint} explicitly."
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const start = Date.now();
|
|
80
|
+
const mapFiles = await walk(serverDir);
|
|
81
|
+
if (mapFiles.length === 0) {
|
|
82
|
+
log(
|
|
83
|
+
`[bugstack] No .map files found under ${serverDir}. Make sure withBugstack() is wrapping your next.config or that source-map emission is otherwise enabled.`
|
|
84
|
+
);
|
|
85
|
+
return { uploaded: 0, skipped: 0, failed: 0, totalBytes: 0, elapsedMs: 0, failures: [] };
|
|
86
|
+
}
|
|
87
|
+
log(
|
|
88
|
+
`[bugstack] Uploading ${mapFiles.length} source map(s) to ${endpoint} (release=${release || "none"})...`
|
|
89
|
+
);
|
|
90
|
+
const results = await pool(mapFiles, concurrency, async (mapPath) => {
|
|
91
|
+
const bundleFile = bundleFileFor(mapPath, serverDir);
|
|
92
|
+
const stats = await stat(mapPath);
|
|
93
|
+
if (stats.size > maxBytes) {
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
bundleFile,
|
|
97
|
+
bytes: 0,
|
|
98
|
+
skipped: true,
|
|
99
|
+
error: `Skipped \u2014 ${(stats.size / 1024 / 1024).toFixed(1)}MB exceeds maxBytes`
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const mapJson = await readFile(mapPath, "utf8");
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetch(endpoint, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: {
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
"X-BugStack-API-Key": apiKey
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({ bundleFile, mapJson, release })
|
|
111
|
+
});
|
|
112
|
+
if (!res.ok) {
|
|
113
|
+
const text = await res.text().catch(() => "");
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
bundleFile,
|
|
117
|
+
bytes: 0,
|
|
118
|
+
skipped: false,
|
|
119
|
+
error: `HTTP ${res.status} ${text.slice(0, 200)}`
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, bundleFile, bytes: stats.size, skipped: false };
|
|
123
|
+
} catch (err) {
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
bundleFile,
|
|
127
|
+
bytes: 0,
|
|
128
|
+
skipped: false,
|
|
129
|
+
error: err instanceof Error ? err.message : String(err)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const uploaded = results.filter((r) => r.ok).length;
|
|
134
|
+
const skipped = results.filter((r) => !r.ok && r.skipped).length;
|
|
135
|
+
const failed = results.length - uploaded - skipped;
|
|
136
|
+
const totalBytes = results.reduce((n, r) => n + (r.ok ? r.bytes : 0), 0);
|
|
137
|
+
const failures = results.filter((r) => !r.ok && !r.skipped).map((r) => ({ bundleFile: r.bundleFile, error: r.error }));
|
|
138
|
+
const elapsedMs = Date.now() - start;
|
|
139
|
+
log(
|
|
140
|
+
`[bugstack] Uploaded ${uploaded}/${results.length} maps (${(totalBytes / 1024 / 1024).toFixed(
|
|
141
|
+
1
|
|
142
|
+
)}MB) in ${(elapsedMs / 1e3).toFixed(1)}s.`
|
|
143
|
+
);
|
|
144
|
+
if (skipped > 0) {
|
|
145
|
+
warn(`[bugstack] Skipped ${skipped} map(s) over the size cap.`);
|
|
146
|
+
}
|
|
147
|
+
if (failures.length > 0) {
|
|
148
|
+
warn(`[bugstack] ${failures.length} upload(s) failed:`);
|
|
149
|
+
for (const f of failures.slice(0, 10)) {
|
|
150
|
+
warn(` - ${f.bundleFile}: ${f.error}`);
|
|
151
|
+
}
|
|
152
|
+
if (failures.length > 10) {
|
|
153
|
+
warn(` \u2026and ${failures.length - 10} more`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { uploaded, skipped, failed, totalBytes, elapsedMs, failures };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { uploadSourceMaps };
|
|
160
|
+
//# sourceMappingURL=upload.mjs.map
|
|
161
|
+
//# sourceMappingURL=upload.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/build/upload.ts"],"names":[],"mappings":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,EAAU,QAAA,CAAS,MAAA,GAAS,EAAE,CAAA,KAAA,CAAO,CAAA;AAAA,IAC5C;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,MAAA,EAAQ,UAAA,EAAY,WAAW,QAAA,EAAS;AACtE","file":"upload.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"]}
|
|
@@ -660,4 +660,4 @@ declare function isChunkLoadError(error: {
|
|
|
660
660
|
message?: string;
|
|
661
661
|
}): boolean;
|
|
662
662
|
|
|
663
|
-
export { BugStackClient as B, type CapturedError as C,
|
|
663
|
+
export { BugStackClient as B, type CapturedError as C, type ErrorCaptureConfig as E, type NextRouteHandler as N, type RouteContext as R, type StackFrame as S, ErrorCaptureClient as a, type RouteOptions as b, type BugStackConfig as c, ErrorDeduplicator as d, type ErrorReportPayload as e, type ResolvedConfig as f, RetryQueue as g, type SourceContext as h, isChunkLoadError as i };
|
|
@@ -660,4 +660,4 @@ declare function isChunkLoadError(error: {
|
|
|
660
660
|
message?: string;
|
|
661
661
|
}): boolean;
|
|
662
662
|
|
|
663
|
-
export { BugStackClient as B, type CapturedError as C,
|
|
663
|
+
export { BugStackClient as B, type CapturedError as C, type ErrorCaptureConfig as E, type NextRouteHandler as N, type RouteContext as R, type StackFrame as S, ErrorCaptureClient as a, type RouteOptions as b, type BugStackConfig as c, ErrorDeduplicator as d, type ErrorReportPayload as e, type ResolvedConfig as f, RetryQueue as g, type SourceContext as h, isChunkLoadError as i };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CapturedError,
|
|
2
|
-
export { B as BugStackClient,
|
|
1
|
+
import { C as CapturedError, a as ErrorCaptureClient, S as StackFrame } from './client-DoqE7sNh.mjs';
|
|
2
|
+
export { B as BugStackClient, c as BugStackConfig, E as ErrorCaptureConfig, d as ErrorDeduplicator, e as ErrorReportPayload, N as NextRouteHandler, f as ResolvedConfig, g as RetryQueue, R as RouteContext, b as RouteOptions, h as SourceContext, i as isChunkLoadError } from './client-DoqE7sNh.mjs';
|
|
3
3
|
export { withBugStack, withErrorCapture } from './adapters/nextjs/index.mjs';
|
|
4
4
|
import 'next/server';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CapturedError,
|
|
2
|
-
export { B as BugStackClient,
|
|
1
|
+
import { C as CapturedError, a as ErrorCaptureClient, S as StackFrame } from './client-DoqE7sNh.js';
|
|
2
|
+
export { B as BugStackClient, c as BugStackConfig, E as ErrorCaptureConfig, d as ErrorDeduplicator, e as ErrorReportPayload, N as NextRouteHandler, f as ResolvedConfig, g as RetryQueue, R as RouteContext, b as RouteOptions, h as SourceContext, i as isChunkLoadError } from './client-DoqE7sNh.js';
|
|
3
3
|
export { withBugStack, withErrorCapture } from './adapters/nextjs/index.js';
|
|
4
4
|
import 'next/server';
|
|
5
5
|
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `next.config.js` wrapper for bugstack — turns server-side source-map
|
|
3
|
+
* emission on without the user having to touch their webpack config.
|
|
4
|
+
*
|
|
5
|
+
* Intended use:
|
|
6
|
+
*
|
|
7
|
+
* // next.config.js
|
|
8
|
+
* const { withBugstack } = require('bugstack-sdk/next-config')
|
|
9
|
+
*
|
|
10
|
+
* module.exports = withBugstack({
|
|
11
|
+
* // ...your existing Next config
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* Once wrapped, `next build` emits .map files alongside server bundles in
|
|
15
|
+
* .next/server/. Pair with `bugstack sourcemaps upload` in your build
|
|
16
|
+
* script to ship them to bugstack so the orchestrator can resolve
|
|
17
|
+
* production stack frames back to source files.
|
|
18
|
+
*
|
|
19
|
+
* Anything you already pass under `webpack` is preserved and called first;
|
|
20
|
+
* we only set `devtool` afterwards, and only for production server builds
|
|
21
|
+
* (not dev, not client). Idempotent — wrapping twice is a no-op.
|
|
22
|
+
*/
|
|
23
|
+
type WebpackConfig = {
|
|
24
|
+
devtool?: string | false;
|
|
25
|
+
} & Record<string, unknown>;
|
|
26
|
+
type WebpackContext = {
|
|
27
|
+
dev: boolean;
|
|
28
|
+
isServer: boolean;
|
|
29
|
+
nextRuntime?: "nodejs" | "edge";
|
|
30
|
+
};
|
|
31
|
+
type WebpackHook = (config: WebpackConfig, context: WebpackContext) => WebpackConfig;
|
|
32
|
+
type NextConfigLike = {
|
|
33
|
+
webpack?: WebpackHook;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
interface BugstackNextOptions {
|
|
37
|
+
/**
|
|
38
|
+
* When true (default), enables server-side source-map emission.
|
|
39
|
+
* Set false to opt back out — useful if you have your own devtool config
|
|
40
|
+
* and want bugstack to leave it alone.
|
|
41
|
+
*/
|
|
42
|
+
emitServerSourceMaps?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* `devtool` value to use for production server builds. Default
|
|
45
|
+
* `"source-map"` (full external maps). Override to e.g. `"hidden-source-map"`
|
|
46
|
+
* if you want maps emitted but no `# sourceMappingURL` comment in the JS.
|
|
47
|
+
*/
|
|
48
|
+
serverDevtool?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wrap a Next.js config to enable bugstack's source-map pipeline.
|
|
52
|
+
* Pass-through if `emitServerSourceMaps` is false.
|
|
53
|
+
*/
|
|
54
|
+
declare function withBugstack<C extends NextConfigLike>(nextConfig?: C, options?: BugstackNextOptions): C;
|
|
55
|
+
|
|
56
|
+
export { type BugstackNextOptions, withBugstack as default, withBugstack };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `next.config.js` wrapper for bugstack — turns server-side source-map
|
|
3
|
+
* emission on without the user having to touch their webpack config.
|
|
4
|
+
*
|
|
5
|
+
* Intended use:
|
|
6
|
+
*
|
|
7
|
+
* // next.config.js
|
|
8
|
+
* const { withBugstack } = require('bugstack-sdk/next-config')
|
|
9
|
+
*
|
|
10
|
+
* module.exports = withBugstack({
|
|
11
|
+
* // ...your existing Next config
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* Once wrapped, `next build` emits .map files alongside server bundles in
|
|
15
|
+
* .next/server/. Pair with `bugstack sourcemaps upload` in your build
|
|
16
|
+
* script to ship them to bugstack so the orchestrator can resolve
|
|
17
|
+
* production stack frames back to source files.
|
|
18
|
+
*
|
|
19
|
+
* Anything you already pass under `webpack` is preserved and called first;
|
|
20
|
+
* we only set `devtool` afterwards, and only for production server builds
|
|
21
|
+
* (not dev, not client). Idempotent — wrapping twice is a no-op.
|
|
22
|
+
*/
|
|
23
|
+
type WebpackConfig = {
|
|
24
|
+
devtool?: string | false;
|
|
25
|
+
} & Record<string, unknown>;
|
|
26
|
+
type WebpackContext = {
|
|
27
|
+
dev: boolean;
|
|
28
|
+
isServer: boolean;
|
|
29
|
+
nextRuntime?: "nodejs" | "edge";
|
|
30
|
+
};
|
|
31
|
+
type WebpackHook = (config: WebpackConfig, context: WebpackContext) => WebpackConfig;
|
|
32
|
+
type NextConfigLike = {
|
|
33
|
+
webpack?: WebpackHook;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
interface BugstackNextOptions {
|
|
37
|
+
/**
|
|
38
|
+
* When true (default), enables server-side source-map emission.
|
|
39
|
+
* Set false to opt back out — useful if you have your own devtool config
|
|
40
|
+
* and want bugstack to leave it alone.
|
|
41
|
+
*/
|
|
42
|
+
emitServerSourceMaps?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* `devtool` value to use for production server builds. Default
|
|
45
|
+
* `"source-map"` (full external maps). Override to e.g. `"hidden-source-map"`
|
|
46
|
+
* if you want maps emitted but no `# sourceMappingURL` comment in the JS.
|
|
47
|
+
*/
|
|
48
|
+
serverDevtool?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wrap a Next.js config to enable bugstack's source-map pipeline.
|
|
52
|
+
* Pass-through if `emitServerSourceMaps` is false.
|
|
53
|
+
*/
|
|
54
|
+
declare function withBugstack<C extends NextConfigLike>(nextConfig?: C, options?: BugstackNextOptions): C;
|
|
55
|
+
|
|
56
|
+
export { type BugstackNextOptions, withBugstack as default, withBugstack };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// src/next-config/index.ts
|
|
6
|
+
function withBugstack(nextConfig = {}, options = {}) {
|
|
7
|
+
const emit = options.emitServerSourceMaps ?? true;
|
|
8
|
+
if (!emit) return nextConfig;
|
|
9
|
+
const serverDevtool = options.serverDevtool ?? "source-map";
|
|
10
|
+
const userWebpack = nextConfig.webpack;
|
|
11
|
+
const wrapped = (config, context) => {
|
|
12
|
+
const next = userWebpack ? userWebpack(config, context) : config;
|
|
13
|
+
if (context.isServer && !context.dev) {
|
|
14
|
+
next.devtool = serverDevtool;
|
|
15
|
+
}
|
|
16
|
+
return next;
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
...nextConfig,
|
|
20
|
+
webpack: wrapped
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
var next_config_default = withBugstack;
|
|
24
|
+
|
|
25
|
+
exports.default = next_config_default;
|
|
26
|
+
exports.withBugstack = withBugstack;
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/next-config/index.ts"],"names":[],"mappings":";;;;;AA0DO,SAAS,aACd,UAAA,GAAgB,EAAC,EACjB,OAAA,GAA+B,EAAC,EAC7B;AACH,EAAA,MAAM,IAAA,GAAO,QAAQ,oBAAA,IAAwB,IAAA;AAC7C,EAAA,IAAI,CAAC,MAAM,OAAO,UAAA;AAElB,EAAA,MAAM,aAAA,GAAgB,QAAQ,aAAA,IAAiB,YAAA;AAC/C,EAAA,MAAM,cAAc,UAAA,CAAW,OAAA;AAE/B,EAAA,MAAM,OAAA,GAAuB,CAAC,MAAA,EAAQ,OAAA,KAAY;AAGhD,IAAA,MAAM,IAAA,GAAO,WAAA,GAAc,WAAA,CAAY,MAAA,EAAQ,OAAO,CAAA,GAAI,MAAA;AAE1D,IAAA,IAAI,OAAA,CAAQ,QAAA,IAAY,CAAC,OAAA,CAAQ,GAAA,EAAK;AACpC,MAAA,IAAA,CAAK,OAAA,GAAU,aAAA;AAAA,IACjB;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,UAAA;AAAA,IACH,OAAA,EAAS;AAAA,GACX;AACF;AAIA,IAAO,mBAAA,GAAQ","file":"index.js","sourcesContent":["/**\r\n * `next.config.js` wrapper for bugstack — turns server-side source-map\r\n * emission on without the user having to touch their webpack config.\r\n *\r\n * Intended use:\r\n *\r\n * // next.config.js\r\n * const { withBugstack } = require('bugstack-sdk/next-config')\r\n *\r\n * module.exports = withBugstack({\r\n * // ...your existing Next config\r\n * })\r\n *\r\n * Once wrapped, `next build` emits .map files alongside server bundles in\r\n * .next/server/. Pair with `bugstack sourcemaps upload` in your build\r\n * script to ship them to bugstack so the orchestrator can resolve\r\n * production stack frames back to source files.\r\n *\r\n * Anything you already pass under `webpack` is preserved and called first;\r\n * we only set `devtool` afterwards, and only for production server builds\r\n * (not dev, not client). Idempotent — wrapping twice is a no-op.\r\n */\r\n\r\n// Minimal NextConfig shape — keeping it loose so we don't pull in `next`\r\n// as a peer dependency just for this wrapper. The underlying type is\r\n// import(\"next\").NextConfig but consumers don't need to know that.\r\ntype WebpackConfig = { devtool?: string | false } & Record<string, unknown>;\r\ntype WebpackContext = {\r\n dev: boolean;\r\n isServer: boolean;\r\n nextRuntime?: \"nodejs\" | \"edge\";\r\n};\r\ntype WebpackHook = (config: WebpackConfig, context: WebpackContext) => WebpackConfig;\r\ntype NextConfigLike = {\r\n webpack?: WebpackHook;\r\n [key: string]: unknown;\r\n};\r\n\r\nexport interface BugstackNextOptions {\r\n /**\r\n * When true (default), enables server-side source-map emission.\r\n * Set false to opt back out — useful if you have your own devtool config\r\n * and want bugstack to leave it alone.\r\n */\r\n emitServerSourceMaps?: boolean;\r\n\r\n /**\r\n * `devtool` value to use for production server builds. Default\r\n * `\"source-map\"` (full external maps). Override to e.g. `\"hidden-source-map\"`\r\n * if you want maps emitted but no `# sourceMappingURL` comment in the JS.\r\n */\r\n serverDevtool?: string;\r\n}\r\n\r\n/**\r\n * Wrap a Next.js config to enable bugstack's source-map pipeline.\r\n * Pass-through if `emitServerSourceMaps` is false.\r\n */\r\nexport function withBugstack<C extends NextConfigLike>(\r\n nextConfig: C = {} as C,\r\n options: BugstackNextOptions = {},\r\n): C {\r\n const emit = options.emitServerSourceMaps ?? true;\r\n if (!emit) return nextConfig;\r\n\r\n const serverDevtool = options.serverDevtool ?? \"source-map\";\r\n const userWebpack = nextConfig.webpack;\r\n\r\n const wrapped: WebpackHook = (config, context) => {\r\n // Run the user's hook first so we don't clobber custom resolve aliases,\r\n // plugins, etc. Their hook may also touch `devtool`; we override after.\r\n const next = userWebpack ? userWebpack(config, context) : config;\r\n\r\n if (context.isServer && !context.dev) {\r\n next.devtool = serverDevtool;\r\n }\r\n return next;\r\n };\r\n\r\n return {\r\n ...nextConfig,\r\n webpack: wrapped,\r\n };\r\n}\r\n\r\n// Default export aliases withBugstack so `require('bugstack-sdk/next-config')`\r\n// also works as a callable wrapper without destructuring.\r\nexport default withBugstack;\r\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/next-config/index.ts
|
|
2
|
+
function withBugstack(nextConfig = {}, options = {}) {
|
|
3
|
+
const emit = options.emitServerSourceMaps ?? true;
|
|
4
|
+
if (!emit) return nextConfig;
|
|
5
|
+
const serverDevtool = options.serverDevtool ?? "source-map";
|
|
6
|
+
const userWebpack = nextConfig.webpack;
|
|
7
|
+
const wrapped = (config, context) => {
|
|
8
|
+
const next = userWebpack ? userWebpack(config, context) : config;
|
|
9
|
+
if (context.isServer && !context.dev) {
|
|
10
|
+
next.devtool = serverDevtool;
|
|
11
|
+
}
|
|
12
|
+
return next;
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
...nextConfig,
|
|
16
|
+
webpack: wrapped
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var next_config_default = withBugstack;
|
|
20
|
+
|
|
21
|
+
export { next_config_default as default, withBugstack };
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|
|
23
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/next-config/index.ts"],"names":[],"mappings":";AA0DO,SAAS,aACd,UAAA,GAAgB,EAAC,EACjB,OAAA,GAA+B,EAAC,EAC7B;AACH,EAAA,MAAM,IAAA,GAAO,QAAQ,oBAAA,IAAwB,IAAA;AAC7C,EAAA,IAAI,CAAC,MAAM,OAAO,UAAA;AAElB,EAAA,MAAM,aAAA,GAAgB,QAAQ,aAAA,IAAiB,YAAA;AAC/C,EAAA,MAAM,cAAc,UAAA,CAAW,OAAA;AAE/B,EAAA,MAAM,OAAA,GAAuB,CAAC,MAAA,EAAQ,OAAA,KAAY;AAGhD,IAAA,MAAM,IAAA,GAAO,WAAA,GAAc,WAAA,CAAY,MAAA,EAAQ,OAAO,CAAA,GAAI,MAAA;AAE1D,IAAA,IAAI,OAAA,CAAQ,QAAA,IAAY,CAAC,OAAA,CAAQ,GAAA,EAAK;AACpC,MAAA,IAAA,CAAK,OAAA,GAAU,aAAA;AAAA,IACjB;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,GAAG,UAAA;AAAA,IACH,OAAA,EAAS;AAAA,GACX;AACF;AAIA,IAAO,mBAAA,GAAQ","file":"index.mjs","sourcesContent":["/**\r\n * `next.config.js` wrapper for bugstack — turns server-side source-map\r\n * emission on without the user having to touch their webpack config.\r\n *\r\n * Intended use:\r\n *\r\n * // next.config.js\r\n * const { withBugstack } = require('bugstack-sdk/next-config')\r\n *\r\n * module.exports = withBugstack({\r\n * // ...your existing Next config\r\n * })\r\n *\r\n * Once wrapped, `next build` emits .map files alongside server bundles in\r\n * .next/server/. Pair with `bugstack sourcemaps upload` in your build\r\n * script to ship them to bugstack so the orchestrator can resolve\r\n * production stack frames back to source files.\r\n *\r\n * Anything you already pass under `webpack` is preserved and called first;\r\n * we only set `devtool` afterwards, and only for production server builds\r\n * (not dev, not client). Idempotent — wrapping twice is a no-op.\r\n */\r\n\r\n// Minimal NextConfig shape — keeping it loose so we don't pull in `next`\r\n// as a peer dependency just for this wrapper. The underlying type is\r\n// import(\"next\").NextConfig but consumers don't need to know that.\r\ntype WebpackConfig = { devtool?: string | false } & Record<string, unknown>;\r\ntype WebpackContext = {\r\n dev: boolean;\r\n isServer: boolean;\r\n nextRuntime?: \"nodejs\" | \"edge\";\r\n};\r\ntype WebpackHook = (config: WebpackConfig, context: WebpackContext) => WebpackConfig;\r\ntype NextConfigLike = {\r\n webpack?: WebpackHook;\r\n [key: string]: unknown;\r\n};\r\n\r\nexport interface BugstackNextOptions {\r\n /**\r\n * When true (default), enables server-side source-map emission.\r\n * Set false to opt back out — useful if you have your own devtool config\r\n * and want bugstack to leave it alone.\r\n */\r\n emitServerSourceMaps?: boolean;\r\n\r\n /**\r\n * `devtool` value to use for production server builds. Default\r\n * `\"source-map\"` (full external maps). Override to e.g. `\"hidden-source-map\"`\r\n * if you want maps emitted but no `# sourceMappingURL` comment in the JS.\r\n */\r\n serverDevtool?: string;\r\n}\r\n\r\n/**\r\n * Wrap a Next.js config to enable bugstack's source-map pipeline.\r\n * Pass-through if `emitServerSourceMaps` is false.\r\n */\r\nexport function withBugstack<C extends NextConfigLike>(\r\n nextConfig: C = {} as C,\r\n options: BugstackNextOptions = {},\r\n): C {\r\n const emit = options.emitServerSourceMaps ?? true;\r\n if (!emit) return nextConfig;\r\n\r\n const serverDevtool = options.serverDevtool ?? \"source-map\";\r\n const userWebpack = nextConfig.webpack;\r\n\r\n const wrapped: WebpackHook = (config, context) => {\r\n // Run the user's hook first so we don't clobber custom resolve aliases,\r\n // plugins, etc. Their hook may also touch `devtool`; we override after.\r\n const next = userWebpack ? userWebpack(config, context) : config;\r\n\r\n if (context.isServer && !context.dev) {\r\n next.devtool = serverDevtool;\r\n }\r\n return next;\r\n };\r\n\r\n return {\r\n ...nextConfig,\r\n webpack: wrapped,\r\n };\r\n}\r\n\r\n// Default export aliases withBugstack so `require('bugstack-sdk/next-config')`\r\n// also works as a callable wrapper without destructuring.\r\nexport default withBugstack;\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bugstack-sdk",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Framework-agnostic error capture SDK with adapters for Next.js, Express, and more - automatically capture, report, and fix errors",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,11 +40,26 @@
|
|
|
40
40
|
"types": "./dist/adapters/generic/index.d.ts",
|
|
41
41
|
"import": "./dist/adapters/generic/index.mjs",
|
|
42
42
|
"require": "./dist/adapters/generic/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./build": {
|
|
45
|
+
"types": "./dist/build/upload.d.ts",
|
|
46
|
+
"import": "./dist/build/upload.mjs",
|
|
47
|
+
"require": "./dist/build/upload.js"
|
|
48
|
+
},
|
|
49
|
+
"./next-config": {
|
|
50
|
+
"types": "./dist/next-config/index.d.ts",
|
|
51
|
+
"import": "./dist/next-config/index.mjs",
|
|
52
|
+
"require": "./dist/next-config/index.js"
|
|
43
53
|
}
|
|
44
54
|
},
|
|
55
|
+
"bin": {
|
|
56
|
+
"bugstack": "bin/bugstack.cjs"
|
|
57
|
+
},
|
|
45
58
|
"files": [
|
|
46
59
|
"dist",
|
|
47
|
-
"
|
|
60
|
+
"bin",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md"
|
|
48
63
|
],
|
|
49
64
|
"scripts": {
|
|
50
65
|
"build": "tsup",
|