@getmonitor/cli 0.1.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 +201 -0
- package/README.md +84 -0
- package/dist/bin.d.ts +9 -0
- package/dist/bin.js +321 -0
- package/dist/bin.js.map +1 -0
- package/dist/discoverArtifacts.d.ts +10 -0
- package/dist/index.cjs +267 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +265 -0
- package/dist/index.js.map +1 -0
- package/dist/injectDebugId.d.ts +16 -0
- package/dist/processSourceMaps.d.ts +7 -0
- package/dist/resolveRelease.d.ts +6 -0
- package/dist/types.d.ts +11 -0
- package/dist/uploadSourceMap.d.ts +14 -0
- package/package.json +33 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { readdirSync, existsSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { join, dirname, relative } from 'node:path';
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
// packages/cli/src/discoverArtifacts.ts
|
|
7
|
+
const SOURCE_MAPPING_URL = /^\s*\/\/#\s*sourceMappingURL=(\S+)\s*$/gm;
|
|
8
|
+
// Node recognizes three JS module extensions with runtime meaning (`.js`, `.mjs` for explicit
|
|
9
|
+
// ESM, `.cjs` for explicit CommonJS regardless of the nearest package.json's "type") — all three
|
|
10
|
+
// show up as real build output. Nitro's node-server preset (used by `@getmonitor/nuxt`'s e2e
|
|
11
|
+
// test), for one, emits `.output/server/**/*.mjs` unconditionally: verified against a real
|
|
12
|
+
// `nuxt build`, where a `.js`-only match left every server chunk's `.map` file undiscovered and
|
|
13
|
+
// unstripped even though `.output/` itself was already fully written by the time discovery ran.
|
|
14
|
+
const JS_EXTENSIONS = ['.js', '.mjs', '.cjs'];
|
|
15
|
+
/** Recursively finds every JS file (`.js`, `.mjs`, `.cjs`) under `directory` and resolves its
|
|
16
|
+
* source map path primarily via its `//# sourceMappingURL=` comment (resolved relative to the
|
|
17
|
+
* JS file's own directory), falling back to same-basename-plus-`.map` when there's no comment,
|
|
18
|
+
* the comment references a data: URI, or the referenced file doesn't exist. A JS file with no
|
|
19
|
+
* resolvable map either way is skipped. */
|
|
20
|
+
function discoverArtifacts(directory) {
|
|
21
|
+
const artifacts = [];
|
|
22
|
+
walk(directory, artifacts);
|
|
23
|
+
return artifacts;
|
|
24
|
+
}
|
|
25
|
+
function walk(dir, artifacts) {
|
|
26
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
27
|
+
const fullPath = join(dir, entry.name);
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
walk(fullPath, artifacts);
|
|
30
|
+
}
|
|
31
|
+
else if (entry.isFile() && JS_EXTENSIONS.some((ext) => entry.name.endsWith(ext))) {
|
|
32
|
+
const mapPath = resolveMapPath(fullPath);
|
|
33
|
+
if (mapPath)
|
|
34
|
+
artifacts.push({ jsPath: fullPath, mapPath });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function resolveMapPath(jsPath) {
|
|
39
|
+
const commentMapPath = readSourceMappingUrlComment(jsPath);
|
|
40
|
+
if (commentMapPath && existsSync(commentMapPath))
|
|
41
|
+
return commentMapPath;
|
|
42
|
+
const fallbackMapPath = `${jsPath}.map`;
|
|
43
|
+
if (existsSync(fallbackMapPath))
|
|
44
|
+
return fallbackMapPath;
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function readSourceMappingUrlComment(jsPath) {
|
|
48
|
+
let content;
|
|
49
|
+
try {
|
|
50
|
+
content = readFileSync(jsPath, 'utf8');
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Unreadable file (permission denied, broken symlink, deleted mid-walk, etc.) — treat it
|
|
54
|
+
// like "no comment found" rather than aborting the whole discoverArtifacts() walk.
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const matches = [...content.matchAll(SOURCE_MAPPING_URL)];
|
|
58
|
+
if (matches.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
// The LAST sourceMappingURL comment in the file wins, matching how bundlers/browsers treat
|
|
61
|
+
// concatenated/reprocessed output — later comments supersede earlier ones.
|
|
62
|
+
const reference = matches.at(-1)[1];
|
|
63
|
+
if (reference.startsWith('data:'))
|
|
64
|
+
return undefined; // embedded map, nothing to discover on disk
|
|
65
|
+
return join(dirname(jsPath), reference);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// packages/cli/src/injectDebugId.ts
|
|
69
|
+
/** Computes the debug-ID-injected JS content and the debug-ID-tagged source map JSON, in
|
|
70
|
+
* memory — callers decide whether/when to persist the result to disk (processSourceMaps
|
|
71
|
+
* only writes it after a successful upload, so a failed upload never leaves partially
|
|
72
|
+
* mutated files behind). The injected JS also has its `//# sourceMappingURL=` comment(s)
|
|
73
|
+
* removed, since the source map it names is only ever kept in GetMonitor's backend after
|
|
74
|
+
* a successful upload — never served publicly alongside it.
|
|
75
|
+
*
|
|
76
|
+
* `originalMapJson` must be valid JSON — this is a pure function with no fallback to
|
|
77
|
+
* degrade to (unlike discoverArtifacts, which can skip an unreadable file, this function's
|
|
78
|
+
* caller expects a definite result), so a malformed map is left to throw via JSON.parse
|
|
79
|
+
* rather than being swallowed here. */
|
|
80
|
+
function injectDebugId(originalJs, originalMapJson, debugId) {
|
|
81
|
+
const withoutMapComment = originalJs
|
|
82
|
+
.split('\n')
|
|
83
|
+
.filter((line) => !line.trimStart().startsWith('//# sourceMappingURL='))
|
|
84
|
+
.join('\n');
|
|
85
|
+
const map = JSON.parse(originalMapJson);
|
|
86
|
+
map.debugId = debugId;
|
|
87
|
+
return {
|
|
88
|
+
js: `${withoutMapComment}\n${buildInjectedSnippet(debugId)}`,
|
|
89
|
+
map: JSON.stringify(map),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** At load time, captures this statement's own `Error().stack`, extracts this file's
|
|
93
|
+
* identity from it using the same frame-shape @getmonitor/core's parseStackTrace parses for
|
|
94
|
+
* real errors (V8's `at ... (file:line:col)`, V8's bare `at file:line:col`, and Gecko's
|
|
95
|
+
* `fn@file:line:col`), and registers the debug ID under that identity. Like parseStackTrace,
|
|
96
|
+
* it scans every stack line and takes the first one that matches any of those shapes, rather
|
|
97
|
+
* than assuming a fixed line index — V8 prefixes an `"ErrorType: message"` header line that
|
|
98
|
+
* Gecko and Safari don't emit, so a fixed index would grab the wrong frame (or the wrong
|
|
99
|
+
* file's identity) on non-V8 engines; the header line simply fails to match any frame regex
|
|
100
|
+
* and is skipped automatically. A later real error whose frame.filename is parsed from the
|
|
101
|
+
* same JS-engine stack serialization will look up the same key. Wrapped in try/catch so any
|
|
102
|
+
* parsing edge case can never break the host app; wrapped in an IIFE so its locals don't leak
|
|
103
|
+
* into the file's module scope.
|
|
104
|
+
*
|
|
105
|
+
* `debugId` is interpolated unescaped into the generated snippet's string literal. That's
|
|
106
|
+
* safe today because every caller in this system sources `debugId` from
|
|
107
|
+
* `crypto.randomUUID()` (a later task), which can never contain a quote or backslash — but
|
|
108
|
+
* this function itself doesn't enforce that shape, so a caller passing an arbitrary string
|
|
109
|
+
* containing `'` or `\` would produce invalid/injected JS here. Flagged, not fixed, since
|
|
110
|
+
* validating/escaping isn't part of this function's specified contract. */
|
|
111
|
+
function buildInjectedSnippet(debugId) {
|
|
112
|
+
return (";(function(){try{var s=(new Error()).stack||'';var ls=s.split('\\n');var m=null;" +
|
|
113
|
+
'for(var i=0;i<ls.length&&!m;i++){var l=ls[i];' +
|
|
114
|
+
"m=l.match(/\\((.*):(\\d+):(\\d+)\\)\\s*$/)||l.match(/at (.*):(\\d+):(\\d+)\\s*$/)||l.match(/@(.*):(\\d+):(\\d+)\\s*$/)}" +
|
|
115
|
+
"var f=m&&m[1];if(f){var g=(typeof globalThis!=='undefined'?globalThis:self);" +
|
|
116
|
+
`g.__getmonitorDebugIds=g.__getmonitorDebugIds||{};g.__getmonitorDebugIds[f]='${debugId}';` +
|
|
117
|
+
'}}catch(e){}})();');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// packages/cli/src/resolveRelease.ts
|
|
121
|
+
/** Resolves the release identifier to tag uploaded source maps with. Precedence: explicit
|
|
122
|
+
* argument -> GETMONITOR_RELEASE env var -> current git commit SHA (if `directory` is inside
|
|
123
|
+
* a git working tree) -> `version` field of the nearest package.json walking up from
|
|
124
|
+
* `directory`. Matches the SDKs' own optional `release` field so events and source maps
|
|
125
|
+
* for the same deploy carry the same value. */
|
|
126
|
+
function resolveRelease(directory, explicit) {
|
|
127
|
+
if (explicit)
|
|
128
|
+
return explicit;
|
|
129
|
+
if (process.env.GETMONITOR_RELEASE)
|
|
130
|
+
return process.env.GETMONITOR_RELEASE;
|
|
131
|
+
const gitSha = tryGitSha(directory);
|
|
132
|
+
if (gitSha)
|
|
133
|
+
return gitSha;
|
|
134
|
+
const packageVersion = tryPackageVersion(directory);
|
|
135
|
+
if (packageVersion)
|
|
136
|
+
return packageVersion;
|
|
137
|
+
throw new Error('Could not resolve a release. Pass --release, set GETMONITOR_RELEASE, run inside a git repository, or add a package.json with a "version" field.');
|
|
138
|
+
}
|
|
139
|
+
function tryGitSha(directory) {
|
|
140
|
+
try {
|
|
141
|
+
return execFileSync('git', ['rev-parse', 'HEAD'], {
|
|
142
|
+
cwd: directory,
|
|
143
|
+
encoding: 'utf8',
|
|
144
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
145
|
+
}).trim();
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function tryPackageVersion(directory) {
|
|
152
|
+
let dir = directory;
|
|
153
|
+
for (let i = 0; i < 20; i++) {
|
|
154
|
+
const pkgPath = join(dir, 'package.json');
|
|
155
|
+
if (existsSync(pkgPath)) {
|
|
156
|
+
try {
|
|
157
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
158
|
+
return typeof pkg.version === 'string' ? pkg.version : undefined;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const parent = dirname(dir);
|
|
165
|
+
if (parent === dir)
|
|
166
|
+
return undefined;
|
|
167
|
+
dir = parent;
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// packages/cli/src/uploadSourceMap.ts
|
|
173
|
+
/** POSTs a single source map artifact to the (not-yet-implemented) backend contract
|
|
174
|
+
* documented in docs/superpowers/specs/2026-08-09-phase-2-source-maps-design.md. Throws on
|
|
175
|
+
* any non-2xx response or network failure — the caller (processSourceMaps) decides what
|
|
176
|
+
* "failed" means for its own result reporting and disk-write ordering. */
|
|
177
|
+
async function uploadSourceMap(params) {
|
|
178
|
+
// Must bind to globalThis, mirroring @getmonitor/core's HttpTransport: browsers' native
|
|
179
|
+
// fetch() throws "Illegal invocation" if called with a `this` other than
|
|
180
|
+
// Window/WorkerGlobalScope. Here fetchImpl is invoked as a plain function call below
|
|
181
|
+
// (`fetchImpl(url, init)`, never `params.fetchImpl(...)` or `this.fetchImpl(...)`), so this
|
|
182
|
+
// bind is defensive/consistent rather than load-bearing for this particular call site — but
|
|
183
|
+
// keeping the same default expression as HttpTransport avoids a divergent default if this
|
|
184
|
+
// code is ever refactored into a method.
|
|
185
|
+
const fetchImpl = params.fetchImpl ?? fetch.bind(globalThis);
|
|
186
|
+
const form = new FormData();
|
|
187
|
+
form.set('release', params.release);
|
|
188
|
+
form.set('debugId', params.debugId);
|
|
189
|
+
form.set('filename', params.filename);
|
|
190
|
+
form.set('sourcemap', new Blob([params.mapContent], { type: 'application/json' }), `${params.filename}.map`);
|
|
191
|
+
const response = await fetchImpl(`${params.apiHost}/api/v1/sourcemaps`, {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
headers: { Authorization: `Bearer ${params.authToken}` },
|
|
194
|
+
body: form,
|
|
195
|
+
});
|
|
196
|
+
if (!response.ok) {
|
|
197
|
+
throw new Error(`Source map upload failed for ${params.filename}: ${response.status} ${response.statusText}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// packages/cli/src/processSourceMaps.ts
|
|
202
|
+
/** Finds every JS/map artifact pair under `options.directory`, and for each one: injects a
|
|
203
|
+
* debug ID, uploads the tagged source map, and — only on a successful upload — writes the
|
|
204
|
+
* debug-ID-injected JS back to disk and deletes the `.map` file. An artifact whose upload
|
|
205
|
+
* fails is left completely untouched on disk, so it can be retried by re-running this
|
|
206
|
+
* function against the same directory. */
|
|
207
|
+
async function processSourceMaps(options) {
|
|
208
|
+
const authToken = options.authToken ?? process.env.GETMONITOR_AUTH_TOKEN;
|
|
209
|
+
if (!authToken) {
|
|
210
|
+
throw new Error('Missing auth token. Pass --auth-token or set GETMONITOR_AUTH_TOKEN.');
|
|
211
|
+
}
|
|
212
|
+
const release = resolveRelease(options.directory, options.release);
|
|
213
|
+
const artifacts = discoverArtifacts(options.directory);
|
|
214
|
+
const result = { uploaded: [], failed: [] };
|
|
215
|
+
for (const artifact of artifacts) {
|
|
216
|
+
const debugId = randomUUID();
|
|
217
|
+
let injected;
|
|
218
|
+
try {
|
|
219
|
+
const originalJs = readFileSync(artifact.jsPath, 'utf8');
|
|
220
|
+
const originalMap = readFileSync(artifact.mapPath, 'utf8');
|
|
221
|
+
// injectDebugId is a pure function that throws on malformed map JSON (by design — see
|
|
222
|
+
// its own doc comment). That's deliberately caught here, alongside upload failures: one
|
|
223
|
+
// corrupt/unreadable artifact on disk must not abort processing of every other artifact
|
|
224
|
+
// in the directory, the same failure-isolation principle discoverArtifacts applies to
|
|
225
|
+
// unreadable files during its walk. Nothing has been uploaded or written yet at this
|
|
226
|
+
// point, so a thrown injectDebugId or upload failure leaves the artifact's files
|
|
227
|
+
// completely untouched, and it's safe to report it as `failed` for a retry.
|
|
228
|
+
injected = injectDebugId(originalJs, originalMap, debugId);
|
|
229
|
+
await uploadSourceMap({
|
|
230
|
+
apiHost: options.apiHost,
|
|
231
|
+
authToken,
|
|
232
|
+
release,
|
|
233
|
+
debugId,
|
|
234
|
+
// Relative to options.directory, not the absolute on-disk path — the backend has no
|
|
235
|
+
// use for (and shouldn't see) the build machine's local filesystem layout.
|
|
236
|
+
filename: relative(options.directory, artifact.jsPath),
|
|
237
|
+
mapContent: injected.map,
|
|
238
|
+
fetchImpl: options.fetchImpl,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
result.failed.push(artifact.jsPath);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
writeFileSync(artifact.jsPath, injected.js);
|
|
247
|
+
rmSync(artifact.mapPath);
|
|
248
|
+
result.uploaded.push(artifact.jsPath);
|
|
249
|
+
}
|
|
250
|
+
catch (cleanupError) {
|
|
251
|
+
// The upload above already succeeded, so this must never land in `failed` — a caller
|
|
252
|
+
// retrying failed artifacts would mint a fresh debugId and re-upload, orphaning this
|
|
253
|
+
// upload server-side under the old one with no way to reconcile the two. The local
|
|
254
|
+
// cleanup failure (disk full, permission error, file lock) is real and worth knowing
|
|
255
|
+
// about, so it's surfaced here rather than silently swallowed, but it doesn't change
|
|
256
|
+
// the artifact's outcome.
|
|
257
|
+
result.uploaded.push(artifact.jsPath);
|
|
258
|
+
console.error(`Uploaded ${artifact.jsPath} but failed to update local files:`, cleanupError);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export { processSourceMaps };
|
|
265
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/discoverArtifacts.ts","../src/injectDebugId.ts","../src/resolveRelease.ts","../src/uploadSourceMap.ts","../src/processSourceMaps.ts"],"sourcesContent":["// packages/cli/src/discoverArtifacts.ts\nimport { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nexport interface Artifact {\n jsPath: string\n mapPath: string\n}\n\nconst SOURCE_MAPPING_URL = /^\\s*\\/\\/#\\s*sourceMappingURL=(\\S+)\\s*$/gm\n\n// Node recognizes three JS module extensions with runtime meaning (`.js`, `.mjs` for explicit\n// ESM, `.cjs` for explicit CommonJS regardless of the nearest package.json's \"type\") — all three\n// show up as real build output. Nitro's node-server preset (used by `@getmonitor/nuxt`'s e2e\n// test), for one, emits `.output/server/**/*.mjs` unconditionally: verified against a real\n// `nuxt build`, where a `.js`-only match left every server chunk's `.map` file undiscovered and\n// unstripped even though `.output/` itself was already fully written by the time discovery ran.\nconst JS_EXTENSIONS = ['.js', '.mjs', '.cjs']\n\n/** Recursively finds every JS file (`.js`, `.mjs`, `.cjs`) under `directory` and resolves its\n * source map path primarily via its `//# sourceMappingURL=` comment (resolved relative to the\n * JS file's own directory), falling back to same-basename-plus-`.map` when there's no comment,\n * the comment references a data: URI, or the referenced file doesn't exist. A JS file with no\n * resolvable map either way is skipped. */\nexport function discoverArtifacts(directory: string): Artifact[] {\n const artifacts: Artifact[] = []\n walk(directory, artifacts)\n return artifacts\n}\n\nfunction walk(dir: string, artifacts: Artifact[]): void {\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const fullPath = join(dir, entry.name)\n if (entry.isDirectory()) {\n walk(fullPath, artifacts)\n } else if (entry.isFile() && JS_EXTENSIONS.some((ext) => entry.name.endsWith(ext))) {\n const mapPath = resolveMapPath(fullPath)\n if (mapPath) artifacts.push({ jsPath: fullPath, mapPath })\n }\n }\n}\n\nfunction resolveMapPath(jsPath: string): string | undefined {\n const commentMapPath = readSourceMappingUrlComment(jsPath)\n if (commentMapPath && existsSync(commentMapPath)) return commentMapPath\n\n const fallbackMapPath = `${jsPath}.map`\n if (existsSync(fallbackMapPath)) return fallbackMapPath\n\n return undefined\n}\n\nfunction readSourceMappingUrlComment(jsPath: string): string | undefined {\n let content: string\n try {\n content = readFileSync(jsPath, 'utf8')\n } catch {\n // Unreadable file (permission denied, broken symlink, deleted mid-walk, etc.) — treat it\n // like \"no comment found\" rather than aborting the whole discoverArtifacts() walk.\n return undefined\n }\n\n const matches = [...content.matchAll(SOURCE_MAPPING_URL)]\n if (matches.length === 0) return undefined\n\n // The LAST sourceMappingURL comment in the file wins, matching how bundlers/browsers treat\n // concatenated/reprocessed output — later comments supersede earlier ones.\n const reference = matches.at(-1)![1]\n if (reference.startsWith('data:')) return undefined // embedded map, nothing to discover on disk\n\n return join(dirname(jsPath), reference)\n}\n","// packages/cli/src/injectDebugId.ts\n\nexport interface InjectedArtifact {\n js: string\n map: string\n}\n\n/** Computes the debug-ID-injected JS content and the debug-ID-tagged source map JSON, in\n * memory — callers decide whether/when to persist the result to disk (processSourceMaps\n * only writes it after a successful upload, so a failed upload never leaves partially\n * mutated files behind). The injected JS also has its `//# sourceMappingURL=` comment(s)\n * removed, since the source map it names is only ever kept in GetMonitor's backend after\n * a successful upload — never served publicly alongside it.\n *\n * `originalMapJson` must be valid JSON — this is a pure function with no fallback to\n * degrade to (unlike discoverArtifacts, which can skip an unreadable file, this function's\n * caller expects a definite result), so a malformed map is left to throw via JSON.parse\n * rather than being swallowed here. */\nexport function injectDebugId(originalJs: string, originalMapJson: string, debugId: string): InjectedArtifact {\n const withoutMapComment = originalJs\n .split('\\n')\n .filter((line) => !line.trimStart().startsWith('//# sourceMappingURL='))\n .join('\\n')\n\n const map = JSON.parse(originalMapJson)\n map.debugId = debugId\n\n return {\n js: `${withoutMapComment}\\n${buildInjectedSnippet(debugId)}`,\n map: JSON.stringify(map),\n }\n}\n\n/** At load time, captures this statement's own `Error().stack`, extracts this file's\n * identity from it using the same frame-shape @getmonitor/core's parseStackTrace parses for\n * real errors (V8's `at ... (file:line:col)`, V8's bare `at file:line:col`, and Gecko's\n * `fn@file:line:col`), and registers the debug ID under that identity. Like parseStackTrace,\n * it scans every stack line and takes the first one that matches any of those shapes, rather\n * than assuming a fixed line index — V8 prefixes an `\"ErrorType: message\"` header line that\n * Gecko and Safari don't emit, so a fixed index would grab the wrong frame (or the wrong\n * file's identity) on non-V8 engines; the header line simply fails to match any frame regex\n * and is skipped automatically. A later real error whose frame.filename is parsed from the\n * same JS-engine stack serialization will look up the same key. Wrapped in try/catch so any\n * parsing edge case can never break the host app; wrapped in an IIFE so its locals don't leak\n * into the file's module scope.\n *\n * `debugId` is interpolated unescaped into the generated snippet's string literal. That's\n * safe today because every caller in this system sources `debugId` from\n * `crypto.randomUUID()` (a later task), which can never contain a quote or backslash — but\n * this function itself doesn't enforce that shape, so a caller passing an arbitrary string\n * containing `'` or `\\` would produce invalid/injected JS here. Flagged, not fixed, since\n * validating/escaping isn't part of this function's specified contract. */\nfunction buildInjectedSnippet(debugId: string): string {\n return (\n \";(function(){try{var s=(new Error()).stack||'';var ls=s.split('\\\\n');var m=null;\" +\n 'for(var i=0;i<ls.length&&!m;i++){var l=ls[i];' +\n \"m=l.match(/\\\\((.*):(\\\\d+):(\\\\d+)\\\\)\\\\s*$/)||l.match(/at (.*):(\\\\d+):(\\\\d+)\\\\s*$/)||l.match(/@(.*):(\\\\d+):(\\\\d+)\\\\s*$/)}\" +\n \"var f=m&&m[1];if(f){var g=(typeof globalThis!=='undefined'?globalThis:self);\" +\n `g.__getmonitorDebugIds=g.__getmonitorDebugIds||{};g.__getmonitorDebugIds[f]='${debugId}';` +\n '}}catch(e){}})();'\n )\n}\n","// packages/cli/src/resolveRelease.ts\nimport { execFileSync } from 'node:child_process'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\n/** Resolves the release identifier to tag uploaded source maps with. Precedence: explicit\n * argument -> GETMONITOR_RELEASE env var -> current git commit SHA (if `directory` is inside\n * a git working tree) -> `version` field of the nearest package.json walking up from\n * `directory`. Matches the SDKs' own optional `release` field so events and source maps\n * for the same deploy carry the same value. */\nexport function resolveRelease(directory: string, explicit?: string): string {\n if (explicit) return explicit\n if (process.env.GETMONITOR_RELEASE) return process.env.GETMONITOR_RELEASE\n\n const gitSha = tryGitSha(directory)\n if (gitSha) return gitSha\n\n const packageVersion = tryPackageVersion(directory)\n if (packageVersion) return packageVersion\n\n throw new Error(\n 'Could not resolve a release. Pass --release, set GETMONITOR_RELEASE, run inside a git repository, or add a package.json with a \"version\" field.',\n )\n}\n\nfunction tryGitSha(directory: string): string | undefined {\n try {\n return execFileSync('git', ['rev-parse', 'HEAD'], {\n cwd: directory,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim()\n } catch {\n return undefined\n }\n}\n\nfunction tryPackageVersion(directory: string): string | undefined {\n let dir = directory\n for (let i = 0; i < 20; i++) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))\n return typeof pkg.version === 'string' ? pkg.version : undefined\n } catch {\n return undefined\n }\n }\n const parent = dirname(dir)\n if (parent === dir) return undefined\n dir = parent\n }\n return undefined\n}\n","// packages/cli/src/uploadSourceMap.ts\n\nexport interface UploadSourceMapParams {\n apiHost: string\n authToken: string\n release: string\n debugId: string\n filename: string\n mapContent: string\n fetchImpl?: typeof fetch\n}\n\n/** POSTs a single source map artifact to the (not-yet-implemented) backend contract\n * documented in docs/superpowers/specs/2026-08-09-phase-2-source-maps-design.md. Throws on\n * any non-2xx response or network failure — the caller (processSourceMaps) decides what\n * \"failed\" means for its own result reporting and disk-write ordering. */\nexport async function uploadSourceMap(params: UploadSourceMapParams): Promise<void> {\n // Must bind to globalThis, mirroring @getmonitor/core's HttpTransport: browsers' native\n // fetch() throws \"Illegal invocation\" if called with a `this` other than\n // Window/WorkerGlobalScope. Here fetchImpl is invoked as a plain function call below\n // (`fetchImpl(url, init)`, never `params.fetchImpl(...)` or `this.fetchImpl(...)`), so this\n // bind is defensive/consistent rather than load-bearing for this particular call site — but\n // keeping the same default expression as HttpTransport avoids a divergent default if this\n // code is ever refactored into a method.\n const fetchImpl = params.fetchImpl ?? fetch.bind(globalThis)\n\n const form = new FormData()\n form.set('release', params.release)\n form.set('debugId', params.debugId)\n form.set('filename', params.filename)\n form.set('sourcemap', new Blob([params.mapContent], { type: 'application/json' }), `${params.filename}.map`)\n\n const response = await fetchImpl(`${params.apiHost}/api/v1/sourcemaps`, {\n method: 'POST',\n headers: { Authorization: `Bearer ${params.authToken}` },\n body: form,\n })\n\n if (!response.ok) {\n throw new Error(`Source map upload failed for ${params.filename}: ${response.status} ${response.statusText}`)\n }\n}\n","// packages/cli/src/processSourceMaps.ts\nimport { randomUUID } from 'node:crypto'\nimport { readFileSync, rmSync, writeFileSync } from 'node:fs'\nimport { relative } from 'node:path'\nimport { discoverArtifacts } from './discoverArtifacts'\nimport { injectDebugId, InjectedArtifact } from './injectDebugId'\nimport { resolveRelease } from './resolveRelease'\nimport { uploadSourceMap } from './uploadSourceMap'\nimport { ProcessSourceMapsOptions, ProcessSourceMapsResult } from './types'\n\n/** Finds every JS/map artifact pair under `options.directory`, and for each one: injects a\n * debug ID, uploads the tagged source map, and — only on a successful upload — writes the\n * debug-ID-injected JS back to disk and deletes the `.map` file. An artifact whose upload\n * fails is left completely untouched on disk, so it can be retried by re-running this\n * function against the same directory. */\nexport async function processSourceMaps(options: ProcessSourceMapsOptions): Promise<ProcessSourceMapsResult> {\n const authToken = options.authToken ?? process.env.GETMONITOR_AUTH_TOKEN\n if (!authToken) {\n throw new Error('Missing auth token. Pass --auth-token or set GETMONITOR_AUTH_TOKEN.')\n }\n\n const release = resolveRelease(options.directory, options.release)\n const artifacts = discoverArtifacts(options.directory)\n const result: ProcessSourceMapsResult = { uploaded: [], failed: [] }\n\n for (const artifact of artifacts) {\n const debugId = randomUUID()\n let injected: InjectedArtifact\n\n try {\n const originalJs = readFileSync(artifact.jsPath, 'utf8')\n const originalMap = readFileSync(artifact.mapPath, 'utf8')\n // injectDebugId is a pure function that throws on malformed map JSON (by design — see\n // its own doc comment). That's deliberately caught here, alongside upload failures: one\n // corrupt/unreadable artifact on disk must not abort processing of every other artifact\n // in the directory, the same failure-isolation principle discoverArtifacts applies to\n // unreadable files during its walk. Nothing has been uploaded or written yet at this\n // point, so a thrown injectDebugId or upload failure leaves the artifact's files\n // completely untouched, and it's safe to report it as `failed` for a retry.\n injected = injectDebugId(originalJs, originalMap, debugId)\n\n await uploadSourceMap({\n apiHost: options.apiHost,\n authToken,\n release,\n debugId,\n // Relative to options.directory, not the absolute on-disk path — the backend has no\n // use for (and shouldn't see) the build machine's local filesystem layout.\n filename: relative(options.directory, artifact.jsPath),\n mapContent: injected.map,\n fetchImpl: options.fetchImpl,\n })\n } catch {\n result.failed.push(artifact.jsPath)\n continue\n }\n\n try {\n writeFileSync(artifact.jsPath, injected.js)\n rmSync(artifact.mapPath)\n result.uploaded.push(artifact.jsPath)\n } catch (cleanupError) {\n // The upload above already succeeded, so this must never land in `failed` — a caller\n // retrying failed artifacts would mint a fresh debugId and re-upload, orphaning this\n // upload server-side under the old one with no way to reconcile the two. The local\n // cleanup failure (disk full, permission error, file lock) is real and worth knowing\n // about, so it's surfaced here rather than silently swallowed, but it doesn't change\n // the artifact's outcome.\n result.uploaded.push(artifact.jsPath)\n console.error(`Uploaded ${artifact.jsPath} but failed to update local files:`, cleanupError)\n }\n }\n\n return result\n}\n"],"names":[],"mappings":";;;;;AAAA;AASA,MAAM,kBAAkB,GAAG,0CAA0C;AAErE;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;AAE7C;;;;AAI2C;AACrC,SAAU,iBAAiB,CAAC,SAAiB,EAAA;IACjD,MAAM,SAAS,GAAe,EAAE;AAChC,IAAA,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC;AAC1B,IAAA,OAAO,SAAS;AAClB;AAEA,SAAS,IAAI,CAAC,GAAW,EAAE,SAAqB,EAAA;AAC9C,IAAA,KAAK,MAAM,K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M,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC3C,YAAA,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;YACxB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACvC;QAAE,OAAO,YAAY,EAAE;;;;;;;YAOrB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YACrC,OAAO,CAAC,KAAK,CAAC,CAAA,SAAA,EAAY,QAAQ,CAAC,MAAM,CAAA,kCAAA,CAAoC,EAAE,YAAY,CAAC;QAC9F;IACF;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface InjectedArtifact {
|
|
2
|
+
js: string;
|
|
3
|
+
map: string;
|
|
4
|
+
}
|
|
5
|
+
/** Computes the debug-ID-injected JS content and the debug-ID-tagged source map JSON, in
|
|
6
|
+
* memory — callers decide whether/when to persist the result to disk (processSourceMaps
|
|
7
|
+
* only writes it after a successful upload, so a failed upload never leaves partially
|
|
8
|
+
* mutated files behind). The injected JS also has its `//# sourceMappingURL=` comment(s)
|
|
9
|
+
* removed, since the source map it names is only ever kept in GetMonitor's backend after
|
|
10
|
+
* a successful upload — never served publicly alongside it.
|
|
11
|
+
*
|
|
12
|
+
* `originalMapJson` must be valid JSON — this is a pure function with no fallback to
|
|
13
|
+
* degrade to (unlike discoverArtifacts, which can skip an unreadable file, this function's
|
|
14
|
+
* caller expects a definite result), so a malformed map is left to throw via JSON.parse
|
|
15
|
+
* rather than being swallowed here. */
|
|
16
|
+
export declare function injectDebugId(originalJs: string, originalMapJson: string, debugId: string): InjectedArtifact;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProcessSourceMapsOptions, ProcessSourceMapsResult } from './types';
|
|
2
|
+
/** Finds every JS/map artifact pair under `options.directory`, and for each one: injects a
|
|
3
|
+
* debug ID, uploads the tagged source map, and — only on a successful upload — writes the
|
|
4
|
+
* debug-ID-injected JS back to disk and deletes the `.map` file. An artifact whose upload
|
|
5
|
+
* fails is left completely untouched on disk, so it can be retried by re-running this
|
|
6
|
+
* function against the same directory. */
|
|
7
|
+
export declare function processSourceMaps(options: ProcessSourceMapsOptions): Promise<ProcessSourceMapsResult>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Resolves the release identifier to tag uploaded source maps with. Precedence: explicit
|
|
2
|
+
* argument -> GETMONITOR_RELEASE env var -> current git commit SHA (if `directory` is inside
|
|
3
|
+
* a git working tree) -> `version` field of the nearest package.json walking up from
|
|
4
|
+
* `directory`. Matches the SDKs' own optional `release` field so events and source maps
|
|
5
|
+
* for the same deploy carry the same value. */
|
|
6
|
+
export declare function resolveRelease(directory: string, explicit?: string): string;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface UploadSourceMapParams {
|
|
2
|
+
apiHost: string;
|
|
3
|
+
authToken: string;
|
|
4
|
+
release: string;
|
|
5
|
+
debugId: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
mapContent: string;
|
|
8
|
+
fetchImpl?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
/** POSTs a single source map artifact to the (not-yet-implemented) backend contract
|
|
11
|
+
* documented in docs/superpowers/specs/2026-08-09-phase-2-source-maps-design.md. Throws on
|
|
12
|
+
* any non-2xx response or network failure — the caller (processSourceMaps) decides what
|
|
13
|
+
* "failed" means for its own result reporting and disk-write ordering. */
|
|
14
|
+
export declare function uploadSourceMap(params: UploadSourceMapParams): Promise<void>;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getmonitor/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"getmonitor": "dist/bin.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
20
|
+
"@types/node": "^20.14.0",
|
|
21
|
+
"esbuild": "^0.24.0",
|
|
22
|
+
"rollup": "^4.24.0",
|
|
23
|
+
"tslib": "^2.6.0",
|
|
24
|
+
"typescript": "^5.8.2",
|
|
25
|
+
"vitest": "^2.1.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rollup -c && chmod +x dist/bin.js",
|
|
29
|
+
"test": "vitest run --exclude 'e2e/**'",
|
|
30
|
+
"test:e2e": "vitest run e2e/processSourceMaps.spec.ts",
|
|
31
|
+
"lint": "tsc --noEmit && tsc --noEmit -p e2e"
|
|
32
|
+
}
|
|
33
|
+
}
|