diff options
Diffstat (limited to 'lib/internal/modules/cjs/loader.js')
-rw-r--r-- | lib/internal/modules/cjs/loader.js | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 418867980d..9728cd2cb9 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -64,6 +64,11 @@ const manifest = getOptionValue('--experimental-policy') ? require('internal/process/policy').manifest : null; const { compileFunction } = internalBinding('contextify'); + +// Whether any user-provided CJS modules had been loaded (executed). +// Used for internal assertions. +let hasLoadedAnyUserCJSModule = false; + const { ERR_INVALID_ARG_VALUE, ERR_INVALID_OPT_VALUE, @@ -71,14 +76,12 @@ const { ERR_REQUIRE_ESM } = require('internal/errors').codes; const { validateString } = require('internal/validators'); -const { - resolveMainPath, - shouldUseESMLoader, - runMainESM -} = require('internal/bootstrap/pre_execution'); const pendingDeprecation = getOptionValue('--pending-deprecation'); -module.exports = { wrapSafe, Module, toRealPath, readPackageScope }; +module.exports = { + wrapSafe, Module, toRealPath, readPackageScope, + get hasLoadedAnyUserCJSModule() { return hasLoadedAnyUserCJSModule; } +}; let asyncESM, ModuleJob, ModuleWrap, kInstantiated; @@ -1172,6 +1175,7 @@ Module.prototype._compile = function(content, filename) { result = compiledWrapper.call(thisValue, exports, require, module, filename, dirname); } + hasLoadedAnyUserCJSModule = true; if (requireDepth === 0) statCache = null; return result; }; @@ -1240,17 +1244,6 @@ Module._extensions['.node'] = function(module, filename) { return process.dlopen(module, path.toNamespacedPath(filename)); }; -// Bootstrap main module. -Module.runMain = function(main = process.argv[1]) { - const resolvedMain = resolveMainPath(main); - const useESMLoader = shouldUseESMLoader(resolvedMain); - if (useESMLoader) { - runMainESM(resolvedMain || main); - } else { - Module._load(main, null, true); - } -}; - function createRequireFromPath(filename) { // Allow a directory to be passed as the filename const trailingSlash = |