* 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])
| 138 | * @param {string} main - First positional CLI argument, such as `'entry.js'` from `node entry.js` |
| 139 | */ |
| 140 | function 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 | |
| 167 | module.exports = { |
| 168 | executeUserEntryPoint, |
nothing calls this directly
no test coverage detected
searching dependent graphs…