Skip to content

Commit

Permalink
sea: allow requiring core modules with the "node:" prefix
Browse files Browse the repository at this point in the history
Previously, the `require()` function exposed to the embedded SEA code
was calling the internal `require()` function if the module name
belonged to the list of public core modules but the internal `require()`
function does not support loading modules with the "node:" prefix, so
this change forwards the calls to another `require()` function that
supports this.

Fixes: nodejs/single-executable#69
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Apr 29, 2023
1 parent c968361 commit 614323f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/internal/util/embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ function embedderRunCjs(contents) {
customDirname);
}

let embedderRequireInternal;

function embedderRequire(path) {
if (!Module.isBuiltin(path)) {
throw new ERR_UNKNOWN_BUILTIN_MODULE(path);
}

return require(path);
if (!embedderRequireInternal) {
embedderRequireInternal = Module.createRequire(process.execPath);
}

return embedderRequireInternal(path);
}

module.exports = { embedderRequire, embedderRunCjs };
2 changes: 1 addition & 1 deletion test/fixtures/sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expectWarning('ExperimentalWarning',
'might change at any time');

const { deepStrictEqual, strictEqual, throws } = require('assert');
const { dirname } = require('path');
const { dirname } = require('node:path');

deepStrictEqual(process.argv, [process.execPath, process.execPath, '-a', '--b=c', 'd']);

Expand Down

0 comments on commit 614323f

Please sign in to comment.