-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor: redirect subsequent imports of "source-map-support" to this… #23
refactor: redirect subsequent imports of "source-map-support" to this… #23
Conversation
For hooking node's CommonJS resolver, I think we need to use What if someone does What if someone tries to Should this be opt-in via a flag? Or automatic? If the former, |
Done
For 1st one, the latest change already detects it correctly, for 2nd one though, that seems like an very unusual case for importing
Wouldn't that change the package
I'm fine with either, but given that doing nothing will cause source maps to be misaligned, I'd say to enable by default. |
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.
Although for ESM I don't know how to overwrite the imports (maybe at compile/transpile level?)
ts-node
can do that within its ESM loader hooks, but only if our loader hook is used, which only happens if the user passes --loader
. Instead, or in addition to the require.resolve
redirection, perhaps we should detect competing source-map-support
installations via Object.defineProperty
setters when we install our hooks.
Do we need to consider if a library may use 'source-map-support'
's API without calling install()
? In those cases, redirecting the require.resolve
is unnecessary.
Actually, that's exactly the case with
For this I don't know exactly what you suggest to apply, if it means the points you listed there: TypeStrong/ts-node#1441 (comment) then it will suffer the same issue as above, since the package could use other exports like |
I see, I'm not sure what it's doing to get access to raw stack frames. Is it failing because it does not have access to our |
I was thinking we can implement redirection from https://nodejs.org/dist/latest-v16.x/docs/api/esm.html#esm_resolve_specifier_context_defaultresolve |
I've inspected the usage and
So there's nothing to be done on this package for ESM support, but instead a PR on |
Yeah, the only thing this package might want to do is expose a I'm reviewing this pull request today and might push some code changes to your branch. |
Hello @cspotcode, were you able to check this PR? I'm using |
I looked at it briefly but have been swamped with my paycheck job. I hope
I'm able to make a ts-node release this weekend, and I can include these
changes when I do that.
…On Tue, Sep 28, 2021 at 11:40 AM ejose19 ***@***.***> wrote:
Hello @cspotcode <https://github.com/cspotcode>, were you able to check
this PR? I'm using ts-node & tslog on many projects and the invalid stack
traces surely makes debugging harder, I'd rather avoid installing a
previous version of ts-node or monkey-patching tslog just to get it
right, lmk if you need any other changes here.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OCTT4L427H2VJJCQY3UEHOYJANCNFSM5C7QMNGA>
.
|
Allow installers to be notified upon redirection so they can log warnings to users Allow installers to opt-out of redirection Support both entrypoints: source-map-support and source-map-support/register
Made some progress on this. I had to fix and merge #28 first. Then I had to merge those changes into #29. Kind of annoying, but I want to get all those changes together for the next version since they kinda overlap. I need to update this PR to store state on the |
Feel free to tackle the tasks listed in my previous comment, but if you don't have time, I will try to do them soon. |
Regarding the failing test I see some issues with the test or the behavior you want to implement:
So tell me what is the desired outcome (reuse already installed hook or always override) and I'll fix the test |
Ideally we keep the single hook, but with an array of So if there are 2x |
…tall` of request redirect
Ok, should be good now. Only thing I don't like much is the jsdoc type for |
Thanks, I'll take a look soon. Agreed about the jsdoc. Ideally, you're supposed to use |
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.
One more small change required; otherwise looks good. Thanks!
…alled on top if it
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.
I had to tweak the enabled
stuff but now looks good to go.
@ejose19 I just published ts-node 10.3.0 which includes this fix. Thanks again for fixing this, and if you hit any more issues please let me know. https://github.com/TypeStrong/ts-node/releases/tag/v10.3.0 |
@cspotcode I confirm it's working correctly now, thanks! |
This is a breaking change. I have an Angular CLI project that uses Karma to run tests. I wrote my Karma config in TypeScript, so Karma uses ts-node under the hood to transpile the config. Since the Angular CLI uses karma-source-map-support to load source-map-support, these changes break my tests because the symbol sourceMapSupport isn't defined anymore in the browser. For reference, the changes in this PR affect resolving the path to the source-map-support package, and later, constructing a path to the actual file, which is named differently in the two packages. Patching the names doesn't work anyway because the version in this repo is incompatible ("require is not defined" error). Not sure what to do. Is there any way to flex here, or should I pester Google? I don't know if anyone maintains karma-source-map-support anymore. |
Besides checking if you can just use this module instead of |
We could also add an option to disable ts-node's registration of source-map-support entirely. Related tickets, though each is slightly different: TypeStrong/ts-node#796 talks about turning off sourcemaps entirely, whereas I'm describing a feature that continues to generate sourcemaps but does not register source-map-support TypeStrong/ts-node#1473 talks about automatically skipping source-map-support installation when the user has node's |
I've created a ticket for the idea I've described above: TypeStrong/ts-node#1533 Pull requests and constructive criticism are welcome. |
… package
Fixes: TypeStrong/ts-node#1441
EDIT from @cspotcode: blocked by #28 because I think we'll need to be sure the shared state also tracks installation of the redirections in this ticket