Skip to content
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

esm: synchronise default path of ModuleLoader.load #57390

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JakobJingleheimer
Copy link
Member

No description provided.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Mar 9, 2025
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultGetFormat is already sync

@JakobJingleheimer JakobJingleheimer changed the title esm: synchronise ModuleLoader esm: synchronise ModuleLoader.load Mar 9, 2025
@JakobJingleheimer JakobJingleheimer changed the title esm: synchronise ModuleLoader.load esm: synchronise default path of ModuleLoader.load Mar 9, 2025
const { readFile: readFileAsync } = require('internal/fs/promises').exports;
source = await readFileAsync(url);
source = readFileSync(url);
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CommonJS loadSource uses readFileSync:

return fs.readFileSync(filename, 'utf8');

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?

Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the effort. Tracking issue: #55782

We should also find some benchmarks that measure the performance impact of the overall syncification effort. Perhaps the existing ESM benchmarks are sufficient?

const { readFile: readFileAsync } = require('internal/fs/promises').exports;
source = await readFileAsync(url);
source = readFileSync(url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CommonJS loadSource uses readFileSync:

return fs.readFileSync(filename, 'utf8');

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants