-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don’t patch Error.prepareStackTrace
if --enable-source-maps
is used.
#5403
Conversation
It looks like |
Tests also pass on |
Node |
Error.prepareStackTrace
if --enable-source-maps
is used.
If you don’t mind updating with the latest |
- Added check to not patch `Error.prepareStackTrace` if it has already been patched by another library. - Always attach inline source maps if `--enable-source-map` is set. - Added some basic tests for stack trace.
50dfa8e
to
85cc164
Compare
test/sourcemap.coffee
Outdated
if process.version.split(".")[0] != "v12" | ||
test "native source maps", -> | ||
new Promise (resolve, reject) -> | ||
proc = spawn "node", [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use child_process.fork
to specifically spawn Node child processes: https://nodejs.org/api/child_process.html#:~:text=The%20child_process.fork()%20method%20is%20a%20special%20case%20of%20child_process.spawn()%20used%20specifically%20to%20spawn%20new%20Node.js%20processes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you used fork
in the above test but spawn
here?
Co-authored-by: Geoffrey Booth <[email protected]>
I'm pretty happy with how this is functionally. There's some more clean up and testing that can be followed up with but I'm fairly confident that this will maintain the existing functionality while fixing the two cases where patching |
There's actually one other case that this doesn't address correctly yet: when The fix is to move the logic into |
`path.relative` doesn't include a trailing separator which causes source maps to have an inaccurate file path when using `--enable-source-maps` in node.
Please let me know when you’re done working on this branch and I’ll review it again. Please don’t forget the style notes (single-quoted strings unless interpolating, avoid single-character variables). |
I'll get a few more updates in and summarize the changes as well over the next few days. |
@GeoffreyBooth this is ready for review now. It's a bit larger than I originally anticipated. Please ask any questions you have so I can better document exactly what changed and how things work. I'm not sure why the CI is flaky on windows but I should look into that before this is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very good! A few notes here and there and this should be ready to land.
Does this fix #5216 by chance? From a quick search of open issues, that appears to be the only other open issue related to source maps.
exports.anonymousFileName = do -> | ||
n = 0 | ||
-> | ||
"<anonymous-#{n++}>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use square brackets (like [anonymous-0]
) to match [stdin]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was previously <anonymous>
which matches the "filename" of Node's eval
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which matches the “filename” of Node’s
eval
.
That’s fine; do you mind sharing where you see that in Node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node
Welcome to Node.js v17.9.0.
Type ".help" for more information.
> eval("throw new Error")
Uncaught Error
at eval (eval at <anonymous> (REPL1:1:1), <anonymous>:1:7)
>
test/sourcemap.coffee
Outdated
if process.version.split(".")[0] != "v12" | ||
test "native source maps", -> | ||
new Promise (resolve, reject) -> | ||
proc = spawn "node", [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you used fork
in the above test but spawn
here?
One thing to note is that though this does fix a bug/unexpected behavior it could be considered a breaking change to how CoffeeScript = require('coffeescript')
CoffeeScript.patchStackTrace() |
I thought the intent was to keep the current behavior unless |
I think that the correct long term solution is to not do anything drastic to people's environments when If that is too breaking a change to go out soon then I can update the PR to also have |
I thought the current behavior was not to patch unless If so, yeah, we should restrict the patching to |
👍 The current behavior in coffeescript/src/coffeescript.coffee Line 368 in 76cf769
This PR restricts the patching to |
sourceURL = "//# sourceURL=#{filename}" | ||
js = "#{js}\n#{sourceMapDataURI}\n#{sourceURL}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, not as part of this PR but related: #5237
Thanks @STRd6 and congrats! We’re overdue for a release, are there any other PRs you’d like to land soon or should I prepare a release for later this week? |
@GeoffreyBooth thanks for the review! I don't have anything else ready to land so release when ready 👍 |
Fixes #5382 Don't monkey patch
Error.prepareStackTrace
if--enable-source-maps
is used.This ended up being kind of a chonker but I'm pretty happy with the overall structure. Also a little terrified with how much this touches, as well as a little relieved that there are tons of existing tests to catch regressions 😅
In summary:
require('coffeescript')
no longer patchesError.prepareStackTrace
. People mustrequire('coffeescript/register')
to opt-in.CoffeeScript.run
already does this which will maintain the existingcoffee
cli experience.Error.prepareStackTrace
is not patched if another library has already patched it even when callingrequire('coffeescript/register')
.Error.prepareStackTrace
patching incoffeescript.coffee
is now exported rather than applied automatically.register.coffee
imports it. The browser docs also call it directly.sourcemap.coffee
(not sure if this is the ideal place).<anonymous>
name.getSourceMap
andregisterCompiled
much simpler.registerCompiled
so other tools can cache source maps and hook into CoffeeScript stack remapping (CoffeeCoverage, etc.)helpers.syntaxErrorToString
to print[stdin]
for<anonymous.*
files as well as files with undefined file name to match the existing tests.index.coffee
CoffeeScript.run
setinlineMap
to be true and set the baseoption.filename
to match themainModule
filename.TODO
CoffeeScript.compile
always caches source maps if present. This makes the call toregisterCompiled
inregister.coffee
redundant. Need to do some thinking about how to untangle this../bin/coffee --nodejs --enable-source-maps test/importing/error.coffee
(Looks like file path is currently incorrect:C:\Users\duder\Documents\GitHub\coffeescript\test\..test\importing\error.coffee:3:9
)