Skip to content

esm: implement import.meta.main - #57804

Merged
nodejs-github-bot merged 45 commits into
nodejs:mainfrom
Lordfirespeed:import-meta-main
May 26, 2025
Merged

esm: implement import.meta.main#57804
nodejs-github-bot merged 45 commits into
nodejs:mainfrom
Lordfirespeed:import-meta-main

Conversation

@Lordfirespeed

@LordfirespeedLordfirespeed commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

Implements #57226

This PR supersedes #32223

Fixes: #57226

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-botnodejs-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

Lordfirespeed commented Apr 9, 2025

Copy link
Copy Markdown
ContributorAuthor

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

Comment threadtest/es-module/test-esm-import-meta.mjs Outdated
Comment threaddoc/api/esm.md Outdated
@codecov

codecovBot commented Apr 9, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.22%. Comparing base (b197355) to head (41d80f0).
Report is 222 commits behind head on main.

Files with missing linesPatch %Lines
lib/internal/main/worker_thread.js92.85%1 Missing ⚠️
lib/internal/modules/esm/loader.js80.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #57804 +/- ##
==========================================
- Coverage 90.23% 90.22% -0.02% 
==========================================
Files 633 633 Lines 186818 186844 +26 Branches 36668 36682 +14 ==========================================
- Hits 168578 168575 -3 - Misses 11036 11045 +9 - Partials 7204 7224 +20 
Files with missing linesCoverage Δ
lib/internal/modules/esm/initialize_import_meta.js100.00% <100.00%> (ø)
lib/internal/modules/esm/translators.js91.59% <100.00%> (+0.01%)⬆️
lib/internal/modules/esm/utils.js98.94% <100.00%> (+0.02%)⬆️
lib/internal/worker.js99.82% <100.00%> (-0.01%)⬇️
lib/internal/main/worker_thread.js94.40% <92.85%> (-0.08%)⬇️
lib/internal/modules/esm/loader.js95.98% <80.00%> (-0.09%)⬇️

... and 36 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.

Comment threadlib/internal/modules/esm/translators.js Outdated
Comment threadlib/internal/modules/esm/translators.js Outdated
Comment threadlib/internal/modules/esm/initialize_import_meta.js Outdated
@Lordfirespeed

Copy link
Copy Markdown
ContributorAuthor

@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?

Comment threadlib/internal/modules/esm/translators.js Outdated
@joyeecheungjoyeecheung mentioned this pull request Apr 15, 2025
@Lordfirespeed

Copy link
Copy Markdown
ContributorAuthor

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

@Lordfirespeed

Copy link
Copy Markdown
ContributorAuthor

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

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollinamcollina 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
@github-actions

Copy link
Copy Markdown
Contributor

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

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 18, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 18, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@targos

Copy link
Copy Markdown
Member

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

@LiviaMedeiros

Copy link
Copy Markdown
Member

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

