From 4091cd0305d21ff559dee4c8a87cbefb58fc7373 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 13 Jul 2022 20:51:39 -0400 Subject: [PATCH 1/3] attempt workaround for node regression --- dist-raw/runmain-hack.js | 7 +++++++ src/bin.ts | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 dist-raw/runmain-hack.js diff --git a/dist-raw/runmain-hack.js b/dist-raw/runmain-hack.js new file mode 100644 index 000000000..7a742c505 --- /dev/null +++ b/dist-raw/runmain-hack.js @@ -0,0 +1,7 @@ +// 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(entryPointPath); +} diff --git a/src/bin.ts b/src/bin.ts index fb3208c48..e577f0c1c 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -639,7 +639,12 @@ 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. From 6a32783bf751bda044b2411f2c309dc0b1084f43 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 13 Jul 2022 20:54:59 -0400 Subject: [PATCH 2/3] lint-fix --- src/bin.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin.ts b/src/bin.ts index e577f0c1c..f470a2c83 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -639,7 +639,10 @@ function phase4(payload: BootstrapState) { // Execute the main contents (either eval, script or piped). if (executeEntrypoint) { - if(payload.isInChildProcess && versionGteLt(process.versions.node, '18.6.0')) { + if ( + payload.isInChildProcess && + versionGteLt(process.versions.node, '18.6.0') + ) { // HACK workaround node regression require('../dist-raw/runmain-hack.js').run(entryPointPath); } else { From 77bb2beb2fbd880aa5ca0792ed9f755af9b2ad5b Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 13 Jul 2022 21:11:33 -0400 Subject: [PATCH 3/3] fix --- dist-raw/runmain-hack.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dist-raw/runmain-hack.js b/dist-raw/runmain-hack.js index 7a742c505..6c0688e14 100644 --- a/dist-raw/runmain-hack.js +++ b/dist-raw/runmain-hack.js @@ -1,7 +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(entryPointPath); + import(pathToFileURL(entryPointPath)); }