From 3a48311046769dc74ed2ab381afab37dc218ac64 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 6 Mar 2018 22:42:32 +0800 Subject: [PATCH 1/4] src: put bootstrappers in lib/internal/bootstrap/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create `lib/internal/bootstrap/` and put bootstrappers there: Before: ``` lib/internal ├── ... ├── bootstrap_loaders.js └── bootstrap_node.js ``` After: ``` lib/internal ├── ... └── bootstrap ├── loaders.js └── node.js ``` --- lib/assert.js | 2 +- lib/buffer.js | 2 +- lib/domain.js | 2 +- .../loaders.js} | 8 ++--- .../{bootstrap_node.js => bootstrap/node.js} | 2 +- lib/internal/encoding.js | 2 +- lib/internal/loader/CreateDynamicModule.js | 2 +- lib/internal/loader/DefaultResolve.js | 2 +- lib/internal/loader/ModuleJob.js | 2 +- lib/internal/loader/Translators.js | 2 +- lib/internal/process/modules.js | 2 +- lib/internal/test/binding.js | 2 +- lib/internal/util/comparisons.js | 2 +- lib/internal/vm/Module.js | 2 +- lib/module.js | 2 +- lib/string_decoder.js | 2 +- lib/util.js | 2 +- node.gyp | 4 +-- src/node.cc | 34 ++++++++++--------- src/node_internals.h | 4 +-- src/node_url.cc | 2 +- test/message/core_line_numbers.out | 2 +- test/message/error_exit.out | 4 +-- test/message/eval_messages.out | 24 ++++++------- .../events_unhandled_error_common_trace.out | 6 ++-- .../events_unhandled_error_nexttick.out | 8 ++--- .../events_unhandled_error_sameline.out | 6 ++-- test/message/nexttick_throw.out | 4 +-- test/message/stdin_messages.out | 16 ++++----- .../test-loaders-hidden-from-users.js | 6 ++-- .../test-inspector-overwrite-config.js | 3 +- 31 files changed, 83 insertions(+), 80 deletions(-) rename lib/internal/{bootstrap_loaders.js => bootstrap/loaders.js} (97%) rename lib/internal/{bootstrap_node.js => bootstrap/node.js} (99%) diff --git a/lib/assert.js b/lib/assert.js index b0d0d9ab4c0e38..797252afc0e01e 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -36,7 +36,7 @@ const { openSync, closeSync, readSync } = require('fs'); const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn'); const { inspect } = require('util'); const { EOL } = require('os'); -const { NativeModule } = require('internal/bootstrap_loaders'); +const { NativeModule } = require('internal/bootstrap/loaders'); // Escape control characters but not \n and \t to keep the line breaks and // indentation intact. diff --git a/lib/buffer.js b/lib/buffer.js index 7703d2a129419f..b369d27a1ed471 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -41,7 +41,7 @@ const { // that test/parallel/test-buffer-bindingobj-no-zerofill.js is written. let isAnyArrayBuffer; try { - const { internalBinding } = require('internal/bootstrap_loaders'); + const { internalBinding } = require('internal/bootstrap/loaders'); isAnyArrayBuffer = internalBinding('types').isAnyArrayBuffer; } catch (e) { isAnyArrayBuffer = require('util').types.isAnyArrayBuffer; diff --git a/lib/domain.js b/lib/domain.js index e2cc38a1f9a1b4..170f29172788a4 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -34,7 +34,7 @@ const { ERR_UNHANDLED_ERROR } = require('internal/errors').codes; const { createHook } = require('async_hooks'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); // overwrite process.domain with a getter/setter that will allow for more // effective optimizations diff --git a/lib/internal/bootstrap_loaders.js b/lib/internal/bootstrap/loaders.js similarity index 97% rename from lib/internal/bootstrap_loaders.js rename to lib/internal/bootstrap/loaders.js index e409438dfcacfd..601c54a0cdbcd0 100644 --- a/lib/internal/bootstrap_loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -2,7 +2,7 @@ // modules. In contrast, user land modules are loaded using // lib/module.js (CommonJS Modules) or lib/internal/loader/* (ES Modules). // -// This file is compiled and run by node.cc before bootstrap_node.js +// This file is compiled and run by node.cc before bootstrap/node.js // was called, therefore the loaders are bootstraped before we start to // actually bootstrap Node.js. It creates the following objects: // @@ -29,7 +29,7 @@ // so they can be loaded faster without the cost of I/O. This class makes the // lib/internal/*, deps/internal/* modules and internalBinding() available by // default to core modules, and lets the core modules require itself via -// require('internal/bootstrap_loaders') even when this file is not written in +// require('internal/bootstrap/loaders') even when this file is not written in // CommonJS style. // // Other objects: @@ -111,7 +111,7 @@ // Think of this as module.exports in this file even though it is not // written in CommonJS style. const loaderExports = { internalBinding, NativeModule }; - const loaderId = 'internal/bootstrap_loaders'; + const loaderId = 'internal/bootstrap/loaders'; NativeModule.require = function(id) { if (id === loaderId) { return loaderExports; @@ -224,6 +224,6 @@ }; // This will be passed to the bootstrapNodeJSCore function in - // bootstrap_node.js. + // bootstrap/node.js. return loaderExports; }); diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap/node.js similarity index 99% rename from lib/internal/bootstrap_node.js rename to lib/internal/bootstrap/node.js index 6cdbebc0c125b5..67ec63eb01a1e5 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap/node.js @@ -5,7 +5,7 @@ // to the performance of the startup process, many dependencies are invoked // lazily. // -// Before this file is run, lib/internal/bootstrap_loaders.js gets run first +// Before this file is run, lib/internal/bootstrap/loaders.js gets run first // to bootstrap the internal binding and module loaders, including // process.binding(), process._linkedBinding(), internalBinding() and // NativeModule. And then { internalBinding, NativeModule } will be passed diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 1846fc552735a2..9cd47f861f908f 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -23,7 +23,7 @@ const { const { isArrayBufferView } = require('internal/util/types'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { isArrayBuffer } = internalBinding('types'); diff --git a/lib/internal/loader/CreateDynamicModule.js b/lib/internal/loader/CreateDynamicModule.js index 8c289171386a0d..7e9777af51ee2b 100644 --- a/lib/internal/loader/CreateDynamicModule.js +++ b/lib/internal/loader/CreateDynamicModule.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { ModuleWrap } = internalBinding('module_wrap'); const debug = require('util').debuglog('esm'); const ArrayJoin = Function.call.bind(Array.prototype.join); diff --git a/lib/internal/loader/DefaultResolve.js b/lib/internal/loader/DefaultResolve.js index f99e0c98b9271e..a012314d2a1e1a 100644 --- a/lib/internal/loader/DefaultResolve.js +++ b/lib/internal/loader/DefaultResolve.js @@ -3,7 +3,7 @@ const { URL } = require('url'); const CJSmodule = require('module'); const internalFS = require('internal/fs'); -const { NativeModule, internalBinding } = require('internal/bootstrap_loaders'); +const { NativeModule, internalBinding } = require('internal/bootstrap/loaders'); const { extname } = require('path'); const { realpathSync } = require('fs'); const preserveSymlinks = !!process.binding('config').preserveSymlinks; diff --git a/lib/internal/loader/ModuleJob.js b/lib/internal/loader/ModuleJob.js index 162b0504d3d313..d948252829ddbf 100644 --- a/lib/internal/loader/ModuleJob.js +++ b/lib/internal/loader/ModuleJob.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { ModuleWrap } = internalBinding('module_wrap'); const { SafeSet, SafePromise } = require('internal/safe_globals'); const { decorateErrorStack } = require('internal/util'); diff --git a/lib/internal/loader/Translators.js b/lib/internal/loader/Translators.js index 74dd4358274d3b..8796b4ddfd00e5 100644 --- a/lib/internal/loader/Translators.js +++ b/lib/internal/loader/Translators.js @@ -1,6 +1,6 @@ 'use strict'; -const { NativeModule, internalBinding } = require('internal/bootstrap_loaders'); +const { NativeModule, internalBinding } = require('internal/bootstrap/loaders'); const { ModuleWrap } = internalBinding('module_wrap'); const internalCJSModule = require('internal/module'); const CJSModule = require('module'); diff --git a/lib/internal/process/modules.js b/lib/internal/process/modules.js index 1592761f54df25..ca2a9dde5dbcd4 100644 --- a/lib/internal/process/modules.js +++ b/lib/internal/process/modules.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { setImportModuleDynamicallyCallback, setInitializeImportMetaObjectCallback diff --git a/lib/internal/test/binding.js b/lib/internal/test/binding.js index aae89ce7a0f5ea..f9f018a78226ce 100644 --- a/lib/internal/test/binding.js +++ b/lib/internal/test/binding.js @@ -8,7 +8,7 @@ process.emitWarning( // These exports should be scoped as specifically as possible // to avoid exposing APIs because even with that warning and // this file being internal people will still try to abuse it. -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); module.exports = { ModuleWrap: internalBinding('module_wrap').ModuleWrap, }; diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index c1c4d7a712d2cc..119fb66611a7c6 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -2,7 +2,7 @@ const { compare } = process.binding('buffer'); const { isArrayBufferView } = require('internal/util/types'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { isDate, isMap, isRegExp, isSet } = internalBinding('types'); function objectToString(o) { diff --git a/lib/internal/vm/Module.js b/lib/internal/vm/Module.js index 6d8f7f76d8354b..feb4bb190f7759 100644 --- a/lib/internal/vm/Module.js +++ b/lib/internal/vm/Module.js @@ -1,6 +1,6 @@ 'use strict'; -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { emitExperimentalWarning } = require('internal/util'); const { URL } = require('internal/url'); const { kParsingContext, isContext } = process.binding('contextify'); diff --git a/lib/module.js b/lib/module.js index 6d4e3dbfcf07d4..0b94cb84c6dde8 100644 --- a/lib/module.js +++ b/lib/module.js @@ -21,7 +21,7 @@ 'use strict'; -const { NativeModule } = require('internal/bootstrap_loaders'); +const { NativeModule } = require('internal/bootstrap/loaders'); const util = require('util'); const { decorateErrorStack } = require('internal/util'); const { getURLFromFilePath } = require('internal/url'); diff --git a/lib/string_decoder.js b/lib/string_decoder.js index 4cb50ca97b7f2b..a6ae64c0624b0e 100644 --- a/lib/string_decoder.js +++ b/lib/string_decoder.js @@ -22,7 +22,7 @@ 'use strict'; const { Buffer } = require('buffer'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { kIncompleteCharactersStart, kIncompleteCharactersEnd, diff --git a/lib/util.js b/lib/util.js index 95bf17519b174b..b64d103cb30bca 100644 --- a/lib/util.js +++ b/lib/util.js @@ -39,7 +39,7 @@ const { kRejected, } = process.binding('util'); -const { internalBinding } = require('internal/bootstrap_loaders'); +const { internalBinding } = require('internal/bootstrap/loaders'); const types = internalBinding('types'); Object.assign(types, require('internal/util/types')); const { diff --git a/node.gyp b/node.gyp index 5efe2323599cff..73f5f4ef225f8d 100644 --- a/node.gyp +++ b/node.gyp @@ -24,8 +24,8 @@ 'node_lib_target_name%': 'node_lib', 'node_intermediate_lib_type%': 'static_library', 'library_files': [ - 'lib/internal/bootstrap_loaders.js', - 'lib/internal/bootstrap_node.js', + 'lib/internal/bootstrap/loaders.js', + 'lib/internal/bootstrap/node.js', 'lib/async_hooks.js', 'lib/assert.js', 'lib/buffer.js', diff --git a/src/node.cc b/src/node.cc index c03c753c37cf09..b3eaec5ad96f0c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -246,7 +246,7 @@ bool config_experimental_vm_modules = false; // Set in node.cc by ParseArgs when --loader is used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js std::string config_userland_loader; // NOLINT(runtime/string) // Set by ParseArgs when --pending-deprecation or NODE_PENDING_DEPRECATION @@ -259,7 +259,7 @@ std::string config_warning_file; // NOLINT(runtime/string) // Set in node.cc by ParseArgs when --expose-internals or --expose_internals is // used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js bool config_expose_internals = false; bool v8_initialized = false; @@ -3326,23 +3326,23 @@ static Local GetBootstrapper(Environment* env, Local source, // are not safe to ignore. try_catch.SetVerbose(false); - // Execute the factory javascript file - Local factory_v = ExecuteString(env, source, script_name); + // Execute the bootstrapper javascript file + Local bootstrapper_v = ExecuteString(env, source, script_name); if (try_catch.HasCaught()) { ReportException(env, try_catch); exit(10); } - CHECK(factory_v->IsFunction()); - Local factory = Local::Cast(factory_v); + CHECK(bootstrapper_v->IsFunction()); + Local bootstrapper = Local::Cast(bootstrapper_v); - return scope.Escape(factory); + return scope.Escape(bootstrapper); } -static bool ExecuteBootstrapper(Environment* env, Local factory, +static bool ExecuteBootstrapper(Environment* env, Local bootstrapper, int argc, Local argv[], Local* out) { - bool ret = factory->Call( + bool ret = bootstrapper->Call( env->context(), Null(env->isolate()), argc, argv).ToLocal(out); // If there was an error during bootstrap then it was either handled by the @@ -3369,16 +3369,18 @@ void LoadEnvironment(Environment* env) { // are not safe to ignore. try_catch.SetVerbose(false); - // The factory scripts are lib/internal/bootstrap_loaders.js and - // lib/internal/bootstrap_node.js, each included as a static C string + // The bootstrapper scripts are lib/internal/bootstrap/loaders.js and + // lib/internal/bootstrap/node.js, each included as a static C string // defined in node_javascript.h, generated in node_javascript.cc by // node_js2c. + Local loaders_name = + FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/loaders.js"); Local loaders_bootstrapper = - GetBootstrapper(env, LoadersBootstrapperSource(env), - FIXED_ONE_BYTE_STRING(env->isolate(), "bootstrap_loaders.js")); + GetBootstrapper(env, LoadersBootstrapperSource(env), loaders_name); + Local node_name = + FIXED_ONE_BYTE_STRING(env->isolate(), "internal/bootstrap/node.js"); Local node_bootstrapper = - GetBootstrapper(env, NodeBootstrapperSource(env), - FIXED_ONE_BYTE_STRING(env->isolate(), "bootstrap_node.js")); + GetBootstrapper(env, NodeBootstrapperSource(env), node_name); // Add a reference to the global object Local global = env->context()->Global(); @@ -4292,7 +4294,7 @@ void Init(int* argc, #endif // Needed for access to V8 intrinsics. Disabled again during bootstrapping, - // see lib/internal/bootstrap_node.js. + // see lib/internal/bootstrap/node.js. const char allow_natives_syntax[] = "--allow_natives_syntax"; V8::SetFlagsFromString(allow_natives_syntax, sizeof(allow_natives_syntax) - 1); diff --git a/src/node_internals.h b/src/node_internals.h index 2faa6f93475ad7..b638d906db05c3 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -182,13 +182,13 @@ extern bool config_experimental_vm_modules; // Set in node.cc by ParseArgs when --loader is used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js extern std::string config_userland_loader; // Set in node.cc by ParseArgs when --expose-internals or --expose_internals is // used. // Used in node_config.cc to set a constant on process.binding('config') -// that is used by lib/internal/bootstrap_node.js +// that is used by lib/internal/bootstrap/node.js extern bool config_expose_internals; // Set in node.cc by ParseArgs when --redirect-warnings= is used. diff --git a/src/node_url.cc b/src/node_url.cc index cac2831af6ef7f..6b56628d753f60 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -2275,7 +2275,7 @@ const Local URL::ToObject(Environment* env) const { // The SetURLConstructor method must have been called already to // set the constructor function used below. SetURLConstructor is // called automatically when the internal/url.js module is loaded - // during the internal/bootstrap_node.js processing. + // during the internal/bootstrap/node.js processing. ret = env->url_constructor_function() ->Call(env->context(), undef, arraysize(argv), argv); } diff --git a/test/message/core_line_numbers.out b/test/message/core_line_numbers.out index 1049fdc3e935df..5658a5a59ecbcd 100644 --- a/test/message/core_line_numbers.out +++ b/test/message/core_line_numbers.out @@ -12,4 +12,4 @@ RangeError: Invalid input at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) diff --git a/test/message/error_exit.out b/test/message/error_exit.out index eab43959b6c8d8..2cbc4ad4fd544f 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -11,5 +11,5 @@ AssertionError [ERR_ASSERTION]: 1 strictEqual 2 at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/eval_messages.out b/test/message/eval_messages.out index 7dbf9e950c2c71..84772ffa48a14f 100644 --- a/test/message/eval_messages.out +++ b/test/message/eval_messages.out @@ -8,9 +8,9 @@ SyntaxError: Strict mode code may not include a with statement at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) 42 42 [eval]:1 @@ -23,9 +23,9 @@ Error: hello at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) [eval]:1 throw new Error("hello") @@ -37,9 +37,9 @@ Error: hello at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) 100 [eval]:1 var x = 100; y = x; @@ -51,9 +51,9 @@ ReferenceError: y is not defined at Object.runInThisContext (vm.js:*:*) at Object. ([eval]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) [eval]:1 var ______________________________________________; throw 10 diff --git a/test/message/events_unhandled_error_common_trace.out b/test/message/events_unhandled_error_common_trace.out index 15355734705331..003446edaa5e17 100644 --- a/test/message/events_unhandled_error_common_trace.out +++ b/test/message/events_unhandled_error_common_trace.out @@ -12,11 +12,11 @@ Error: foo:bar at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) Emitted 'error' event at: at quux (*events_unhandled_error_common_trace.js:*:*) at Object. (*events_unhandled_error_common_trace.js:*:*) at Module._compile (module.js:*:*) [... lines matching original stack trace ...] - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/events_unhandled_error_nexttick.out b/test/message/events_unhandled_error_nexttick.out index c578f55f90c45a..5912f9fd387b4c 100644 --- a/test/message/events_unhandled_error_nexttick.out +++ b/test/message/events_unhandled_error_nexttick.out @@ -10,11 +10,11 @@ Error at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.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 startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/events_unhandled_error_sameline.out b/test/message/events_unhandled_error_sameline.out index d8441c44d41fd5..dcbb45afbd4240 100644 --- a/test/message/events_unhandled_error_sameline.out +++ b/test/message/events_unhandled_error_sameline.out @@ -10,10 +10,10 @@ Error at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*:*) at Function.Module.runMain (module.js:*:*) - at startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) Emitted 'error' event at: at Object. (*events_unhandled_error_sameline.js:*:*) at Module._compile (module.js:*:*) [... lines matching original stack trace ...] - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/nexttick_throw.out b/test/message/nexttick_throw.out index 41412b95f6ae5a..798b208d7d9049 100644 --- a/test/message/nexttick_throw.out +++ b/test/message/nexttick_throw.out @@ -6,5 +6,5 @@ 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 startup (bootstrap_node.js:*:*) - at bootstrapNodeJSCore (bootstrap_node.js:*:*) + at startup (internal/bootstrap/node.js:*:*) + at bootstrapNodeJSCore (internal/bootstrap/node.js:*:*) diff --git a/test/message/stdin_messages.out b/test/message/stdin_messages.out index d2192050dd4196..c6c37a5be4f397 100644 --- a/test/message/stdin_messages.out +++ b/test/message/stdin_messages.out @@ -8,8 +8,8 @@ SyntaxError: Strict mode code may not include a with statement at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) @@ -25,8 +25,8 @@ Error: hello at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) @@ -40,8 +40,8 @@ Error: hello at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) @@ -56,8 +56,8 @@ ReferenceError: y is not defined at Object.runInThisContext (vm.js:*) at Object. ([stdin]-wrapper:*:*) at Module._compile (module.js:*:*) - at evalScript (bootstrap_node.js:*:*) - at Socket. (bootstrap_node.js:*:*) + at evalScript (internal/bootstrap/node.js:*:*) + at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) at endReadableNT (_stream_readable.js:*:*) at process._tickCallback (internal/process/next_tick.js:*:*) diff --git a/test/parallel/test-loaders-hidden-from-users.js b/test/parallel/test-loaders-hidden-from-users.js index b3e6622c8c0c88..0d752f5718b729 100644 --- a/test/parallel/test-loaders-hidden-from-users.js +++ b/test/parallel/test-loaders-hidden-from-users.js @@ -6,16 +6,16 @@ const common = require('../common'); common.expectsError( () => { - require('internal/bootstrap_loaders'); + require('internal/bootstrap/loaders'); }, { code: 'MODULE_NOT_FOUND', - message: 'Cannot find module \'internal/bootstrap_loaders\'' + message: 'Cannot find module \'internal/bootstrap/loaders\'' } ); common.expectsError( () => { - const source = 'module.exports = require("internal/bootstrap_loaders")'; + const source = 'module.exports = require("internal/bootstrap/loaders")'; process.binding('natives').owo = source; require('owo'); }, { diff --git a/test/sequential/test-inspector-overwrite-config.js b/test/sequential/test-inspector-overwrite-config.js index 2a00b1e0796141..8b641a0048484a 100644 --- a/test/sequential/test-inspector-overwrite-config.js +++ b/test/sequential/test-inspector-overwrite-config.js @@ -2,7 +2,8 @@ 'use strict'; // This test ensures that overwriting a process configuration -// value does not affect code in bootstrap_node.js. Specifically this tests +// value does not affect code in lib/internal/bootstrap/node.js. +// Specifically this tests // that the inspector console functions are bound even though // overwrite-config-preload-module.js overwrote the process.config variable. From ea39dc5c7e9141848919a6427f7d8d5380f58b9e Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 7 Mar 2018 02:30:18 +0800 Subject: [PATCH 2/4] lib: restructure cjs and esm loaders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ``` --- lib/internal/bootstrap/loaders.js | 3 +- lib/internal/bootstrap/node.js | 50 +++++++++++-------- .../{module.js => modules/cjs/helpers.js} | 0 .../modules/cjs/loader.js} | 27 ++++++---- .../esm}/CreateDynamicModule.js | 0 .../{loader => modules/esm}/DefaultResolve.js | 2 +- .../{loader => modules/esm}/Loader.js | 10 ++-- .../{loader => modules/esm}/ModuleJob.js | 0 .../{loader => modules/esm}/ModuleMap.js | 2 +- .../{loader => modules/esm}/Translators.js | 13 +++-- .../process/{modules.js => esm_loader.js} | 2 +- lib/repl.js | 23 +++++---- node.gyp | 17 ++++--- test/es-module/test-esm-loader-modulemap.js | 8 +-- test/es-module/test-esm-loader-search.js | 2 +- test/fixtures/module-require-depth/one.js | 10 ++-- test/fixtures/module-require-depth/two.js | 10 ++-- test/message/core_line_numbers.out | 12 ++--- test/message/error_exit.out | 12 ++--- test/message/esm_display_syntax_error.out | 2 +- .../esm_display_syntax_error_import.out | 2 +- ...esm_display_syntax_error_import_module.out | 2 +- .../esm_display_syntax_error_module.out | 2 +- test/message/eval_messages.out | 8 +-- .../events_unhandled_error_common_trace.out | 14 +++--- .../events_unhandled_error_nexttick.out | 14 +++--- .../events_unhandled_error_sameline.out | 14 +++--- test/message/if-error-has-good-stack.out | 12 ++--- test/message/nexttick_throw.out | 2 +- test/message/stdin_messages.out | 8 +-- .../undefined_reference_in_new_context.out | 10 ++-- test/message/vm_display_runtime_error.out | 24 ++++----- test/message/vm_display_syntax_error.out | 24 ++++----- .../message/vm_dont_display_runtime_error.out | 12 ++--- test/message/vm_dont_display_syntax_error.out | 12 ++--- .../test-internal-module-map-asserts.js | 2 +- .../test-internal-modules-strip-shebang.js | 2 +- test/parallel/test-module-require-depth.js | 8 +-- 38 files changed, 203 insertions(+), 174 deletions(-) rename lib/internal/{module.js => modules/cjs/helpers.js} (100%) rename lib/{module.js => internal/modules/cjs/loader.js} (97%) rename lib/internal/{loader => modules/esm}/CreateDynamicModule.js (100%) rename lib/internal/{loader => modules/esm}/DefaultResolve.js (97%) rename lib/internal/{loader => modules/esm}/Loader.js (92%) rename lib/internal/{loader => modules/esm}/ModuleJob.js (100%) rename lib/internal/{loader => modules/esm}/ModuleMap.js (93%) rename lib/internal/{loader => modules/esm}/Translators.js (90%) rename lib/internal/process/{modules.js => esm_loader.js} (96%) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 601c54a0cdbcd0..f7384b27848870 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -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 diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 67ec63eb01a1e5..7d7ca03d36f7ac 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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(''); + const consoleAPIModule = new CJSModule(''); 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 }); } diff --git a/lib/internal/module.js b/lib/internal/modules/cjs/helpers.js similarity index 100% rename from lib/internal/module.js rename to lib/internal/modules/cjs/helpers.js diff --git a/lib/module.js b/lib/internal/modules/cjs/loader.js similarity index 97% rename from lib/module.js rename to lib/internal/modules/cjs/loader.js index 0b94cb84c6dde8..a1722666619d00 100644 --- a/lib/module.js +++ b/lib/internal/modules/cjs/loader.js @@ -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; diff --git a/lib/internal/loader/CreateDynamicModule.js b/lib/internal/modules/esm/CreateDynamicModule.js similarity index 100% rename from lib/internal/loader/CreateDynamicModule.js rename to lib/internal/modules/esm/CreateDynamicModule.js diff --git a/lib/internal/loader/DefaultResolve.js b/lib/internal/modules/esm/DefaultResolve.js similarity index 97% rename from lib/internal/loader/DefaultResolve.js rename to lib/internal/modules/esm/DefaultResolve.js index a012314d2a1e1a..00461e7df1f684 100644 --- a/lib/internal/loader/DefaultResolve.js +++ b/lib/internal/modules/esm/DefaultResolve.js @@ -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'); diff --git a/lib/internal/loader/Loader.js b/lib/internal/modules/esm/Loader.js similarity index 92% rename from lib/internal/loader/Loader.js rename to lib/internal/modules/esm/Loader.js index e4457cfd817ba1..84c23cc10ac2fc 100644 --- a/lib/internal/loader/Loader.js +++ b/lib/internal/modules/esm/Loader.js @@ -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); diff --git a/lib/internal/loader/ModuleJob.js b/lib/internal/modules/esm/ModuleJob.js similarity index 100% rename from lib/internal/loader/ModuleJob.js rename to lib/internal/modules/esm/ModuleJob.js diff --git a/lib/internal/loader/ModuleMap.js b/lib/internal/modules/esm/ModuleMap.js similarity index 93% rename from lib/internal/loader/ModuleMap.js rename to lib/internal/modules/esm/ModuleMap.js index dce8f834ba6d10..e9a8d22d7bf311 100644 --- a/lib/internal/loader/ModuleMap.js +++ b/lib/internal/modules/esm/ModuleMap.js @@ -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; diff --git a/lib/internal/loader/Translators.js b/lib/internal/modules/esm/Translators.js similarity index 90% rename from lib/internal/loader/Translators.js rename to lib/internal/modules/esm/Translators.js index 8796b4ddfd00e5..2928115be515e0 100644 --- a/lib/internal/loader/Translators.js +++ b/lib/internal/modules/esm/Translators.js @@ -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; diff --git a/lib/internal/process/modules.js b/lib/internal/process/esm_loader.js similarity index 96% rename from lib/internal/process/modules.js rename to lib/internal/process/esm_loader.js index ca2a9dde5dbcd4..e45c0faa185214 100644 --- a/lib/internal/process/modules.js +++ b/lib/internal/process/esm_loader.js @@ -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'); diff --git a/lib/repl.js b/lib/repl.js index 078bb208ae1544..06703da131c301 100644 --- a/lib/repl.js +++ b/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(''); - module.paths = Module._resolveLookupPaths('', parentModule, true) || []; + var module = new CJSModule(''); + module.paths = + CJSModule._resolveLookupPaths('', 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++) { diff --git a/node.gyp b/node.gyp index 73f5f4ef225f8d..eb1b0e1a8cc6af 100644 --- a/node.gyp +++ b/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', diff --git a/test/es-module/test-esm-loader-modulemap.js b/test/es-module/test-esm-loader-modulemap.js index 1c1623b680e7bd..e9faa6d9f122f4 100644 --- a/test/es-module/test-esm-loader-modulemap.js +++ b/test/es-module/test-esm-loader-modulemap.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); diff --git a/test/es-module/test-esm-loader-search.js b/test/es-module/test-esm-loader-search.js index 4a85ea93253a0c..0f4591a4e3fd95 100644 --- a/test/es-module/test-esm-loader-search.js +++ b/test/es-module/test-esm-loader-search.js @@ -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), diff --git a/test/fixtures/module-require-depth/one.js b/test/fixtures/module-require-depth/one.js index 5927908b7540ab..02b451465bb76c 100644 --- a/test/fixtures/module-require-depth/one.js +++ b/test/fixtures/module-require-depth/one.js @@ -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); diff --git a/test/fixtures/module-require-depth/two.js b/test/fixtures/module-require-depth/two.js index aea49947d1152d..5c94c4c89aa9ef 100644 --- a/test/fixtures/module-require-depth/two.js +++ b/test/fixtures/module-require-depth/two.js @@ -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); diff --git a/test/message/core_line_numbers.out b/test/message/core_line_numbers.out index 5658a5a59ecbcd..b50e1678f49fb7 100644 --- a/test/message/core_line_numbers.out +++ b/test/message/core_line_numbers.out @@ -6,10 +6,10 @@ RangeError: Invalid input at error (punycode.js:42:*) at Object.decode (punycode.js:*:*) at Object. (*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:*:*) diff --git a/test/message/error_exit.out b/test/message/error_exit.out index 2cbc4ad4fd544f..e7bcb050654513 100644 --- a/test/message/error_exit.out +++ b/test/message/error_exit.out @@ -5,11 +5,11 @@ assert.js:* AssertionError [ERR_ASSERTION]: 1 strictEqual 2 at Object. (*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:*:*) diff --git a/test/message/esm_display_syntax_error.out b/test/message/esm_display_syntax_error.out index 57d39e6c7920b3..4564fe06d582ac 100644 --- a/test/message/esm_display_syntax_error.out +++ b/test/message/esm_display_syntax_error.out @@ -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:*:*) diff --git a/test/message/esm_display_syntax_error_import.out b/test/message/esm_display_syntax_error_import.out index 617ecd09efc2d4..02050d361e101d 100644 --- a/test/message/esm_display_syntax_error_import.out +++ b/test/message/esm_display_syntax_error_import.out @@ -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:*:*) diff --git a/test/message/esm_display_syntax_error_import_module.out b/test/message/esm_display_syntax_error_import_module.out index 2e7ea8e5728dae..ae0bf331de53ee 100644 --- a/test/message/esm_display_syntax_error_import_module.out +++ b/test/message/esm_display_syntax_error_import_module.out @@ -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:*:*) diff --git a/test/message/esm_display_syntax_error_module.out b/test/message/esm_display_syntax_error_module.out index 56bbac93074703..fc0581c225f485 100644 --- a/test/message/esm_display_syntax_error_module.out +++ b/test/message/esm_display_syntax_error_module.out @@ -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:*:*) diff --git a/test/message/eval_messages.out b/test/message/eval_messages.out index 84772ffa48a14f..d01dfe547cbd73 100644 --- a/test/message/eval_messages.out +++ b/test/message/eval_messages.out @@ -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. ([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. ([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. ([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. ([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:*:*) diff --git a/test/message/events_unhandled_error_common_trace.out b/test/message/events_unhandled_error_common_trace.out index 003446edaa5e17..f6b74e9991306b 100644 --- a/test/message/events_unhandled_error_common_trace.out +++ b/test/message/events_unhandled_error_common_trace.out @@ -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. (*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. (*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:*:*) diff --git a/test/message/events_unhandled_error_nexttick.out b/test/message/events_unhandled_error_nexttick.out index 5912f9fd387b4c..e00580ce93cf45 100644 --- a/test/message/events_unhandled_error_nexttick.out +++ b/test/message/events_unhandled_error_nexttick.out @@ -4,17 +4,17 @@ events.js:* Error at Object. (*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:*:*) diff --git a/test/message/events_unhandled_error_sameline.out b/test/message/events_unhandled_error_sameline.out index dcbb45afbd4240..55841cdbc345d7 100644 --- a/test/message/events_unhandled_error_sameline.out +++ b/test/message/events_unhandled_error_sameline.out @@ -4,16 +4,16 @@ events.js:* Error at Object. (*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. (*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:*:*) diff --git a/test/message/if-error-has-good-stack.out b/test/message/if-error-has-good-stack.out index 7aa58b0283f75d..2a4dfe8fb26630 100644 --- a/test/message/if-error-has-good-stack.out +++ b/test/message/if-error-has-good-stack.out @@ -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. (*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:*:*) diff --git a/test/message/nexttick_throw.out b/test/message/nexttick_throw.out index 798b208d7d9049..16e41f6343baec 100644 --- a/test/message/nexttick_throw.out +++ b/test/message/nexttick_throw.out @@ -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:*:*) diff --git a/test/message/stdin_messages.out b/test/message/stdin_messages.out index c6c37a5be4f397..d4498b452aa6ba 100644 --- a/test/message/stdin_messages.out +++ b/test/message/stdin_messages.out @@ -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. ([stdin]-wrapper:*:*) - at Module._compile (module.js:*:*) + at Module._compile (internal/modules/cjs/loader.js:*:*) at evalScript (internal/bootstrap/node.js:*:*) at Socket. (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. ([stdin]-wrapper:*:*) - at Module._compile (module.js:*:*) + at Module._compile (internal/modules/cjs/loader.js:*:*) at evalScript (internal/bootstrap/node.js:*:*) at Socket. (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. ([stdin]-wrapper:*:*) - at Module._compile (module.js:*:*) + at Module._compile (internal/modules/cjs/loader.js:*:*) at evalScript (internal/bootstrap/node.js:*:*) at Socket. (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. ([stdin]-wrapper:*:*) - at Module._compile (module.js:*:*) + at Module._compile (internal/modules/cjs/loader.js:*:*) at evalScript (internal/bootstrap/node.js:*:*) at Socket. (internal/bootstrap/node.js:*:*) at Socket.emit (events.js:*:*) diff --git a/test/message/undefined_reference_in_new_context.out b/test/message/undefined_reference_in_new_context.out index ff517cc981a255..6b5fedfa993701 100644 --- a/test/message/undefined_reference_in_new_context.out +++ b/test/message/undefined_reference_in_new_context.out @@ -9,8 +9,8 @@ ReferenceError: foo is not defined at Script.runInNewContext (vm.js:*) at Object.runInNewContext (vm.js:*) at Object. (*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:*:*) diff --git a/test/message/vm_display_runtime_error.out b/test/message/vm_display_runtime_error.out index 056ea79f8d39b4..bc95b2a7b092f5 100644 --- a/test/message/vm_display_runtime_error.out +++ b/test/message/vm_display_runtime_error.out @@ -8,12 +8,12 @@ Error: boo! at Script.runInThisContext (vm.js:*) at Object.runInThisContext (vm.js:*) at Object. (*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. (*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:*) diff --git a/test/message/vm_display_syntax_error.out b/test/message/vm_display_syntax_error.out index f3b9953307db19..f0692723e81257 100644 --- a/test/message/vm_display_syntax_error.out +++ b/test/message/vm_display_syntax_error.out @@ -7,12 +7,12 @@ SyntaxError: Unexpected number at createScript (vm.js:*) at Object.runInThisContext (vm.js:*) at Object. (*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. (*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:*) diff --git a/test/message/vm_dont_display_runtime_error.out b/test/message/vm_dont_display_runtime_error.out index a7e06d49f85a7c..532cfbf4dd8125 100644 --- a/test/message/vm_dont_display_runtime_error.out +++ b/test/message/vm_dont_display_runtime_error.out @@ -9,9 +9,9 @@ Error: boo! at Script.runInThisContext (vm.js:*) at Object.runInThisContext (vm.js:*) at Object. (*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:*) diff --git a/test/message/vm_dont_display_syntax_error.out b/test/message/vm_dont_display_syntax_error.out index 5c74c25dd8aa3b..f27cb1a0859d8c 100644 --- a/test/message/vm_dont_display_syntax_error.out +++ b/test/message/vm_dont_display_syntax_error.out @@ -9,9 +9,9 @@ SyntaxError: Unexpected number at createScript (vm.js:*) at Object.runInThisContext (vm.js:*) at Object. (*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:*) diff --git a/test/parallel/test-internal-module-map-asserts.js b/test/parallel/test-internal-module-map-asserts.js index 1160c910421b80..330f04cfd96800 100644 --- a/test/parallel/test-internal-module-map-asserts.js +++ b/test/parallel/test-internal-module-map-asserts.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. diff --git a/test/parallel/test-internal-modules-strip-shebang.js b/test/parallel/test-internal-modules-strip-shebang.js index 93be3d41981f50..6c23848a969231 100644 --- a/test/parallel/test-internal-modules-strip-shebang.js +++ b/test/parallel/test-internal-modules-strip-shebang.js @@ -3,7 +3,7 @@ require('../common'); const assert = require('assert'); -const stripShebang = require('internal/module').stripShebang; +const stripShebang = require('internal/modules/cjs/helpers').stripShebang; [ ['', ''], diff --git a/test/parallel/test-module-require-depth.js b/test/parallel/test-module-require-depth.js index 151934917cd678..0a3fc2826c71f4 100644 --- a/test/parallel/test-module-require-depth.js +++ b/test/parallel/test-module-require-depth.js @@ -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); From 60b7afcfbd7032373da2b18ff9dc1906615d0067 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 14 Mar 2018 12:51:53 +0800 Subject: [PATCH 3/4] lib: add back lib/module.js redirection The previous commit deleted lib/module.js so that git recognize the file move `lib/module.js` -> `lib/internal/modules/cjs/loader.js`. This commit add the redirection back. --- lib/module.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/module.js diff --git a/lib/module.js b/lib/module.js new file mode 100644 index 00000000000000..962f18b054cc90 --- /dev/null +++ b/lib/module.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('internal/modules/cjs/loader'); From e636691ce3feb8a991af3bcd272202bba7c5bf4a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 14 Mar 2018 20:56:28 +0800 Subject: [PATCH 4/4] test: remove NODE_DEBUG in global module loading test Otherwise the debug log output might be mixed up with the expected errors and the assertion matching the error message would fail. --- test/parallel/test-module-loading-globalpaths.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/parallel/test-module-loading-globalpaths.js b/test/parallel/test-module-loading-globalpaths.js index aff96543735428..798b7765bb6d5b 100644 --- a/test/parallel/test-module-loading-globalpaths.js +++ b/test/parallel/test-module-loading-globalpaths.js @@ -41,8 +41,6 @@ if (process.argv[2] === 'child') { const testFixturesDir = fixtures.path(path.basename(__filename, '.js')); const env = Object.assign({}, process.env); - // Turn on module debug to aid diagnosing failures. - env.NODE_DEBUG = 'module'; // Unset NODE_PATH. delete env.NODE_PATH;