Repository navigation
feat: Embed source content and allow setting the source file name - #104
Conversation
Does this string live in memory for the life of the process? |
|
Good point, thanks for raising! I'm unfortunately not a 100% familiar with Orchestrion but I believe for runtime instrumentation via tracing-hooks, this should be discarded from memory as soon as the transform ran. For runtime, the source maps don't get consumed. If I'm missing something here, or we generally want to err on the side of caution, I can also remove the embedding part from the PR. |
|
(reviewing, but just re the comments above @jsumners-nr and @Lms24) The map is always generated when
Suggestion: no change needed for this PR. As future work, runtime callers do not need a sourcemap at all. An option to skip map generation (or to generate it lazily) would save more than this PR adds, but I'd argue it's out of scope here. |
isaacs
left a comment
There was a problem hiding this comment.
I like this. It keeps the change at the one place that builds the map, and adds an options object rather than a 5th positional argument, which leaves room for more options. The default source name does not change, so existing callers only see the new sourcesContent. Embedding the source is the safer of the two changes: it makes the map self-contained no matter what path the caller gives, and its cost is transient for the runtime hooks.
The weak point is the input-sourcemap path. The transform doesn't compose with an earlier map, and instead merges two maps in different coordinate systems. This PR isn't the cause of that, but it puts a real file path and the intermediate content on top of it.
I recommend fixing the composition with applySourceMap, handling null and '' options, and updating the README. With those, this is good to go, imo.
Co-authored-by: isaacs <i@izs.me>
Copying the input map's mappings into the generator mixed two coordinate systems and never resolved output positions back through the input map. Build a fresh generator for the transform and apply the input map to it, so positions resolve to the original source. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Currently, the
Transformer::transformmethod names the source in its generated sourcemap<moduleName>/<filePath>(for exampleioredis/built/Redis.js) and doesn't embed the file's content. Bundlers resolve that name against the project root (/app/ioredis/built/Redis.js), but the actual file lives innode_modules(e.g./app/node_modules/ioredis/built/Redis.js).Tools that follow the map back to the original code, then can fail with ENOENT for every chunk that contains an instrumented module. A concrete example is Sentry's source map upload in Sveltekit where we use
sorceryto walk a chain of source maps to flatten them (to get correct source maps linking back to the actual source code instead of an intermediate build output).This PR proposes two changes:
sourcesContent. With the code inside the map, tools don't need to read the source file from disk. The map still works when the path is wrong, or when the file isn't there, for example after the map is uploaded somewhere else.{ sourceFile }argument toTransformer::transformthat sets the source name, so bundler plugins can pass the module's real path. Callers that don't pass it keep the current source name. In a follow-up PR,@apm-js-collab/code-transformer-bundler-pluginswill pass each module's absolute path as sourceFile, so the maps it returns point at real files on disk.If reviewers prefer, I can also remove the embedding part of the PR, since it's not strictly needed for Sentry (we inline sourcesContent before we upload source maps anyway). Might be helpful for others though.
AI disclosure: Code written with Claude Code and was reviewed by me. PR description written myself.
Context: getsentry/sentry-javascript#25329