There is: https://github.com/nodejs/node/blob/37091e661b0d048252389d894858f42d960c3df1/test/es-module/test-esm-import-meta-main.mjs#L4

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

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment threadlib/internal/modules/esm/utils.js Outdated
aduh95 added a commit that referenced this pull request Jul 28, 2025
Notable changes:
deps:
* (SEMVER-MINOR) update amaro to 1.1.0 (Node.js GitHub Bot) #56350
doc:
* add islandryu to collaborators (Shima Ryuhei) #58714
esm:
* (SEMVER-MINOR) implement `import.meta.main` (Joe) #57804
fs:
* (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490
module:
* (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #56350
* (SEMVER-MINOR) unflag `--experimental-strip-types` (Marco Ippolito) #56350
permission:
* (SEMVER-MINOR) propagate permission model flags on spawn (Rafael Gonzaga) #58853
sqlite:
* (SEMVER-MINOR) add support for `readBigInts` option in db connection level (Miguel Marcondes Filho) #58697
src,permission:
* (SEMVER-MINOR) add support to `permission.has(addon)` (Rafael Gonzaga) #58951
url:
* (SEMVER-MINOR) add `fileURLToPathBuffer` API (James M Snell) #58700
watch:
* (SEMVER-MINOR) add `--watch-kill-signal` flag (Dario Piotrowicz) #58719
worker:
* (SEMVER-MINOR) make `Worker` async disposable (James M Snell) #58385
PR-URL: #59256
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
aduh95 added a commit that referenced this pull request Jul 31, 2025
Notable changes:
deps:
* (SEMVER-MINOR) update amaro to 1.1.0 (Node.js GitHub Bot) #56350
doc:
* add islandryu to collaborators (Shima Ryuhei) #58714
esm:
* (SEMVER-MINOR) implement `import.meta.main` (Joe) #57804
fs:
* (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490
module:
* (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #56350
* (SEMVER-MINOR) unflag `--experimental-strip-types` (Marco Ippolito) #56350
permission:
* (SEMVER-MINOR) propagate permission model flags on spawn (Rafael Gonzaga) #58853
sqlite:
* (SEMVER-MINOR) add support for `readBigInts` option in db connection level (Miguel Marcondes Filho) #58697
src,permission:
* (SEMVER-MINOR) add support to `permission.has(addon)` (Rafael Gonzaga) #58951
url:
* (SEMVER-MINOR) add `fileURLToPathBuffer` API (James M Snell) #58700
watch:
* (SEMVER-MINOR) add `--watch-kill-signal` flag (Dario Piotrowicz) #58719
worker:
* (SEMVER-MINOR) make `Worker` async disposable (James M Snell) #58385
PR-URL: #59256
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
aduh95 added a commit that referenced this pull request Jul 31, 2025
Notable changes:
deps:
* (SEMVER-MINOR) update amaro to 1.1.0 (Node.js GitHub Bot) #56350
doc:
* add islandryu to collaborators (Shima Ryuhei) #58714
esm:
* (SEMVER-MINOR) implement `import.meta.main` (Joe) #57804
fs:
* (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) #58490
module:
* (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) #56350
* (SEMVER-MINOR) unflag `--experimental-strip-types` (Marco Ippolito) #56350
permission:
* (SEMVER-MINOR) propagate permission model flags on spawn (Rafael Gonzaga) #58853
sqlite:
* (SEMVER-MINOR) add support for `readBigInts` option in db connection level (Miguel Marcondes Filho) #58697
src,permission:
* (SEMVER-MINOR) add support to `permission.has(addon)` (Rafael Gonzaga) #58951
url:
* (SEMVER-MINOR) add `fileURLToPathBuffer` API (James M Snell) #58700
watch:
* (SEMVER-MINOR) add `--watch-kill-signal` flag (Dario Piotrowicz) #58719
worker:
* (SEMVER-MINOR) make `Worker` async disposable (James M Snell) #58385
PR-URL: #59256
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
mete0rfish pushed a commit to mete0rfish/node-contribute that referenced this pull request Aug 9, 2025
Notable changes:
deps:
* (SEMVER-MINOR) update amaro to 1.1.0 (Node.js GitHub Bot) nodejs#56350
doc:
* add islandryu to collaborators (Shima Ryuhei) nodejs#58714
esm:
* (SEMVER-MINOR) implement `import.meta.main` (Joe) nodejs#57804
fs:
* (SEMVER-MINOR) allow correct handling of burst in fs-events with AsyncIterator (Philipp Dunkel) nodejs#58490
module:
* (SEMVER-MINOR) remove experimental warning from type stripping (Marco Ippolito) nodejs#56350
* (SEMVER-MINOR) unflag `--experimental-strip-types` (Marco Ippolito) nodejs#56350
permission:
* (SEMVER-MINOR) propagate permission model flags on spawn (Rafael Gonzaga) nodejs#58853
sqlite:
* (SEMVER-MINOR) add support for `readBigInts` option in db connection level (Miguel Marcondes Filho) nodejs#58697
src,permission:
* (SEMVER-MINOR) add support to `permission.has(addon)` (Rafael Gonzaga) nodejs#58951
url:
* (SEMVER-MINOR) add `fileURLToPathBuffer` API (James M Snell) nodejs#58700
watch:
* (SEMVER-MINOR) add `--watch-kill-signal` flag (Dario Piotrowicz) nodejs#58719
worker:
* (SEMVER-MINOR) make `Worker` async disposable (James M Snell) nodejs#58385
PR-URL: nodejs#59256
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested-v22.xPRs awaiting manual backport to the v22.x-staging branch.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.esmIssues and PRs related to the ECMAScript Modules implementation.needs-ciPRs that need a full CI run.notable-changePRs with changes that should be highlighted in changelogs.semver-minorPRs 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

13 participants

@Lordfirespeed@nodejs-github-bot@targos@LiviaMedeiros@aduh95@rauschma@js-choi@ljharb@mcollina@jasnell@guybedford@JakobJingleheimer@marco-ippolito