Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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