[sourcemaps] Fix upload failure when sourceMappingURL is an absolute URL#2093
[sourcemaps] Fix upload failure when sourceMappingURL is an absolute URL#2093
Conversation
When JS files contain a full URL in `//# sourceMappingURL=` (e.g., a CDN URL set by webpack/rspack SourceMapDevToolPlugin), `upath.join` produces an invalid local path, causing all sourcemaps to be skipped with no fallback to the legacy `.js.map` glob method. Skip sourceMappingURL values that are absolute URLs (contain `://`) or absolute paths (start with `/`) so the legacy fallback is correctly triggered. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a regression where sourcemaps upload fails to upload any sourcemaps when //# sourceMappingURL is an absolute URL, by skipping unresolvable values so the legacy .js.map fallback can run.
Changes:
- Skip
sourceMappingURLentries that are absolute URLs or absolute paths during sourcemap resolution. - Add an integration test fixture case validating fallback behavior for absolute URL
sourceMappingURL.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/datadog-ci/src/commands/sourcemaps/upload.ts | Ignores absolute sourceMappingURL values to allow legacy .js.map fallback. |
| packages/datadog-ci/src/commands/sourcemaps/tests/upload.test.ts | Adds an integration test ensuring absolute-URL sourceMappingURL triggers the legacy fallback. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Skip absolute URLs and absolute paths — they can't be resolved to local files | ||
| if (sourcemapUrl.includes('://') || upath.isAbsolute(sourcemapUrl)) { |
There was a problem hiding this comment.
sourcemapUrl.includes('://') won’t catch other non-local sourceMappingURL forms that are also common/valid and would still produce an invalid joined path (and still block the legacy fallback), e.g. protocol-relative URLs (//cdn.example.com/...) and data URIs (data:application/json;base64,...). Consider expanding this guard to detect any URL scheme (e.g. ^[a-zA-Z][a-zA-Z\\d+.-]*:) and protocol-relative // in addition to upath.isAbsolute(...), so these cases get skipped too.
| // Skip absolute URLs and absolute paths — they can't be resolved to local files | |
| if (sourcemapUrl.includes('://') || upath.isAbsolute(sourcemapUrl)) { | |
| // Skip non-local URLs and absolute paths — they can't be resolved to local files | |
| const hasUrlScheme = /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(sourcemapUrl) | |
| const isProtocolRelative = sourcemapUrl.startsWith('//') | |
| if (hasUrlScheme || isProtocolRelative || upath.isAbsolute(sourcemapUrl)) { |
There was a problem hiding this comment.
https://tc39.es/ecma426 defines sourceMappingURL as a URL, which can either be relative or absolute. So there will be a :// protocol.
| if (sourcemapUrl.includes('://') || upath.isAbsolute(sourcemapUrl)) { | ||
| return undefined | ||
| } |
There was a problem hiding this comment.
This change adds a new branch for absolute paths via upath.isAbsolute(sourcemapUrl), but the added integration test only covers the absolute-URL case. Add a test fixture where //# sourceMappingURL=/sourcemaps/chunk.min.js.map (absolute path) is present and assert the command falls back to the legacy .js.map lookup, so both sides of this condition are covered.
buranmert
left a comment
There was a problem hiding this comment.
copilot has minor concerns but LGTM
Summary
Fixes a regression introduced in #2035 where
sourcemaps uploadfails to upload any sourcemaps when JS files contain an absolute URL in//# sourceMappingURL.Background
PR #2035 added
sourceMappingURLsupport: instead of relying on the legacy convention (foo.min.js→foo.min.js.map), the upload command now reads the//# sourceMappingURL=...comment from each JS file to locate its corresponding sourcemap. If this new method finds no results, it falls back to the legacy.js.maplookup.The problem
When
sourceMappingURLcontains an absolute URL (common with webpack/rspackSourceMapDevToolPluginwhenpublicPathis set to a CDN),upath.joinproduces an invalid local path:This path obviously doesn't exist on disk, so
validatePayloadskips it. But because thesourceMappingURLregex did match, the modern method returns a non-empty result set (of invalid entries), which means the legacy fallback is never triggered — resulting in zero sourcemaps uploaded.The fix
Skip
sourceMappingURLvalues that are absolute URLs (containing://) or absolute paths (starting with/), returningundefinedso they don't count as results. This allows the legacy.js.mapfallback to take over for these files.Examples
sourceMappingURLvaluechunk.min.js.map(relative)upath.join— works../maps/chunk.min.js.map(relative)upath.join— workshttps://cdn.example.com/sourcemaps/chunk.min.js.map(absolute URL)upath.joinproduces invalid path, blocks legacy fallback.js.maplookup/sourcemaps/chunk.min.js.map(absolute path)upath.joinproduces invalid path, blocks legacy fallback.js.maplookupTest plan
//# sourceMappingURL=https://cdn.example.com/sourcemaps/chunk.min.js.map