runmain-hack.js 467 B

123456789
  1. const {pathToFileURL} = require('url');
  2. // Hack to avoid Module.runMain on node 18.6.0
  3. // Keeping it simple for now, isolated in this file.
  4. // Could theoretically probe `getFormat` impl to determine if `import()` or `Module._load()` is best
  5. // Note that I attempted a try-catch around `Module._load`, but it poisons some sort of cache such that subsequent `import()` is impossible.
  6. exports.run = function(entryPointPath) {
  7. import(pathToFileURL(entryPointPath));
  8. }