| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3a2d8bf commit 6c4f477
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2533,7 +2533,7 @@ This is not allowed because ES Modules cannot be evaluated while they are | |||
| 2533 | 2533 | already being evaluated. | |
| 2534 | 2534 | ||
| 2535 | 2535 | To avoid the cycle, the `require()` call involved in a cycle should not happen | |
| 2536 | - at the top-level of either a ES Module (via `createRequire()`) or a CommonJS | ||
| 2536 | + at the top-level of either an ES Module (via `createRequire()`) or a CommonJS | ||
| 2537 | 2537 | module, and should be done lazily in an inner function. | |
| 2538 | 2538 | ||
| 2539 | 2539 | <a id="ERR_REQUIRE_ASYNC_MODULE"></a> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1063,7 +1063,7 @@ Module._load = function(request, parent, isMain) { | |||
| 1063 | 1063 | } | |
| 1064 | 1064 | // If it's cached by the ESM loader as a way to indirectly pass | |
| 1065 | 1065 | // the module in to avoid creating it twice, the loading request | |
| 1066 | - // come from imported CJS. In that case use the kModuleCircularVisited | ||
| 1066 | + // came from imported CJS. In that case use the kModuleCircularVisited | ||
| 1067 | 1067 | // to determine if it's loading or not. | |
| 1068 | 1068 | if (cachedModule[kModuleCircularVisited]) { | |
| 1069 | 1069 | return getExportsForCircularRequire(cachedModule); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,10 @@ const { | |||
| 42 | 42 | } = require('internal/modules/helpers'); | |
| 43 | 43 | let defaultResolve, defaultLoad, defaultLoadSync, importMetaInitializer; | |
| 44 | 44 | ||
| 45 | + /** | ||
| 46 | + * @typedef {import('url').URL} URL | ||
| 47 | + */ | ||
| 48 | + | ||
| 45 | 49 | /** | |
| 46 | 50 | * Lazy loads the module_map module and returns a new instance of ResolveCache. | |
| 47 | 51 | * @returns {import('./module_map.js').ResolveCache} | |
@@ -77,6 +81,10 @@ function getTranslators() { | |||
| 77 | 81 | */ | |
| 78 | 82 | let hooksProxy; | |
| 79 | 83 | ||
| 84 | + /** | ||
| 85 | + * @typedef {import('../cjs/loader.js').Module} CJSModule | ||
| 86 | + */ | ||
| 87 | + | ||
| 80 | 88 | /** | |
| 81 | 89 | * @typedef {Record<string, any>} ModuleExports | |
| 82 | 90 | */ | |
@@ -257,11 +265,11 @@ class ModuleLoader { | |||
| 257 | 265 | /** | |
| 258 | 266 | * This constructs (creates, instantiates and evaluates) a module graph that | |
| 259 | 267 | * is require()'d. | |
| 260 | - * @param {import('../cjs/loader.js').Module} mod CJS module wrapper of the ESM. | ||
| 268 | + * @param {CJSModule} mod CJS module wrapper of the ESM. | ||
| 261 | 269 | * @param {string} filename Resolved filename of the module being require()'d | |
| 262 | 270 | * @param {string} source Source code. TODO(joyeecheung): pass the raw buffer. | |
| 263 | 271 | * @param {string} isMain Whether this module is a main module. | |
| 264 | - * @param {import('../cjs/loader.js').Module|undefined} parent Parent module, if any. | ||
| 272 | + * @param {CJSModule|undefined} parent Parent module, if any. | ||
| 265 | 273 | * @returns {{ModuleWrap}} | |
| 266 | 274 | */ | |
| 267 | 275 | importSyncForRequire(mod, filename, source, isMain, parent) { | |
@@ -343,7 +351,7 @@ class ModuleLoader { | |||
| 343 | 351 | } | |
| 344 | 352 | throw new ERR_REQUIRE_CYCLE_MODULE(message); | |
| 345 | 353 | } | |
| 346 | - // Othersie the module could be imported before but the evaluation may be already | ||
| 354 | + // Otherwise the module could be imported before but the evaluation may be already | ||
| 347 | 355 | // completed (e.g. the require call is lazy) so it's okay. We will return the | |
| 348 | 356 | // module now and check asynchronicity of the entire graph later, after the | |
| 349 | 357 | // graph is instantiated. | |
@@ -352,8 +360,12 @@ class ModuleLoader { | |||
| 352 | 360 | ||
| 353 | 361 | defaultLoadSync ??= require('internal/modules/esm/load').defaultLoadSync; | |
| 354 | 362 | const loadResult = defaultLoadSync(url, { format, importAttributes }); | |
| 355 | - const { responseURL, source } = loadResult; | ||
| 356 | - const { format: finalFormat } = loadResult; | ||
| 363 | + const { | ||
| 364 | + format: finalFormat, | ||
| 365 | + responseURL, | ||
| 366 | + source, | ||
| 367 | + } = loadResult; | ||
| 368 | + | ||
| 357 | 369 | this.validateLoadResult(url, finalFormat); | |
| 358 | 370 | if (finalFormat === 'wasm') { | |
| 359 | 371 | assert.fail('WASM is currently unsupported by require(esm)'); | |
@@ -725,11 +737,11 @@ function getOrInitializeCascadedLoader() { | |||
| 725 | 737 | ||
| 726 | 738 | /** | |
| 727 | 739 | * Register a single loader programmatically. | |
| 728 | - * @param {string|import('url').URL} specifier | ||
| 729 | - * @param {string|import('url').URL} [parentURL] Base to use when resolving `specifier`; optional if | ||
| 740 | + * @param {string|URL} specifier | ||
| 741 | + * @param {string|URL} [parentURL] Base to use when resolving `specifier`; optional if | ||
| 730 | 742 | * `specifier` is absolute. Same as `options.parentUrl`, just inline | |
| 731 | 743 | * @param {object} [options] Additional options to apply, described below. | |
| 732 | - * @param {string|import('url').URL} [options.parentURL] Base to use when resolving `specifier` | ||
| 744 | + * @param {string|URL} [options.parentURL] Base to use when resolving `specifier` | ||
| 733 | 745 | * @param {any} [options.data] Arbitrary data passed to the loader's `initialize` hook | |
| 734 | 746 | * @param {any[]} [options.transferList] Objects in `data` that are changing ownership | |
| 735 | 747 | * @returns {void} We want to reserve the return value for potential future extension of the API. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ const { dirname, extname, isAbsolute } = require('path'); | |||
| 41 | 41 | const { | |
| 42 | 42 | loadBuiltinModule, | |
| 43 | 43 | stripBOM, | |
| 44 | + urlToFilename, | ||
| 44 | 45 | } = require('internal/modules/helpers'); | |
| 45 | 46 | const { | |
| 46 | 47 | kIsCachedByESMLoader, | |
@@ -243,7 +244,7 @@ function loadCJSModule(module, source, url, filename) { | |||
| 243 | 244 | } | |
| 244 | 245 | } | |
| 245 | 246 | const { url: resolvedURL } = cascadedLoader.resolveSync(specifier, url, kEmptyObject); | |
| 246 | - return StringPrototypeStartsWith(resolvedURL, 'file://') ? fileURLToPath(resolvedURL) : resolvedURL; | ||
| 247 | + return urlToFilename(resolvedURL); | ||
| 247 | 248 | }); | |
| 248 | 249 | setOwnProperty(requireFn, 'main', process.mainModule); | |
| 249 | 250 | ||
@@ -265,7 +266,7 @@ const cjsCache = new SafeMap(); | |||
| 265 | 266 | function createCJSModuleWrap(url, source, isMain, loadCJS = loadCJSModule) { | |
| 266 | 267 | debug(`Translating CJSModule ${url}`); | |
| 267 | 268 | ||
| 268 | - const filename = StringPrototypeStartsWith(url, 'file://') ? fileURLToPath(url) : url; | ||
| 269 | + const filename = urlToFilename(url); | ||
| 269 | 270 | // In case the source was not provided by the `load` step, we need fetch it now. | |
| 270 | 271 | source = stringify(source ?? getSource(new URL(url)).source); | |
| 271 | 272 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments