MCPcopy Index your code
hub / github.com/nodejs/node / executeUserEntryPoint

Function executeUserEntryPoint

lib/internal/modules/run_main.js:140–165  ·  view source on GitHub ↗

* Parse the CLI main entry point string and run it. * For backwards compatibility, we have to run a bunch of monkey-patchable code that belongs to the CJS loader (exposed * by `require('module')`) even when the entry point is ESM. * Because of backwards compatibility, this function is exposed pub

(main = process.argv[1])

Source from the content-addressed store, hash-verified

138 * @param {string} main - First positional CLI argument, such as `'entry.js'` from `node entry.js`
139 */
140function executeUserEntryPoint(main = process.argv[1]) {
141 let useESMLoader;
142 let resolvedMain;
143 if (getOptionValue('--entry-url')) {
144 useESMLoader = true;
145 } else {
146 resolvedMain = resolveMainPath(main);
147 useESMLoader = shouldUseESMLoader(resolvedMain);
148 }
149 // Unless we know we should use the ESM loader to handle the entry point per the checks in `shouldUseESMLoader`, first
150 // try to run the entry point via the CommonJS loader; and if that fails under certain conditions, retry as ESM.
151 if (!useESMLoader) {
152 const cjsLoader = require('internal/modules/cjs/loader');
153 const { wrapModuleLoad } = cjsLoader;
154 wrapModuleLoad(main, null, true);
155 } else {
156 const mainPath = resolvedMain || main;
157 const mainURL = getOptionValue('--entry-url') ? new URL(mainPath, getCWDURL()) : pathToFileURL(mainPath);
158
159 runEntryPointWithESMLoader((cascadedLoader) => {
160 // Note that if the graph contains unsettled TLA, this may never resolve
161 // even after the event loop stops running.
162 return cascadedLoader.import(mainURL, undefined, { __proto__: null }, undefined, true);
163 });
164 }
165}
166
167module.exports = {
168 executeUserEntryPoint,

Callers

nothing calls this directly

Calls 9

getOptionValueFunction · 0.85
resolveMainPathFunction · 0.85
shouldUseESMLoaderFunction · 0.85
wrapModuleLoadFunction · 0.85
getCWDURLFunction · 0.85
importMethod · 0.80
requireFunction · 0.70
pathToFileURLFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…