-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: print location of unsettled top-level await in entry points #51999
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a61e550
module: refactor ESM loader initialization and entry point handling
joyeecheung 74221f8
src: refactor out FormatErrorMessage for error formatting
joyeecheung 178a286
module: print location of unsettled top-level await in entry points
joyeecheung a3b96bb
fixup! module: print location of unsettled top-level await in entry p…
joyeecheung dc1e09d
fixup! module: refactor ESM loader initialization and entry point han…
joyeecheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,7 +20,7 @@ const { | |||||
ERR_UNKNOWN_MODULE_FORMAT, | ||||||
} = require('internal/errors').codes; | ||||||
const { getOptionValue } = require('internal/options'); | ||||||
const { pathToFileURL, isURL } = require('internal/url'); | ||||||
const { isURL } = require('internal/url'); | ||||||
const { emitExperimentalWarning } = require('internal/util'); | ||||||
const { | ||||||
getDefaultConditions, | ||||||
|
@@ -85,11 +85,6 @@ class ModuleLoader { | |||||
*/ | ||||||
#defaultConditions = getDefaultConditions(); | ||||||
|
||||||
/** | ||||||
* The index for assigning unique URLs to anonymous module evaluation | ||||||
*/ | ||||||
evalIndex = 0; | ||||||
|
||||||
/** | ||||||
* Registry of resolved specifiers | ||||||
*/ | ||||||
|
@@ -187,10 +182,7 @@ class ModuleLoader { | |||||
} | ||||||
} | ||||||
|
||||||
async eval( | ||||||
source, | ||||||
url = pathToFileURL(`${process.cwd()}/[eval${++this.evalIndex}]`).href, | ||||||
) { | ||||||
async eval(source, url, isEntryPoint = false) { | ||||||
const evalInstance = (url) => { | ||||||
const { ModuleWrap } = internalBinding('module_wrap'); | ||||||
const { registerModule } = require('internal/modules/esm/utils'); | ||||||
|
@@ -209,11 +201,12 @@ class ModuleLoader { | |||||
const job = new ModuleJob( | ||||||
this, url, undefined, evalInstance, false, false); | ||||||
this.loadCache.set(url, undefined, job); | ||||||
const { module } = await job.run(); | ||||||
const { module } = await job.run(isEntryPoint); | ||||||
|
||||||
return { | ||||||
__proto__: null, | ||||||
namespace: module.getNamespace(), | ||||||
module, | ||||||
}; | ||||||
} | ||||||
|
||||||
|
@@ -318,9 +311,9 @@ class ModuleLoader { | |||||
* module import. | ||||||
* @returns {Promise<ModuleExports>} | ||||||
*/ | ||||||
async import(specifier, parentURL, importAttributes) { | ||||||
async import(specifier, parentURL, importAttributes, isEntryPoint = false) { | ||||||
const moduleJob = await this.getModuleJob(specifier, parentURL, importAttributes); | ||||||
const { module } = await moduleJob.run(); | ||||||
const { module } = await moduleJob.run(isEntryPoint); | ||||||
return module.getNamespace(); | ||||||
} | ||||||
|
||||||
|
@@ -568,6 +561,23 @@ function getHooksProxy() { | |||||
return hooksProxy; | ||||||
} | ||||||
|
||||||
let cascadedLoader; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity: why call it "cascaded" loader? |
||||||
|
||||||
/** | ||||||
* This is a singleton ESM loader that integrates the loader hooks, if any. | ||||||
* It it used by other internal built-ins when they need to load ESM code | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* while also respecting hooks. | ||||||
* When built-ins need access to this loader, they should do | ||||||
* require('internal/module/esm/loader').getOrInitializeCascadedLoader() | ||||||
* lazily only right before the loader is actually needed, and don't do it | ||||||
* in the top-level, to avoid circular dependencies. | ||||||
* @returns {ModuleLoader} | ||||||
*/ | ||||||
function getOrInitializeCascadedLoader() { | ||||||
cascadedLoader ??= createModuleLoader(); | ||||||
return cascadedLoader; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Register a single loader programmatically. | ||||||
* @param {string|import('url').URL} specifier | ||||||
|
@@ -598,12 +608,11 @@ function getHooksProxy() { | |||||
* ``` | ||||||
*/ | ||||||
function register(specifier, parentURL = undefined, options) { | ||||||
const moduleLoader = require('internal/process/esm_loader').esmLoader; | ||||||
if (parentURL != null && typeof parentURL === 'object' && !isURL(parentURL)) { | ||||||
options = parentURL; | ||||||
parentURL = options.parentURL; | ||||||
} | ||||||
moduleLoader.register( | ||||||
getOrInitializeCascadedLoader().register( | ||||||
specifier, | ||||||
parentURL ?? 'data:', | ||||||
options?.data, | ||||||
|
@@ -614,5 +623,6 @@ function register(specifier, parentURL = undefined, options) { | |||||
module.exports = { | ||||||
createModuleLoader, | ||||||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
getHooksProxy, | ||||||
getOrInitializeCascadedLoader, | ||||||
register, | ||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this method lacks a JSDoc, do you mind adding one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, didn't see this, feel free to follow up and add a comment if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird! I just looked through the history, and it seems this method never got a jsdoc when pretty much everything else did.