mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c868aad15a
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: https://github.com/nodejs/single-executable/issues/69 Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: https://github.com/nodejs/node/pull/47779 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
const { Module: { createRequire } } = require('module');
|
|
const createdRequire = createRequire(__filename);
|
|
|
|
// Although, require('../common') works locally, that couldn't be used here
|
|
// because we set NODE_TEST_DIR=/Users/iojs/node-tmp on Jenkins CI.
|
|
const { expectWarning } = createdRequire(process.env.COMMON_DIRECTORY);
|
|
|
|
expectWarning('ExperimentalWarning',
|
|
'Single executable application is an experimental feature and ' +
|
|
'might change at any time');
|
|
|
|
// Should be possible to require core modules that optionally require the
|
|
// "node:" scheme.
|
|
const { deepStrictEqual, strictEqual, throws } = require('assert');
|
|
const { dirname } = require('node:path');
|
|
|
|
// Should be possible to require a core module that requires using the "node:"
|
|
// scheme.
|
|
{
|
|
const { test } = require('node:test');
|
|
strictEqual(typeof test, 'function');
|
|
}
|
|
|
|
// Should not be possible to require a core module without the "node:" scheme if
|
|
// it requires using the "node:" scheme.
|
|
throws(() => require('test'), {
|
|
code: 'ERR_UNKNOWN_BUILTIN_MODULE',
|
|
});
|
|
|
|
deepStrictEqual(process.argv, [process.execPath, process.execPath, '-a', '--b=c', 'd']);
|
|
|
|
strictEqual(require.cache, undefined);
|
|
strictEqual(require.extensions, undefined);
|
|
strictEqual(require.main, module);
|
|
strictEqual(require.resolve, undefined);
|
|
|
|
strictEqual(__filename, process.execPath);
|
|
strictEqual(__dirname, dirname(process.execPath));
|
|
strictEqual(module.exports, exports);
|
|
|
|
throws(() => require('./requirable.js'), {
|
|
code: 'ERR_UNKNOWN_BUILTIN_MODULE',
|
|
});
|
|
|
|
const requirable = createdRequire('./requirable.js');
|
|
deepStrictEqual(requirable, {
|
|
hello: 'world',
|
|
});
|
|
|
|
console.log('Hello, world! 😊');
|