Skip to content
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

fix: lazy-load repl to avoid domain side effects #2025

Merged
merged 2 commits into from
May 30, 2023

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented May 23, 2023

Actually starting the repl will still put the process into domain-mode, but this at least allows programs to use ts-node or --loader=ts-node/esm without losing the ability to use process.setUncaughtExceptionCaptureCallback().

The problem should ideally be fixed (or mitigated) in node core, but this is still worthwhile for the benefit of supporting current node versions.

Re: nodejs/node#48131
Fix: #2024

Copy link
Collaborator

@cspotcode cspotcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one question about verbosity, that's it.

src/repl.ts Outdated
// Lazy-loaded to prevent repl's require('domain') from causing problems
// https://github.com/TypeStrong/ts-node/issues/2024
// https://github.com/nodejs/node/issues/48131
let nodeRepl: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we simplify to let nodeRepl: typeof _nodeRepl and then nodeRepl = require('repl')? No need to explicitly enumerate the properties we use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wasn't working, I think because it's exporting a namespace in @types/node, not an object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the * as is what I was lacking, thanks. Just doing import type nodeRepl from 'repl' is what didn't work.

Force-push updated to that, PTAL.

@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Merging #2025 (fed7d2b) into main (7af5c48) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
src/repl.ts 84.48% <100.00%> (+0.20%) ⬆️

Actually starting the repl will still put the process into domain-mode,
but this at least allows programs to use `ts-node` or
`--loader=ts-node/esm` without losing the ability to use
process.setUncaughtExceptionCaptureCallback().

The problem should ideally be fixed (or mitigated) in node core, but
this is still worthwhile for the benefit of supporting current node
versions.

Re: nodejs/node#48131
Fix: TypeStrong#2024
@isaacs isaacs force-pushed the isaacs/lazy-load-repl branch from ba747b2 to 82789ed Compare May 24, 2023 21:25
src/repl.ts Outdated Show resolved Hide resolved
@cspotcode
Copy link
Collaborator

Looks great, merged. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repl is loaded unconditionally, preventing uncaught exception capture
2 participants