Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/internal/bootstrap/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ defineOperation(globalThis, 'setTimeout', timers.setTimeout);
exposeLazyInterfaces(globalThis, 'internal/abort_controller', [
'AbortController', 'AbortSignal',
]);
exposeLazyInterfaces(globalThis, 'internal/event_target', [
'EventTarget', 'Event',
]);
const {
EventTarget, Event,
} = require('internal/event_target');
exposeInterface(globalThis, 'Event', Event);
exposeInterface(globalThis, 'EventTarget', EventTarget);
exposeLazyInterfaces(globalThis, 'internal/worker/io', [
'MessageChannel', 'MessagePort', 'MessageEvent',
]);
Expand Down
28 changes: 28 additions & 0 deletions lib/internal/bootstrap/switches/is_main_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,31 @@ rawMethods.resetStdioForTesting = function() {
stdout = undefined;
stderr = undefined;
};

// Needed by the module loader and generally needed everywhere.
require('fs');
require('util');

require('internal/modules/cjs/loader');
require('internal/modules/esm/utils');
require('internal/vm/module');
// Needed to refresh the time origin.
require('internal/perf/utils');
// Needed to register the async hooks.
if (internalBinding('config').hasInspector) {
require('internal/inspector_async_hook');
}
// Needed to set the wasm web API callbacks.
internalBinding('wasm_web_api');
// Needed to detect whether it's on main thread.
internalBinding('worker');
// Needed to setup source maps.
require('internal/source_map/source_map_cache');
// Needed by most execution modes.
require('internal/modules/run_main');
// Needed to refresh DNS configurations.
require('internal/dns/utils');
// Needed by almost all execution modes. It's fine to
// load them into the snapshot as long as we don't run
// any of the initialization.
require('internal/process/pre_execution');
6 changes: 3 additions & 3 deletions lib/internal/main/check_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function loadESMIfNeeded(cb) {
const hasModulePreImport = getOptionValue('--import').length > 0;

if (hasModulePreImport) {
const { loadESM } = require('internal/process/esm_loader');
const { loadESM } = require('internal/modules/esm/cascaded_loader');
loadESM(cb);
return;
}
Expand All @@ -65,7 +65,7 @@ async function checkSyntax(source, filename) {
isModule = getOptionValue('--input-type') === 'module';
} else {
const { defaultResolve } = require('internal/modules/esm/resolve');
const { defaultGetFormat } = require('internal/modules/esm/get_format');
const { defaultGetFormat } = require('internal/modules/esm/utils');
const { url } = await defaultResolve(pathToFileURL(filename).toString());
const format = await defaultGetFormat(url);
isModule = format === 'module';
Expand All @@ -77,7 +77,7 @@ async function checkSyntax(source, filename) {
return;
}

const { loadESM } = require('internal/process/esm_loader');
const { loadESM } = require('internal/modules/esm/cascaded_loader');
const { handleMainPromise } = require('internal/modules/run_main');
handleMainPromise(loadESM((loader) => wrapSafe(filename, source)));
}
2 changes: 1 addition & 1 deletion lib/internal/main/eval_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
markBootstrapComplete
} = require('internal/process/pre_execution');
const { evalModule, evalScript } = require('internal/process/execution');
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');
const { addBuiltinLibsToObject } = require('internal/modules/cjs/loader');

const { getOptionValue } = require('internal/options');

Expand Down
3 changes: 1 addition & 2 deletions lib/internal/main/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ if (process.env.NODE_REPL_EXTERNAL_MODULE) {
process.exit(kGenericUserError);
}

const esmLoader = require('internal/process/esm_loader');
esmLoader.loadESM(() => {
require('internal/modules/esm/cascaded_loader').loadESM(() => {
console.log(`Welcome to Node.js ${process.version}.\n` +
'Type ".help" for more information.');

Expand Down
Loading