fix: resolve relative sourceMappingURL against local path when remoteRoot/localRoot is set#2345
Open
chrisdp wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: resolve relative sourceMappingURL against local path when remoteRoot/localRoot is set#2345chrisdp wants to merge 1 commit intomicrosoft:mainfrom
chrisdp wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…Root/localRoot is set When a script is translated via remoteRoot/localRoot and its sourceMappingURL navigates outside the remoteRoot subtree, the resolved map URL pointed to a non-existent device path instead of the locally-translated equivalent. Fix: after urlToAbsolutePath produces a local absolutePath for the script, re-resolve a relative sourceMapURL against that local path so the source map can be found regardless of where it sits relative to remoteRoot.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When using
remoteRoot/localRootto debug a script on a remote device, a relativesourceMappingURLthat navigates outside theremoteRootsubtree fails to load with ENOENT.Root cause:
sourceMapURLis resolved against the raw remote script URI beforeremoteRoot/localRootpath translation is applied. If the resolved path doesn't start withremoteRoot, no translation is applied and js-debug tries to open a non-existent device path as a local file.Example: with
remoteRoot: .../remote,localRoot: .../local, andsourceMappingURL: ../maps/index.js.mapinremote/index.js:The correct resolution uses the locally-translated script path as the base:
Fix
In
SourceContainer.addSource, afterurlToAbsolutePathproduces the locally-translatedabsolutePathfor the script, re-resolve a relativesourceMapURLagainst that local path. This only applies when:absolutePathis non-empty (translation actually happened)event.urlis afile://URL (excludes http/webpack dev-server cases where the map must be fetched from the remote server)sourceMapURLis not a data URIAbsolute
sourceMapURLs are unaffected —completeUrlignores the base when the input is already an absolute URL.This also fixes the secondary effect where
absSourceRootwas derived from the remote script dirname instead of the local one, causing TypeScript source paths to resolve to nonexistent locations.Test
Added an integration test that creates this fixture layout:
With
remoteRoot: .../remoteandlocalRoot: .../local, the golden file asserts the stack frame referenceslocal/src/index.js(the mapped original source). Without the fix, the source map isn't found and the frame falls back to the compiled path.Related issues