Commit 838ccaa
authored
feat: native debug ID injection and sourcemap upload (#543)
## Summary
Replace `npx @sentry/cli sourcemaps inject` and `@sentry/esbuild-plugin`
with native TypeScript implementations. **Zero new dependencies** — only
uses `node:crypto`, `node:fs/promises`, `node:zlib`, and existing
`p-limit`.
## What changed
### Debug ID Injection (`script/debug-id.ts`)
- `contentToDebugId()`: SHA-256 → UUID v4 (byte-for-byte compatible with
`@sentry/bundler-plugin-core`'s `stringToUUID`, verified against the
actual package)
- `getDebugIdSnippet()`: Runtime IIFE that registers debug IDs in
`globalThis._sentryDebugIds`
- `injectDebugId()`: Injects snippet + comment into JS, adjusts
sourcemap mappings, adds `debugId`/`debug_id` fields
- Idempotent, hashbang-safe, always runs (even without
`SENTRY_AUTH_TOKEN`)
### Streaming ZIP Builder (`src/lib/sourcemap/zip.ts`)
- Writes entries to disk via `node:fs/promises` `FileHandle` — only one
compressed entry in memory at a time
- Uses raw DEFLATE (`node:zlib`) for compression, STORE for empty files
- Produces valid ZIP archives extractable by standard tools
### Sourcemap Upload API (`src/lib/api/sourcemaps.ts`)
- Implements Sentry's chunk-upload + assemble protocol natively
- Parallel chunk uploads via `p-limit` with server-configured
concurrency
- Gzip compression for chunks (server only supports gzip — verified on
US and DE regions)
- Streaming: reads ZIP back in 8MB chunks for upload, never holds full
bundle in memory
### Build Pipeline
- `script/build.ts`: Uses native injection + upload (removed
`execSync('npx @sentry/cli ...')`)
- `script/bundle.ts`: Custom `sentrySourcemapPlugin` esbuild plugin
replaces `@sentry/esbuild-plugin`
### Dependency Removal
- `@sentry/esbuild-plugin` removed from devDependencies
- Its transitive `@sentry/cli` (Rust binary) dependency is eliminated
## Tests
- 13 tests for debug-id (5 property-based, 8 unit)
- 10 tests for ZipWriter (2 property-based, 5 unit, 3 binary format)
## Follow-up (PR 3)
User-facing CLI commands (`sentry sourcemap inject/upload`) with
worker-based parallel processing — tracked separately.1 parent b4cc6fb commit 838ccaa
File tree
10 files changed
+1464
-288
lines changed- script
- src/lib
- api
- sourcemap
- test
- lib/sourcemap
- script
10 files changed
+1464
-288
lines changedLarge diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
121 | 122 | | |
122 | | - | |
123 | | - | |
| 123 | + | |
| 124 | + | |
124 | 125 | | |
125 | | - | |
126 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
127 | 129 | | |
128 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
129 | 144 | | |
130 | 145 | | |
131 | 146 | | |
132 | 147 | | |
133 | 148 | | |
134 | 149 | | |
135 | 150 | | |
136 | | - | |
137 | 151 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
142 | 175 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | 176 | | |
148 | 177 | | |
149 | 178 | | |
| |||
294 | 323 | | |
295 | 324 | | |
296 | 325 | | |
297 | | - | |
298 | | - | |
| 326 | + | |
| 327 | + | |
299 | 328 | | |
300 | 329 | | |
301 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 2 | + | |
16 | 3 | | |
17 | 4 | | |
| 5 | + | |
| 6 | + | |
18 | 7 | | |
19 | 8 | | |
20 | 9 | | |
| |||
33 | 22 | | |
34 | 23 | | |
35 | 24 | | |
36 | | - | |
| 25 | + | |
37 | 26 | | |
38 | 27 | | |
39 | 28 | | |
40 | | - | |
41 | 29 | | |
42 | 30 | | |
43 | 31 | | |
44 | 32 | | |
45 | 33 | | |
46 | | - | |
47 | 34 | | |
48 | 35 | | |
49 | 36 | | |
| |||
59 | 46 | | |
60 | 47 | | |
61 | 48 | | |
62 | | - | |
63 | | - | |
| 49 | + | |
64 | 50 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
69 | 94 | | |
70 | 95 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
84 | 174 | | |
85 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
86 | 178 | | |
87 | 179 | | |
88 | 180 | | |
| |||
0 commit comments