-
-
Notifications
You must be signed in to change notification settings - Fork 32k
esm: synchronise default path of ModuleLoader.load
#57390
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -29,13 +29,12 @@ const { | |||
* @param {ESModuleContext} context used to decorate error messages | ||||
* @returns {Promise<{ responseURL: string, source: string | BufferView }>} | ||||
*/ | ||||
async function getSource(url, context) { | ||||
function getSource(url, context) { | ||||
JakobJingleheimer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
const { protocol, href } = url; | ||||
const responseURL = href; | ||||
let source; | ||||
if (protocol === 'file:') { | ||||
const { readFile: readFileAsync } = require('internal/fs/promises').exports; | ||||
source = await readFileAsync(url); | ||||
source = readFileSync(url); | ||||
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. This converts to a blocking op, but I'm not sure if that matters. 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. The CommonJS node/lib/internal/modules/cjs/loader.js Line 1128 in fbe37d5
though CommonJS is fundamentally sync. I think it should be fine to use the same in ESM; @joyeecheung or anyone else, do you have any concerns? 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. Blocking fs is generally not problematic when your fs is fast enough (and not taking on the async overhead might make it faster, as nodejs/performance#151 shows). |
||||
} else if (protocol === 'data:') { | ||||
const result = dataURLProcessor(url); | ||||
if (result === 'failure') { | ||||
|
@@ -80,7 +79,7 @@ function getSourceSync(url, context) { | |||
* @param {LoadContext} context | ||||
* @returns {LoadReturn} | ||||
*/ | ||||
async function defaultLoad(url, context = kEmptyObject) { | ||||
function defaultLoad(url, context = kEmptyObject) { | ||||
let responseURL = url; | ||||
let { | ||||
importAttributes, | ||||
|
@@ -110,13 +109,13 @@ async function defaultLoad(url, context = kEmptyObject) { | |||
source = null; | ||||
} else if (format !== 'commonjs') { | ||||
if (source == null) { | ||||
({ responseURL, source } = await getSource(urlInstance, context)); | ||||
({ responseURL, source } = getSource(urlInstance, context)); | ||||
context = { __proto__: context, source }; | ||||
} | ||||
|
||||
if (format == null) { | ||||
// Now that we have the source for the module, run `defaultGetFormat` to detect its format. | ||||
format = await defaultGetFormat(urlInstance, context); | ||||
format = defaultGetFormat(urlInstance, context); | ||||
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.
|
||||
|
||||
if (format === 'commonjs') { | ||||
// For backward compatibility reasons, we need to discard the source in | ||||
|
Uh oh!
There was an error while loading. Please reload this page.