lib: restructure cjs and esm loaders
Create `lib/internal/modules` and restructure the module loaders to make the purpose of those files clearer. Also make it clear in the code that the object exported by `lib/internal/modules/cjs/loader.js` is `CJSModule` instead of the ambiguous `Module`. Before: ``` lib ├── ... ├── internal │ ├── loaders │ │ ├── CreateDynamicModule.js │ │ ├── DefaultResolve.js │ │ ├── Loader.js │ │ ├── ModuleJob.js │ │ ├── ModuleMap.js │ │ └── Translators.js │ └── module.js └── module.js ``` After: ``` lib ├── ... ├── internal │ ├── ... │ └── modules │ ├── cjs │ │ ├── helpers.js │ │ └── loader.js │ └── esm │ ├── CreateDynamicModule.js │ ├── DefaultResolve.js │ ├── Loader.js │ ├── ModuleJob.js │ ├── ModuleMap.js │ └── Translators.js └── module.js # deleted in this commit to work with git file mode ``` PR-URL: https://github.com/nodejs/node/pull/19177 Refs: https://github.com/nodejs/node/pull/19112 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
8484b40b3d
commit
c2b01881dc
@ -1,6 +1,7 @@
|
||||
// This file creates the internal module & binding loaders used by built-in
|
||||
// modules. In contrast, user land modules are loaded using
|
||||
// lib/module.js (CommonJS Modules) or lib/internal/loader/* (ES Modules).
|
||||
// lib/internal/modules/cjs/loader.js (CommonJS Modules) or
|
||||
// lib/internal/modules/esm/* (ES Modules).
|
||||
//
|
||||
// This file is compiled and run by node.cc before bootstrap/node.js
|
||||
// was called, therefore the loaders are bootstraped before we start to
|
||||
|
@ -112,7 +112,7 @@
|
||||
process.emitWarning(
|
||||
'The ESM module loader is experimental.',
|
||||
'ExperimentalWarning', undefined);
|
||||
NativeModule.require('internal/process/modules').setup();
|
||||
NativeModule.require('internal/process/esm_loader').setup();
|
||||
}
|
||||
|
||||
{
|
||||
@ -194,8 +194,10 @@
|
||||
preloadModules();
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END);
|
||||
|
||||
const internalModule = NativeModule.require('internal/module');
|
||||
internalModule.addBuiltinLibsToObject(global);
|
||||
const {
|
||||
addBuiltinLibsToObject
|
||||
} = NativeModule.require('internal/modules/cjs/helpers');
|
||||
addBuiltinLibsToObject(global);
|
||||
evalScript('[eval]');
|
||||
} else if (process.argv[1] && process.argv[1] !== '-') {
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START);
|
||||
@ -203,13 +205,13 @@
|
||||
const path = NativeModule.require('path');
|
||||
process.argv[1] = path.resolve(process.argv[1]);
|
||||
|
||||
const Module = NativeModule.require('module');
|
||||
const CJSModule = NativeModule.require('internal/modules/cjs/loader');
|
||||
|
||||
// check if user passed `-c` or `--check` arguments to Node.
|
||||
if (process._syntax_check_only != null) {
|
||||
const fs = NativeModule.require('fs');
|
||||
// read the source
|
||||
const filename = Module._resolveFilename(process.argv[1]);
|
||||
const filename = CJSModule._resolveFilename(process.argv[1]);
|
||||
const source = fs.readFileSync(filename, 'utf-8');
|
||||
checkScriptSyntax(source, filename);
|
||||
process.exit(0);
|
||||
@ -220,7 +222,7 @@
|
||||
preloadModules();
|
||||
perf.markMilestone(
|
||||
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END);
|
||||
Module.runMain();
|
||||
CJSModule.runMain();
|
||||
} else {
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START);
|
||||
perf.markMilestone(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END);
|
||||
@ -345,7 +347,7 @@
|
||||
|
||||
function setupGlobalConsole() {
|
||||
const originalConsole = global.console;
|
||||
const Module = NativeModule.require('module');
|
||||
const CJSModule = NativeModule.require('internal/modules/cjs/loader');
|
||||
// Setup Node.js global.console
|
||||
const wrappedConsole = NativeModule.require('console');
|
||||
Object.defineProperty(global, 'console', {
|
||||
@ -353,7 +355,7 @@
|
||||
enumerable: false,
|
||||
value: wrappedConsole
|
||||
});
|
||||
setupInspector(originalConsole, wrappedConsole, Module);
|
||||
setupInspector(originalConsole, wrappedConsole, CJSModule);
|
||||
}
|
||||
|
||||
function setupGlobalURL() {
|
||||
@ -374,19 +376,20 @@
|
||||
});
|
||||
}
|
||||
|
||||
function setupInspector(originalConsole, wrappedConsole, Module) {
|
||||
function setupInspector(originalConsole, wrappedConsole, CJSModule) {
|
||||
if (!process.config.variables.v8_enable_inspector) {
|
||||
return;
|
||||
}
|
||||
const { addCommandLineAPI, consoleCall } = process.binding('inspector');
|
||||
// Setup inspector command line API
|
||||
const { makeRequireFunction } = NativeModule.require('internal/module');
|
||||
const { makeRequireFunction } =
|
||||
NativeModule.require('internal/modules/cjs/helpers');
|
||||
const path = NativeModule.require('path');
|
||||
const cwd = tryGetCwd(path);
|
||||
|
||||
const consoleAPIModule = new Module('<inspector console>');
|
||||
const consoleAPIModule = new CJSModule('<inspector console>');
|
||||
consoleAPIModule.paths =
|
||||
Module._nodeModulePaths(cwd).concat(Module.globalPaths);
|
||||
CJSModule._nodeModulePaths(cwd).concat(CJSModule.globalPaths);
|
||||
addCommandLineAPI('require', makeRequireFunction(consoleAPIModule));
|
||||
const config = {};
|
||||
for (const key of Object.keys(wrappedConsole)) {
|
||||
@ -515,13 +518,13 @@
|
||||
}
|
||||
|
||||
function evalScript(name) {
|
||||
const Module = NativeModule.require('module');
|
||||
const CJSModule = NativeModule.require('internal/modules/cjs/loader');
|
||||
const path = NativeModule.require('path');
|
||||
const cwd = tryGetCwd(path);
|
||||
|
||||
const module = new Module(name);
|
||||
const module = new CJSModule(name);
|
||||
module.filename = path.join(cwd, name);
|
||||
module.paths = Module._nodeModulePaths(cwd);
|
||||
module.paths = CJSModule._nodeModulePaths(cwd);
|
||||
const body = wrapForBreakOnFirstLine(process._eval);
|
||||
const script = `global.__filename = ${JSON.stringify(name)};\n` +
|
||||
'global.exports = exports;\n' +
|
||||
@ -540,21 +543,26 @@
|
||||
// Load preload modules
|
||||
function preloadModules() {
|
||||
if (process._preload_modules) {
|
||||
NativeModule.require('module')._preloadModules(process._preload_modules);
|
||||
const {
|
||||
_preloadModules
|
||||
} = NativeModule.require('internal/modules/cjs/loader');
|
||||
_preloadModules(process._preload_modules);
|
||||
}
|
||||
}
|
||||
|
||||
function checkScriptSyntax(source, filename) {
|
||||
const Module = NativeModule.require('module');
|
||||
const CJSModule = NativeModule.require('internal/modules/cjs/loader');
|
||||
const vm = NativeModule.require('vm');
|
||||
const internalModule = NativeModule.require('internal/module');
|
||||
const {
|
||||
stripShebang, stripBOM
|
||||
} = NativeModule.require('internal/modules/cjs/helpers');
|
||||
|
||||
// remove Shebang
|
||||
source = internalModule.stripShebang(source);
|
||||
source = stripShebang(source);
|
||||
// remove BOM
|
||||
source = internalModule.stripBOM(source);
|
||||
source = stripBOM(source);
|
||||
// wrap it
|
||||
source = Module.wrap(source);
|
||||
source = CJSModule.wrap(source);
|
||||
// compile the script, this will throw if it fails
|
||||
new vm.Script(source, { displayErrors: true, filename });
|
||||
}
|
||||
|
@ -35,7 +35,12 @@ const {
|
||||
internalModuleStat
|
||||
} = process.binding('fs');
|
||||
const { safeGetenv } = process.binding('util');
|
||||
const internalModule = require('internal/module');
|
||||
const {
|
||||
makeRequireFunction,
|
||||
requireDepth,
|
||||
stripBOM,
|
||||
stripShebang
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
const preserveSymlinks = !!process.binding('config').preserveSymlinks;
|
||||
const experimentalModules = !!process.binding('config').experimentalModules;
|
||||
|
||||
@ -48,9 +53,9 @@ const {
|
||||
module.exports = Module;
|
||||
|
||||
// these are below module.exports for the circular reference
|
||||
const internalESModule = require('internal/process/modules');
|
||||
const ModuleJob = require('internal/loader/ModuleJob');
|
||||
const createDynamicModule = require('internal/loader/CreateDynamicModule');
|
||||
const asyncESM = require('internal/process/esm_loader');
|
||||
const ModuleJob = require('internal/modules/esm/ModuleJob');
|
||||
const createDynamicModule = require('internal/modules/esm/CreateDynamicModule');
|
||||
const {
|
||||
CHAR_UPPERCASE_A,
|
||||
CHAR_LOWERCASE_A,
|
||||
@ -477,7 +482,7 @@ Module._load = function(request, parent, isMain) {
|
||||
}
|
||||
|
||||
if (experimentalModules && isMain) {
|
||||
internalESModule.loaderPromise.then((loader) => {
|
||||
asyncESM.loaderPromise.then((loader) => {
|
||||
return loader.import(getURLFromFilePath(request).pathname);
|
||||
})
|
||||
.catch((e) => {
|
||||
@ -583,7 +588,7 @@ Module.prototype.load = function(filename) {
|
||||
this.loaded = true;
|
||||
|
||||
if (experimentalModules) {
|
||||
const ESMLoader = internalESModule.ESMLoader;
|
||||
const ESMLoader = asyncESM.ESMLoader;
|
||||
const url = getURLFromFilePath(filename);
|
||||
const urlString = `${url}`;
|
||||
const exports = this.exports;
|
||||
@ -631,7 +636,7 @@ var resolvedArgv;
|
||||
// Returns exception, if any.
|
||||
Module.prototype._compile = function(content, filename) {
|
||||
|
||||
content = internalModule.stripShebang(content);
|
||||
content = stripShebang(content);
|
||||
|
||||
// create wrapper function
|
||||
var wrapper = Module.wrap(content);
|
||||
@ -660,8 +665,8 @@ Module.prototype._compile = function(content, filename) {
|
||||
}
|
||||
}
|
||||
var dirname = path.dirname(filename);
|
||||
var require = internalModule.makeRequireFunction(this);
|
||||
var depth = internalModule.requireDepth;
|
||||
var require = makeRequireFunction(this);
|
||||
var depth = requireDepth;
|
||||
if (depth === 0) stat.cache = new Map();
|
||||
var result;
|
||||
if (inspectorWrapper) {
|
||||
@ -679,7 +684,7 @@ Module.prototype._compile = function(content, filename) {
|
||||
// Native extension for .js
|
||||
Module._extensions['.js'] = function(module, filename) {
|
||||
var content = fs.readFileSync(filename, 'utf8');
|
||||
module._compile(internalModule.stripBOM(content), filename);
|
||||
module._compile(stripBOM(content), filename);
|
||||
};
|
||||
|
||||
|
||||
@ -687,7 +692,7 @@ Module._extensions['.js'] = function(module, filename) {
|
||||
Module._extensions['.json'] = function(module, filename) {
|
||||
var content = fs.readFileSync(filename, 'utf8');
|
||||
try {
|
||||
module.exports = JSON.parse(internalModule.stripBOM(content));
|
||||
module.exports = JSON.parse(stripBOM(content));
|
||||
} catch (err) {
|
||||
err.message = filename + ': ' + err.message;
|
||||
throw err;
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { URL } = require('url');
|
||||
const CJSmodule = require('module');
|
||||
const CJSmodule = require('internal/modules/cjs/loader');
|
||||
const internalFS = require('internal/fs');
|
||||
const { NativeModule, internalBinding } = require('internal/bootstrap/loaders');
|
||||
const { extname } = require('path');
|
@ -6,11 +6,11 @@ const {
|
||||
ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK,
|
||||
ERR_UNKNOWN_MODULE_FORMAT
|
||||
} = require('internal/errors').codes;
|
||||
const ModuleMap = require('internal/loader/ModuleMap');
|
||||
const ModuleJob = require('internal/loader/ModuleJob');
|
||||
const defaultResolve = require('internal/loader/DefaultResolve');
|
||||
const createDynamicModule = require('internal/loader/CreateDynamicModule');
|
||||
const translators = require('internal/loader/Translators');
|
||||
const ModuleMap = require('internal/modules/esm/ModuleMap');
|
||||
const ModuleJob = require('internal/modules/esm/ModuleJob');
|
||||
const defaultResolve = require('internal/modules/esm/DefaultResolve');
|
||||
const createDynamicModule = require('internal/modules/esm/CreateDynamicModule');
|
||||
const translators = require('internal/modules/esm/Translators');
|
||||
|
||||
const FunctionBind = Function.call.bind(Function.prototype.bind);
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const ModuleJob = require('internal/loader/ModuleJob');
|
||||
const ModuleJob = require('internal/modules/esm/ModuleJob');
|
||||
const { SafeMap } = require('internal/safe_globals');
|
||||
const debug = require('util').debuglog('esm');
|
||||
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
|
@ -2,10 +2,13 @@
|
||||
|
||||
const { NativeModule, internalBinding } = require('internal/bootstrap/loaders');
|
||||
const { ModuleWrap } = internalBinding('module_wrap');
|
||||
const internalCJSModule = require('internal/module');
|
||||
const CJSModule = require('module');
|
||||
const {
|
||||
stripShebang,
|
||||
stripBOM
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
const CJSModule = require('internal/modules/cjs/loader');
|
||||
const internalURLModule = require('internal/url');
|
||||
const createDynamicModule = require('internal/loader/CreateDynamicModule');
|
||||
const createDynamicModule = require('internal/modules/esm/CreateDynamicModule');
|
||||
const fs = require('fs');
|
||||
const { _makeLong } = require('path');
|
||||
const { SafeMap } = require('internal/safe_globals');
|
||||
@ -24,7 +27,7 @@ translators.set('esm', async (url) => {
|
||||
const source = `${await readFileAsync(new URL(url))}`;
|
||||
debug(`Translating StandardModule ${url}`);
|
||||
return {
|
||||
module: new ModuleWrap(internalCJSModule.stripShebang(source), url),
|
||||
module: new ModuleWrap(stripShebang(source), url),
|
||||
reflect: undefined
|
||||
};
|
||||
});
|
||||
@ -82,7 +85,7 @@ translators.set('json', async (url) => {
|
||||
const pathname = internalURLModule.getPathFromURL(new URL(url));
|
||||
const content = readFileSync(pathname, 'utf8');
|
||||
try {
|
||||
const exports = JsonParse(internalCJSModule.stripBOM(content));
|
||||
const exports = JsonParse(stripBOM(content));
|
||||
reflect.exports.default.set(exports);
|
||||
} catch (err) {
|
||||
err.message = pathname + ': ' + err.message;
|
@ -7,7 +7,7 @@ const {
|
||||
} = internalBinding('module_wrap');
|
||||
|
||||
const { getURLFromFilePath } = require('internal/url');
|
||||
const Loader = require('internal/loader/Loader');
|
||||
const Loader = require('internal/modules/esm/Loader');
|
||||
const path = require('path');
|
||||
const { URL } = require('url');
|
||||
|
23
lib/repl.js
23
lib/repl.js
@ -42,7 +42,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const internalModule = require('internal/module');
|
||||
const {
|
||||
builtinLibs,
|
||||
makeRequireFunction,
|
||||
addBuiltinLibsToObject
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
const { processTopLevelAwait } = require('internal/repl/await');
|
||||
const internalUtil = require('internal/util');
|
||||
const { isTypedArray } = require('internal/util/types');
|
||||
@ -55,7 +59,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { Interface } = require('readline');
|
||||
const { Console } = require('console');
|
||||
const Module = require('module');
|
||||
const CJSModule = require('internal/modules/cjs/loader');
|
||||
const domain = require('domain');
|
||||
const debug = util.debuglog('repl');
|
||||
const {
|
||||
@ -96,7 +100,7 @@ try {
|
||||
}
|
||||
|
||||
// Hack for repl require to work properly with node_modules folders
|
||||
module.paths = Module._nodeModulePaths(module.filename);
|
||||
module.paths = CJSModule._nodeModulePaths(module.filename);
|
||||
|
||||
// If obj.hasOwnProperty has been overridden, then calling
|
||||
// obj.hasOwnProperty(prop) will break.
|
||||
@ -112,7 +116,7 @@ writer.options = Object.assign({},
|
||||
util.inspect.defaultOptions,
|
||||
{ showProxy: true, depth: 2 });
|
||||
|
||||
exports._builtinLibs = internalModule.builtinLibs;
|
||||
exports._builtinLibs = builtinLibs;
|
||||
|
||||
function REPLServer(prompt,
|
||||
stream,
|
||||
@ -789,14 +793,15 @@ REPLServer.prototype.createContext = function() {
|
||||
}
|
||||
}
|
||||
|
||||
var module = new Module('<repl>');
|
||||
module.paths = Module._resolveLookupPaths('<repl>', parentModule, true) || [];
|
||||
var module = new CJSModule('<repl>');
|
||||
module.paths =
|
||||
CJSModule._resolveLookupPaths('<repl>', parentModule, true) || [];
|
||||
|
||||
var require = internalModule.makeRequireFunction(module);
|
||||
var require = makeRequireFunction(module);
|
||||
context.module = module;
|
||||
context.require = require;
|
||||
|
||||
internalModule.addBuiltinLibsToObject(context);
|
||||
addBuiltinLibsToObject(context);
|
||||
|
||||
return context;
|
||||
};
|
||||
@ -1005,7 +1010,7 @@ function complete(line, callback) {
|
||||
} else if (/^\.\.?\//.test(completeOn)) {
|
||||
paths = [process.cwd()];
|
||||
} else {
|
||||
paths = module.paths.concat(Module.globalPaths);
|
||||
paths = module.paths.concat(CJSModule.globalPaths);
|
||||
}
|
||||
|
||||
for (i = 0; i < paths.length; i++) {
|
||||
|
17
node.gyp
17
node.gyp
@ -104,17 +104,18 @@
|
||||
'lib/internal/http.js',
|
||||
'lib/internal/inspector_async_hook.js',
|
||||
'lib/internal/linkedlist.js',
|
||||
'lib/internal/loader/Loader.js',
|
||||
'lib/internal/loader/CreateDynamicModule.js',
|
||||
'lib/internal/loader/DefaultResolve.js',
|
||||
'lib/internal/loader/ModuleJob.js',
|
||||
'lib/internal/loader/ModuleMap.js',
|
||||
'lib/internal/loader/Translators.js',
|
||||
'lib/internal/modules/cjs/helpers.js',
|
||||
'lib/internal/modules/cjs/loader.js',
|
||||
'lib/internal/modules/esm/Loader.js',
|
||||
'lib/internal/modules/esm/CreateDynamicModule.js',
|
||||
'lib/internal/modules/esm/DefaultResolve.js',
|
||||
'lib/internal/modules/esm/ModuleJob.js',
|
||||
'lib/internal/modules/esm/ModuleMap.js',
|
||||
'lib/internal/modules/esm/Translators.js',
|
||||
'lib/internal/safe_globals.js',
|
||||
'lib/internal/net.js',
|
||||
'lib/internal/module.js',
|
||||
'lib/internal/os.js',
|
||||
'lib/internal/process/modules.js',
|
||||
'lib/internal/process/esm_loader.js',
|
||||
'lib/internal/process/next_tick.js',
|
||||
'lib/internal/process/promises.js',
|
||||
'lib/internal/process/stdio.js',
|
||||
|
@ -7,10 +7,10 @@
|
||||
const common = require('../common');
|
||||
|
||||
const { URL } = require('url');
|
||||
const Loader = require('internal/loader/Loader');
|
||||
const ModuleMap = require('internal/loader/ModuleMap');
|
||||
const ModuleJob = require('internal/loader/ModuleJob');
|
||||
const createDynamicModule = require('internal/loader/CreateDynamicModule');
|
||||
const Loader = require('internal/modules/esm/Loader');
|
||||
const ModuleMap = require('internal/modules/esm/ModuleMap');
|
||||
const ModuleJob = require('internal/modules/esm/ModuleJob');
|
||||
const createDynamicModule = require('internal/modules/esm/CreateDynamicModule');
|
||||
|
||||
const stubModuleUrl = new URL('file://tmp/test');
|
||||
const stubModule = createDynamicModule(['default'], stubModuleUrl);
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const { search } = require('internal/loader/DefaultResolve');
|
||||
const { search } = require('internal/modules/esm/DefaultResolve');
|
||||
|
||||
common.expectsError(
|
||||
() => search('target', undefined),
|
||||
|
10
test/fixtures/module-require-depth/one.js
vendored
10
test/fixtures/module-require-depth/one.js
vendored
@ -1,9 +1,11 @@
|
||||
// Flags: --expose_internals
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const internalModule = require('internal/module');
|
||||
const {
|
||||
requireDepth
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
|
||||
exports.requireDepth = internalModule.requireDepth;
|
||||
assert.strictEqual(internalModule.requireDepth, 1);
|
||||
exports.requireDepth = requireDepth;
|
||||
assert.strictEqual(requireDepth, 1);
|
||||
assert.deepStrictEqual(require('./two'), { requireDepth: 2 });
|
||||
assert.strictEqual(internalModule.requireDepth, 1);
|
||||
assert.strictEqual(requireDepth, 1);
|
||||
|
10
test/fixtures/module-require-depth/two.js
vendored
10
test/fixtures/module-require-depth/two.js
vendored
@ -1,9 +1,11 @@
|
||||
// Flags: --expose_internals
|
||||
'use strict';
|
||||
const assert = require('assert');
|
||||
const internalModule = require('internal/module');
|
||||
const {
|
||||
requireDepth
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
|
||||
exports.requireDepth = internalModule.requireDepth;
|
||||
assert.strictEqual(internalModule.requireDepth, 2);
|
||||
exports.requireDepth = requireDepth;
|
||||
assert.strictEqual(requireDepth, 2);
|
||||
assert.deepStrictEqual(require('./one'), { requireDepth: 1 });
|
||||
assert.strictEqual(internalModule.requireDepth, 2);
|
||||
assert.strictEqual(requireDepth, 2);
|
||||
|
@ -6,10 +6,10 @@ RangeError: Invalid input
|
||||
at error (punycode.js:42:*)
|
||||
at Object.decode (punycode.js:*:*)
|
||||
at Object.<anonymous> (*test*message*core_line_numbers.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Object.Module._extensions..js (module.js:*:*)
|
||||
at Module.load (module.js:*:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
|
@ -5,11 +5,11 @@ assert.js:*
|
||||
|
||||
AssertionError [ERR_ASSERTION]: 1 strictEqual 2
|
||||
at Object.<anonymous> (*test*message*error_exit.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Object.Module._extensions..js (module.js:*:*)
|
||||
at Module.load (module.js:*:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
|
@ -3,4 +3,4 @@ file:///*/test/message/esm_display_syntax_error.mjs:3
|
||||
await async () => 0;
|
||||
^^^^^
|
||||
SyntaxError: Unexpected reserved word
|
||||
at translators.set (internal/loader/Translators.js:*:*)
|
||||
at translators.set (internal/modules/esm/Translators.js:*:*)
|
||||
|
@ -3,4 +3,4 @@ file:///*/test/message/esm_display_syntax_error_import.mjs:6
|
||||
notfound
|
||||
^^^^^^^^
|
||||
SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-exports' does not provide an export named 'notfound'
|
||||
at ModuleJob._instantiate (internal/loader/ModuleJob.js:*:*)
|
||||
at ModuleJob._instantiate (internal/modules/esm/ModuleJob.js:*:*)
|
||||
|
@ -3,4 +3,4 @@ file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1
|
||||
import { foo, notfound } from './module-named-exports';
|
||||
^^^^^^^^
|
||||
SyntaxError: The requested module './module-named-exports' does not provide an export named 'notfound'
|
||||
at ModuleJob._instantiate (internal/loader/ModuleJob.js:*:*)
|
||||
at ModuleJob._instantiate (internal/modules/esm/ModuleJob.js:*:*)
|
||||
|
@ -3,4 +3,4 @@ file:///*/test/fixtures/es-module-loaders/syntax-error.mjs:2
|
||||
await async () => 0;
|
||||
^^^^^
|
||||
SyntaxError: Unexpected reserved word
|
||||
at translators.set (internal/loader/Translators.js:*:*)
|
||||
at translators.set (internal/modules/esm/Translators.js:*:*)
|
||||
|
@ -7,7 +7,7 @@ SyntaxError: Strict mode code may not include a with statement
|
||||
at createScript (vm.js:*:*)
|
||||
at Object.runInThisContext (vm.js:*:*)
|
||||
at Object.<anonymous> ([eval]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
@ -22,7 +22,7 @@ Error: hello
|
||||
at Script.runInThisContext (vm.js:*:*)
|
||||
at Object.runInThisContext (vm.js:*:*)
|
||||
at Object.<anonymous> ([eval]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
@ -36,7 +36,7 @@ Error: hello
|
||||
at Script.runInThisContext (vm.js:*:*)
|
||||
at Object.runInThisContext (vm.js:*:*)
|
||||
at Object.<anonymous> ([eval]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
@ -50,7 +50,7 @@ ReferenceError: y is not defined
|
||||
at Script.runInThisContext (vm.js:*:*)
|
||||
at Object.runInThisContext (vm.js:*:*)
|
||||
at Object.<anonymous> ([eval]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
|
@ -6,17 +6,17 @@ Error: foo:bar
|
||||
at bar (*events_unhandled_error_common_trace.js:*:*)
|
||||
at foo (*events_unhandled_error_common_trace.js:*:*)
|
||||
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Object.Module._extensions..js (module.js:*:*)
|
||||
at Module.load (module.js:*:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
Emitted 'error' event at:
|
||||
at quux (*events_unhandled_error_common_trace.js:*:*)
|
||||
at Object.<anonymous> (*events_unhandled_error_common_trace.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
[... lines matching original stack trace ...]
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
|
@ -4,17 +4,17 @@ events.js:*
|
||||
|
||||
Error
|
||||
at Object.<anonymous> (*events_unhandled_error_nexttick.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Object.Module._extensions..js (module.js:*:*)
|
||||
at Module.load (module.js:*:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
Emitted 'error' event at:
|
||||
at process.nextTick (*events_unhandled_error_nexttick.js:*:*)
|
||||
at process._tickCallback (internal/process/next_tick.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
|
@ -4,16 +4,16 @@ events.js:*
|
||||
|
||||
Error
|
||||
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Object.Module._extensions..js (module.js:*:*)
|
||||
at Module.load (module.js:*:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
Emitted 'error' event at:
|
||||
at Object.<anonymous> (*events_unhandled_error_sameline.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
[... lines matching original stack trace ...]
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
|
@ -11,9 +11,9 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
|
||||
at b (*if-error-has-good-stack.js:*:*)
|
||||
at a (*if-error-has-good-stack.js:*:*)
|
||||
at Object.<anonymous> (*if-error-has-good-stack.js:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Object.Module._extensions..js (module.js:*:*)
|
||||
at Module.load (module.js:*:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
|
@ -5,6 +5,6 @@
|
||||
ReferenceError: undefined_reference_error_maker is not defined
|
||||
at *test*message*nexttick_throw.js:*:*
|
||||
at process._tickCallback (internal/process/next_tick.js:*:*)
|
||||
at Function.Module.runMain (module.js:*:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
|
||||
at startup (internal/bootstrap/node.js:*:*)
|
||||
at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*)
|
||||
|
@ -7,7 +7,7 @@ SyntaxError: Strict mode code may not include a with statement
|
||||
at createScript (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> ([stdin]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
|
||||
at Socket.emit (events.js:*:*)
|
||||
@ -24,7 +24,7 @@ Error: hello
|
||||
at Script.runInThisContext (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> ([stdin]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
|
||||
at Socket.emit (events.js:*:*)
|
||||
@ -39,7 +39,7 @@ Error: hello
|
||||
at Script.runInThisContext (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> ([stdin]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
|
||||
at Socket.emit (events.js:*:*)
|
||||
@ -55,7 +55,7 @@ ReferenceError: y is not defined
|
||||
at Script.runInThisContext (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> ([stdin]-wrapper:*:*)
|
||||
at Module._compile (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*:*)
|
||||
at evalScript (internal/bootstrap/node.js:*:*)
|
||||
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
|
||||
at Socket.emit (events.js:*:*)
|
||||
|
@ -9,8 +9,8 @@ ReferenceError: foo is not defined
|
||||
at Script.runInNewContext (vm.js:*)
|
||||
at Object.runInNewContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*undefined_reference_in_new_context.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at *..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at *..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
|
||||
|
@ -8,12 +8,12 @@ Error: boo!
|
||||
at Script.runInThisContext (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*vm_display_runtime_error.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at Object.Module._extensions..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*)
|
||||
at Function.Module.runMain (module.js:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
|
||||
test.vm:1
|
||||
throw new Error("spooky!")
|
||||
^
|
||||
@ -23,9 +23,9 @@ Error: spooky!
|
||||
at Script.runInThisContext (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*vm_display_runtime_error.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at Object.Module._extensions..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*)
|
||||
at Function.Module.runMain (module.js:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
|
||||
|
@ -7,12 +7,12 @@ SyntaxError: Unexpected number
|
||||
at createScript (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*vm_display_syntax_error.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at Object.Module._extensions..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*)
|
||||
at Function.Module.runMain (module.js:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
|
||||
test.vm:1
|
||||
var 5;
|
||||
^
|
||||
@ -21,9 +21,9 @@ SyntaxError: Unexpected number
|
||||
at createScript (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*vm_display_syntax_error.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at Object.Module._extensions..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*)
|
||||
at Function.Module.runMain (module.js:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
|
||||
|
@ -9,9 +9,9 @@ Error: boo!
|
||||
at Script.runInThisContext (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*vm_dont_display_runtime_error.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at Object.Module._extensions..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*)
|
||||
at Function.Module.runMain (module.js:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
|
||||
|
@ -9,9 +9,9 @@ SyntaxError: Unexpected number
|
||||
at createScript (vm.js:*)
|
||||
at Object.runInThisContext (vm.js:*)
|
||||
at Object.<anonymous> (*test*message*vm_dont_display_syntax_error.js:*)
|
||||
at Module._compile (module.js:*)
|
||||
at Object.Module._extensions..js (module.js:*)
|
||||
at Module.load (module.js:*)
|
||||
at tryModuleLoad (module.js:*:*)
|
||||
at Function.Module._load (module.js:*)
|
||||
at Function.Module.runMain (module.js:*)
|
||||
at Module._compile (internal/modules/cjs/loader.js:*)
|
||||
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*)
|
||||
at Module.load (internal/modules/cjs/loader.js:*)
|
||||
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
|
||||
at Function.Module._load (internal/modules/cjs/loader.js:*)
|
||||
at Function.Module.runMain (internal/modules/cjs/loader.js:*)
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const ModuleMap = require('internal/loader/ModuleMap');
|
||||
const ModuleMap = require('internal/modules/esm/ModuleMap');
|
||||
|
||||
// ModuleMap.get, ModuleMap.has and ModuleMap.set should only accept string
|
||||
// values as url argument.
|
||||
|
@ -3,7 +3,7 @@
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const stripShebang = require('internal/module').stripShebang;
|
||||
const stripShebang = require('internal/modules/cjs/helpers').stripShebang;
|
||||
|
||||
[
|
||||
['', ''],
|
||||
|
@ -3,12 +3,14 @@
|
||||
require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const assert = require('assert');
|
||||
const internalModule = require('internal/module');
|
||||
const {
|
||||
requireDepth
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
|
||||
// Module one loads two too so the expected depth for two is, well, two.
|
||||
assert.strictEqual(internalModule.requireDepth, 0);
|
||||
assert.strictEqual(requireDepth, 0);
|
||||
const one = require(fixtures.path('module-require-depth', 'one'));
|
||||
const two = require(fixtures.path('module-require-depth', 'two'));
|
||||
assert.deepStrictEqual(one, { requireDepth: 1 });
|
||||
assert.deepStrictEqual(two, { requireDepth: 2 });
|
||||
assert.strictEqual(internalModule.requireDepth, 0);
|
||||
assert.strictEqual(requireDepth, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user