Add support for proper handling of file protocol (in windows) #201
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.
Trying to debug node with DevTools with transpiled code on Windows is a mess. First, this is not the fault of node-source-map-support at all. It works great on windows on its own. But the hacks necessary to get this to work do break node-source-map-support.
The basic problem is this: Node uses OS file paths, and DevTools doesn't understand OS file paths, it only understands URIs (including file:// URIs). So to actually get DevTools to comprehend source maps (so that you can set breakpoints and step through source code), you need to map your node modules to file:// URIs, so that DevTools can then do the relative path lookups to find your source maps/code. This means your modules that registered in Node need to have filenames like "file:///C:/dev/my-module.js". And this is where the most critical issue in node-source-map-support comes in:
supportRelativeURL
will break that up into "file://" and "/C:/dev/my-module.js" whichpath.resolve
incorrectly computes to something like "C:/C:/dev/module.js" (plus relative path). And becausesupportRelativeURL
can't be replaced by options, I think this actually needs to be fixed in node-source-map-support.I figured while I was fixing this, I would also fix the default retrieveFileHandler to be able to properly handle file:// support (since existsSync/readFileSync doesn't on its own). Although technically you can provide a custom file handler to override this, as a user.
If you are wondering how I map node modules to file:// URLs, in our application I have been monkey patching the
vm.runInThisContext
function:I suppose bonus support would be to actually add an option that does this for the user.
With this all in place, I now have the complete zen harmony of perfectly source-mapped modules in my stack traces and dev tools. I can set breakpoints in source code, I can click on stack traces, and go to the right source in dev tools. It all works beautifully.
I haven't done anything with tests. I wasn't sure how much of this would be willing to be accepted. Let me know if you want anything else for this PR.