mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
Remove `module.register()` (DEP0205), the `--experimental-loader` and `--loader` flags, and the machinery that supported them: the loader hooks worker thread, the hooks proxy, the async module customization hook chains for resolving and loading, the internal worker class used to run the loader thread, and the asynchronous module job linking. Module customization is now provided only by `module.registerHooks()`, which runs synchronously on the thread that loads the modules. As the loader thread no longer exists, the ES module loader always loads and links modules synchronously, so the code that handled promises and the re-invented `require()` for imported CommonJS customized by the async module customization hooks is removed too. `import()` still defers evaluation of the module to a later microtask, as before. `worker_threads.isInternalThread` is kept for compatibility and is now always `false`; removing it is left for a future semver-major change. The `ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED` and `ERR_LOADER_CHAIN_INCOMPLETE` error codes are no longer used and are documented as removed. Tests that exist only to exercise the async module customization hooks are removed. Assisted-by: Claude Signed-off-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: https://github.com/nodejs/node/pull/67090 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
79 lines
2.5 KiB
JavaScript
79 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
// User passed `-e` or `--eval` arguments to Node without `-i` or
|
|
// `--interactive`.
|
|
|
|
const {
|
|
ObjectDefineProperty,
|
|
RegExpPrototypeExec,
|
|
globalThis,
|
|
} = primordials;
|
|
|
|
const {
|
|
prepareMainThreadExecution,
|
|
markBootstrapComplete,
|
|
} = require('internal/process/pre_execution');
|
|
const {
|
|
evalModuleEntryPoint,
|
|
evalTypeScript,
|
|
parseAndEvalCommonjsTypeScript,
|
|
parseAndEvalModuleTypeScript,
|
|
evalScript,
|
|
} = require('internal/process/execution');
|
|
const { addBuiltinLibsToObject } = require('internal/modules/helpers');
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
prepareMainThreadExecution();
|
|
addBuiltinLibsToObject(globalThis, '<eval>');
|
|
markBootstrapComplete();
|
|
|
|
const code = getOptionValue('--eval');
|
|
|
|
const print = getOptionValue('--print');
|
|
const shouldLoadESM = getOptionValue('--import').length > 0;
|
|
const inputType = getOptionValue('--input-type');
|
|
const tsEnabled = getOptionValue('--strip-types');
|
|
if (inputType === 'module') {
|
|
evalModuleEntryPoint(code, print);
|
|
} else if (inputType === 'module-typescript' && tsEnabled) {
|
|
parseAndEvalModuleTypeScript(code, print);
|
|
} else {
|
|
// For backward compatibility, we want the identifier crypto to be the
|
|
// `node:crypto` module rather than WebCrypto.
|
|
const isUsingCryptoIdentifier = RegExpPrototypeExec(/\bcrypto\b/, code) !== null;
|
|
const shouldDefineCrypto = isUsingCryptoIdentifier && internalBinding('config').hasOpenSSL;
|
|
|
|
if (isUsingCryptoIdentifier && !shouldDefineCrypto) {
|
|
// This is taken from `addBuiltinLibsToObject`.
|
|
const object = globalThis;
|
|
const name = 'crypto';
|
|
const setReal = (val) => {
|
|
// Deleting the property before re-assigning it disables the
|
|
// getter/setter mechanism.
|
|
delete object[name];
|
|
object[name] = val;
|
|
};
|
|
ObjectDefineProperty(object, name, { __proto__: null, set: setReal });
|
|
}
|
|
|
|
let evalFunction;
|
|
if (inputType === 'commonjs') {
|
|
evalFunction = evalScript;
|
|
} else if (inputType === 'commonjs-typescript' && tsEnabled) {
|
|
evalFunction = parseAndEvalCommonjsTypeScript;
|
|
} else if (tsEnabled) {
|
|
evalFunction = evalTypeScript;
|
|
} else {
|
|
// Default to commonjs.
|
|
evalFunction = evalScript;
|
|
}
|
|
|
|
evalFunction('[eval]',
|
|
shouldDefineCrypto ? (
|
|
print ? `let crypto=require("node:crypto");{${code}}` : `(crypto=>{{${code}}})(require('node:crypto'))`
|
|
) : code,
|
|
getOptionValue('--inspect-brk'),
|
|
print,
|
|
shouldLoadESM);
|
|
}
|