Skip to content

Commit

Permalink
fix: prevent ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE
Browse files Browse the repository at this point in the history
fixes #248
  • Loading branch information
privatenumber committed Jun 9, 2024
1 parent c67d746 commit fb247eb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"exports": {
"./package.json": "./package.json",
".": "./dist/loader.mjs",
"./patch-repl": "./dist/patch-repl.cjs",
"./cjs": "./dist/cjs/index.cjs",
"./cjs/api": {
"import": {
Expand Down
2 changes: 0 additions & 2 deletions src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './patch-repl.js';

// Hook require() to transform to CJS
// eslint-disable-next-line import-x/no-unresolved
require('./cjs/index.cjs');
Expand Down
11 changes: 11 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ export const run = (
}
}

const shouldPatchRepl = argv.filter(flag => (flag !== '-i' && flag !== '--interactive')).length === 0;

return spawn(
process.execPath,
[
'--require',
require.resolve('./preflight.cjs'),

...(
shouldPatchRepl
? [
'--require',
require.resolve('./patch-repl.cjs'),
]
: []
),

isFeatureSupported(moduleRegister) ? '--import' : '--loader',
pathToFileURL(require.resolve('./loader.mjs')).toString(),

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export const files = {
!(typeof m.default === 'object' && ('default' in m.default)),
));
exports.named = 'named';
// https://github.com/privatenumber/tsx/issues/248
process.setUncaughtExceptionCaptureCallback(console.error);
`,

mjs: {
Expand Down

0 comments on commit fb247eb

Please sign in to comment.