Skip to content

esm: implement import.meta.main #57804

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

Lordfirespeed
Copy link

@Lordfirespeed Lordfirespeed commented Apr 9, 2025

Implements #57226

This PR supersedes #32223

Fixes: #57226

@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 Apr 9, 2025
@Lordfirespeed
Copy link
Author

Lordfirespeed commented Apr 9, 2025

@ljharb I would appreciate your review on this r.e. performance - I am particularly concerned about my changes in lib/internal/modules/esm/translators.js, since I'm not familiar with implications of assignment to a JS object associated with a native object.

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 97.87234% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.20%. Comparing base (a36981a) to head (3f8416a).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/modules/esm/loader.js 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57804      +/-   ##
==========================================
- Coverage   90.21%   90.20%   -0.02%     
==========================================
  Files         630      630              
  Lines      186391   186421      +30     
  Branches    36608    36614       +6     
==========================================
+ Hits       168161   168165       +4     
- Misses      11052    11069      +17     
- Partials     7178     7187       +9     
Files with missing lines Coverage Δ
lib/internal/modules/esm/initialize_import_meta.js 100.00% <100.00%> (ø)
lib/internal/modules/esm/translators.js 91.59% <100.00%> (+0.01%) ⬆️
lib/internal/modules/esm/utils.js 98.94% <100.00%> (+0.02%) ⬆️
lib/internal/worker.js 99.82% <100.00%> (+<0.01%) ⬆️
lib/internal/modules/esm/loader.js 94.95% <80.00%> (-0.09%) ⬇️

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Lordfirespeed
Copy link
Author

@ljharb I've moved the assignment into compileSourceTextModule, but I'm a bit confused

I think I can see where the cache is populated, but not where it is hit in compileSourceTextModule (unless it's in CPP?)
That leads me to think the cache gets hit at some point before the standard moduleStrategy function is used, which would mean moving the assignment either has no effect or is detrimental.

What am I missing?

@Lordfirespeed
Copy link
Author

I think CI should pass now. make -j$(nproc) test is passing locally.

@Lordfirespeed
Copy link
Author

I checked locally, it seems the test no longer fails with unusual character names using a relative import path.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina added notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version. labels Apr 18, 2025
Copy link
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @mcollina.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 18, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 18, 2025
@nodejs-github-bot
Copy link
Collaborator

@targos
Copy link
Member

targos commented Apr 18, 2025

There's a test for import.meta.main === false, but not for true, I think?

@LiviaMedeiros
Copy link
Member

There's a test for import.meta.main === false, but not for true, I think?

There is:

assert.strictEqual(import.meta.main, true);

But it would still be nice to cover more cases, e.g.:

  • worker threads
  • child process (exec, fork)
  • --eval

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 29, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 29, 2025
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the blocked PRs that are blocked by other issues or PRs. label Apr 29, 2025
@aduh95
Copy link
Contributor

aduh95 commented Apr 29, 2025

This should land after #58079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import.meta.main