mirror of
https://github.com/nodejs/node.git
synced 2025-08-17 14:48:58 +02:00

Split the `internal/process/esm_loader` file which contains the singleton cascaded loader: - The the singleton cascaded loader now directly resides in `internal/modules/esm/loader`, where the constructor also lives. This file is the root of most circular dependency of ESM code, (because components of the loader need the singleton itself), so this makes the dependency more obvious. Added comments about loading it lazily to avoid circular dependency. - The getter to the cascaded loader is also turned into a method to make the side effect explicit. - The sequence of `loadESM()` and `handleMainPromise` is now merged together into `runEntryPointWithESMLoader()` in `internal/modules/run_main` because this is intended to run entry points with the ESM loader and not just any module. - Documents how top-level await is handled. PR-URL: https://github.com/nodejs/node/pull/51999 Fixes: https://github.com/nodejs/node/issues/42868 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
38 lines
1 KiB
JavaScript
38 lines
1 KiB
JavaScript
'use strict';
|
|
|
|
// Stdin is not a TTY, we will read it and execute it.
|
|
|
|
const {
|
|
prepareMainThreadExecution,
|
|
markBootstrapComplete,
|
|
} = require('internal/process/pre_execution');
|
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
const {
|
|
evalModuleEntryPoint,
|
|
evalScript,
|
|
readStdin,
|
|
} = require('internal/process/execution');
|
|
|
|
prepareMainThreadExecution();
|
|
markBootstrapComplete();
|
|
|
|
readStdin((code) => {
|
|
// This is necessary for fork() and CJS module compilation.
|
|
// TODO(joyeecheung): pass this with something really internal.
|
|
process._eval = code;
|
|
|
|
const print = getOptionValue('--print');
|
|
const shouldLoadESM = getOptionValue('--import').length > 0;
|
|
if (getOptionValue('--input-type') === 'module' ||
|
|
(getOptionValue('--experimental-default-type') === 'module' && getOptionValue('--input-type') !== 'commonjs')) {
|
|
evalModuleEntryPoint(code, print);
|
|
} else {
|
|
evalScript('[stdin]',
|
|
code,
|
|
getOptionValue('--inspect-brk'),
|
|
print,
|
|
shouldLoadESM);
|
|
}
|
|
});
|