Skip to content

Commit

Permalink
Attempt workaround for node regression (#1838)
Browse files Browse the repository at this point in the history
* attempt workaround for node regression

* lint-fix

* fix
  • Loading branch information
cspotcode authored Jul 14, 2022
1 parent 11424e0 commit c02af13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions dist-raw/runmain-hack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {pathToFileURL} = require('url');

// Hack to avoid Module.runMain on node 18.6.0
// Keeping it simple for now, isolated in this file.
// Could theoretically probe `getFormat` impl to determine if `import()` or `Module._load()` is best
// Note that I attempted a try-catch around `Module._load`, but it poisons some sort of cache such that subsequent `import()` is impossible.
exports.run = function(entryPointPath) {
import(pathToFileURL(entryPointPath));
}
10 changes: 9 additions & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,15 @@ function phase4(payload: BootstrapState) {

// Execute the main contents (either eval, script or piped).
if (executeEntrypoint) {
Module.runMain();
if (
payload.isInChildProcess &&
versionGteLt(process.versions.node, '18.6.0')
) {
// HACK workaround node regression
require('../dist-raw/runmain-hack.js').run(entryPointPath);
} else {
Module.runMain();
}
} else {
// Note: eval and repl may both run, but never with stdin.
// If stdin runs, eval and repl will not.
Expand Down

0 comments on commit c02af13

Please sign in to comment.