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: add --import flag #43942

Merged
merged 3 commits into from
Jul 31, 2022
Merged

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented Jul 22, 2022

Fixes: #40110

todo:

  • add tests

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. labels Jul 22, 2022
@MoLow MoLow added the esm Issues and PRs related to the ECMAScript Modules implementation. label Jul 22, 2022
doc/api/cli.md Outdated Show resolved Hide resolved
doc/api/cli.md Outdated Show resolved Hide resolved
lib/internal/process/esm_loader.js Outdated Show resolved Hide resolved
@JakobJingleheimer

This comment was marked as outdated.

@aduh95
Copy link
Contributor

aduh95 commented Jul 22, 2022

I thought this functionality is already possible with the globalPreload hook.

node/doc/api/esm.md

Lines 940 to 941 in d2fe72a

scope that the application runs in. This hook allows the return of a string
that is run as a sloppy-mode script on startup.

--import is about loading ESM, so it's definitely not the same thing as sloppy-mode script. See #40110 if you need context on this feature.

@MylesBorins
Copy link
Contributor

Is this still spec compliant?

@targos
Copy link
Member

targos commented Jul 22, 2022

@MylesBorins What part of the spec is relevant?

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.

This needs tests, including around variations of async behaviors:

  • An --import module that contains top-level await.
  • An --import module that does something async. Do we automatically await it before the next --import module runs? Before user code runs?

src/node_options.cc Outdated Show resolved Hide resolved
src/node_options.cc Outdated Show resolved Hide resolved
@guybedford
Copy link
Contributor

Overall I'm very much in favour of this, thanks for the PR!

I didn't follow the full thread, but what is the reasoning for starting with --experimental-import instead of just --import here? We can still label the feature as experimental without needing the experimental prefix IMO.

lib/internal/process/esm_loader.js Outdated Show resolved Hide resolved
lib/internal/process/esm_loader.js Outdated Show resolved Hide resolved
lib/internal/process/esm_loader.js Outdated Show resolved Hide resolved
lib/internal/process/esm_loader.js Outdated Show resolved Hide resolved
doc/api/cli.md Outdated Show resolved Hide resolved
@MoLow
Copy link
Member Author

MoLow commented Jul 25, 2022

added some tests, I am not sure if these are enough tests. please direct me to additional cases that need testing if I missed some.
in addition, I am ok with removing the --import from the flag name, just added it since it was what was written in the original issue
CC @GeoffreyBooth

doc/api/cli.md Outdated Show resolved Hide resolved
@MoLow MoLow changed the title esm: add --experimental-import flag esm: add --import flag Jul 25, 2022
@MoLow MoLow added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Jul 25, 2022
doc/api/cli.md Outdated Show resolved Hide resolved
doc/api/cli.md Outdated Show resolved Hide resolved
doc/api/cli.md Outdated Show resolved Hide resolved
doc/api/cli.md Outdated Show resolved Hide resolved
test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/fixtures/es-modules/print_imported.mjs Outdated Show resolved Hide resolved
lib/internal/process/esm_loader.js Show resolved Hide resolved
test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/fixtures/es-modules/esm-top-level-await.mjs Outdated Show resolved Hide resolved
test/fixtures/es-modules/esm-top-level-await.mjs Outdated Show resolved Hide resolved
test/fixtures/es-modules/print_imported.mjs Outdated Show resolved Hide resolved
test/fixtures/es-modules/esm-top-level-await.mjs Outdated Show resolved Hide resolved
@MylesBorins
Copy link
Contributor

@MylesBorins What part of the spec is relevant?

I was curious about how this work in populating the internal cache and global state. Will this work similarly to subsequent script tags for example.

There might not be a spec issue, just wanted to confirm

@GeoffreyBooth
Copy link
Member

Once this lands, I think we should mark it as blocked from release until we also land the “move loaders off thread” work, since that effort might effect --import. It would be similar to how we added the “backport-blocked-v18.x” tag to the chaining loaders PR until we had a few loaders-related PRs ready to release together. Thoughts? I know this will be experimental but I’m hopeful that the other PR isn’t too far behind and therefore we could release these together and minimize churn.

test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/es-module/test-esm-loader-http-imports.mjs Outdated Show resolved Hide resolved
test/es-module/test-esm-loader-http-imports.mjs Outdated Show resolved Hide resolved
test/fixtures/es-modules/print_3.mjs Outdated Show resolved Hide resolved
test/fixtures/es-modules/esm-top-level-await.mjs Outdated Show resolved Hide resolved
test/fixtures/es-modules/esm-top-level-await.mjs Outdated Show resolved Hide resolved
test/es-module/test-esm-import-flag.js Outdated Show resolved Hide resolved
test/fixtures/es-modules/print_3.mjs Outdated Show resolved Hide resolved
test/es-module/test-esm-loader-http-imports.mjs Outdated Show resolved Hide resolved
lib/internal/process/execution.js Outdated Show resolved Hide resolved
@GeoffreyBooth GeoffreyBooth added module Issues and PRs related to the module subsystem. loaders Issues and PRs related to ES module loaders labels Jul 26, 2022
@MoLow MoLow requested a review from benjamingr July 26, 2022 16:04
@aduh95 aduh95 removed the backport-blocked-v18.x PRs that should land on the v18.x-staging branch but are blocked by another PR's pending backport. label Sep 6, 2023
@ruyadorno ruyadorno added the backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. label Sep 7, 2023
@ruyadorno
Copy link
Member

This will need manual backport in case we want to land it in v18.

@GeoffreyBooth
Copy link
Member

Yes, we need this on 18 to support the module customization hooks.

aduh95 pushed a commit to aduh95/node that referenced this pull request Sep 7, 2023
PR-URL: nodejs#43942
Fixes: nodejs#40110
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@aduh95 aduh95 added backport-open-v18.x Indicate that the PR has an open backport. and removed backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. labels Sep 8, 2023
ruyadorno pushed a commit that referenced this pull request Sep 8, 2023
PR-URL: #43942
Backport-PR-URL: #49539
Fixes: #40110
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
ruyadorno added a commit that referenced this pull request Sep 8, 2023
Notable changes:

crypto:
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
doc:
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
@ruyadorno ruyadorno mentioned this pull request Sep 8, 2023
@ruyadorno ruyadorno added backported-to-v18.x PRs backported to the v18.x-staging branch. and removed backport-open-v18.x Indicate that the PR has an open backport. labels Sep 9, 2023
ruyadorno added a commit that referenced this pull request Sep 10, 2023
Notable changes:

crypto:
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
doc:
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno added a commit that referenced this pull request Sep 10, 2023
Notable changes:

crypto:
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
doc:
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno added a commit that referenced this pull request Sep 11, 2023
Notable changes:

crypto:
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
doc:
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) #48596
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno added a commit that referenced this pull request Sep 11, 2023
Notable changes:

build:
  * sync libuv header change (Jiawen Geng) #48078
crypto:
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
deps:
  * add missing thread-common.c in uv.gyp (Santiago Gimeno) #48078
  * upgrade to libuv 1.46.0 (Santiago Gimeno) #48078
  * upgrade to libuv 1.45.0 (Santiago Gimeno) #48078
doc:
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) #48596
fs, stream:
  * initial `Symbol.dispose` and `Symbol.asyncDispose` support (Moshe Atlow) #48518
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno added a commit that referenced this pull request Sep 12, 2023
Notable changes:

build:
  * sync libuv header change (Jiawen Geng) #48078
crypto:
  * update root certificates to NSS 3.93 (Node.js GitHub Bot) #49341
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
deps:
  * add missing thread-common.c in uv.gyp (Santiago Gimeno) #48078
  * upgrade to libuv 1.46.0 (Santiago Gimeno) #48078
  * upgrade to libuv 1.45.0 (Santiago Gimeno) #48078
doc:
  * add atlowChemi to collaborators (atlowChemi) #48757
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) #48596
fs, stream:
  * initial `Symbol.dispose` and `Symbol.asyncDispose` support (Moshe Atlow) #48518
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno pushed a commit that referenced this pull request Sep 13, 2023
PR-URL: #43942
Backport-PR-URL: #49539
Fixes: #40110
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
ruyadorno added a commit that referenced this pull request Sep 13, 2023
Notable changes:

build:
  * sync libuv header change (Jiawen Geng) #48078
crypto:
  * update root certificates to NSS 3.93 (Node.js GitHub Bot) #49341
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
deps:
  * add missing thread-common.c in uv.gyp (Santiago Gimeno) #48078
  * upgrade to libuv 1.46.0 (Santiago Gimeno) #48078
  * upgrade to libuv 1.45.0 (Santiago Gimeno) #48078
doc:
  * add atlowChemi to collaborators (atlowChemi) #48757
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) #48596
fs, stream:
  * initial `Symbol.dispose` and `Symbol.asyncDispose` support (Moshe Atlow) #48518
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno added a commit that referenced this pull request Sep 17, 2023
Notable changes:

build:
  * sync libuv header change (Jiawen Geng) #48078
crypto:
  * update root certificates to NSS 3.93 (Node.js GitHub Bot) #49341
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
deps:
  * add missing thread-common.c in uv.gyp (Santiago Gimeno) #48078
  * upgrade to libuv 1.46.0 (Santiago Gimeno) #48078
  * upgrade to libuv 1.45.0 (Santiago Gimeno) #48078
doc:
  * add atlowChemi to collaborators (atlowChemi) #48757
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) #48596
fs, stream:
  * initial `Symbol.dispose` and `Symbol.asyncDispose` support (Moshe Atlow) #48518
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
ruyadorno added a commit that referenced this pull request Sep 18, 2023
Notable changes:

build:
  * sync libuv header change (Jiawen Geng) #48078
crypto:
  * update root certificates to NSS 3.93 (Node.js GitHub Bot) #49341
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) #48416
deps:
  * add missing thread-common.c in uv.gyp (Santiago Gimeno) #48078
  * upgrade to libuv 1.46.0 (Santiago Gimeno) #48078
  * upgrade to libuv 1.45.0 (Santiago Gimeno) #48078
doc:
  * add atlowChemi to collaborators (atlowChemi) #48757
  * add vmoroz to collaborators (Vladimir Morozov) #48527
  * add kvakil to collaborators (Keyhan Vakil) #48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) #43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) #48596
fs, stream:
  * initial `Symbol.dispose` and `Symbol.asyncDispose` support (Moshe Atlow) #48518
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) #45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) #47885

PR-URL: #49220
@@ -2086,7 +2101,9 @@ done
[#42511]: https://github.com/nodejs/node/issues/42511
[Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/
[CommonJS]: modules.md
[CommonJS module]: modules.md
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you have two links to the same page here

alexfernandez pushed a commit to alexfernandez/node that referenced this pull request Nov 1, 2023
Notable changes:

build:
  * sync libuv header change (Jiawen Geng) nodejs#48078
crypto:
  * update root certificates to NSS 3.93 (Node.js GitHub Bot) nodejs#49341
  * update root certificates to NSS 3.90 (Node.js GitHub Bot) nodejs#48416
deps:
  * add missing thread-common.c in uv.gyp (Santiago Gimeno) nodejs#48078
  * upgrade to libuv 1.46.0 (Santiago Gimeno) nodejs#48078
  * upgrade to libuv 1.45.0 (Santiago Gimeno) nodejs#48078
doc:
  * add atlowChemi to collaborators (atlowChemi) nodejs#48757
  * add vmoroz to collaborators (Vladimir Morozov) nodejs#48527
  * add kvakil to collaborators (Keyhan Vakil) nodejs#48449
esm:
  * (SEMVER-MINOR) add `--import` flag (Moshe Atlow) nodejs#43942
events:
  * (SEMVER-MINOR) allow safely adding listener to abortSignal (Chemi Atlow) nodejs#48596
fs, stream:
  * initial `Symbol.dispose` and `Symbol.asyncDispose` support (Moshe Atlow) nodejs#48518
net:
  * add autoSelectFamily global getter and setter (Paolo Insogna) nodejs#45777
url:
  * (SEMVER-MINOR) add value argument to has and delete methods (Sankalp Shubham) nodejs#47885

PR-URL: nodejs#49220
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backported-to-v18.x PRs backported to the v18.x-staging branch. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem. process Issues and PRs related to the process subsystem. 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.

Add --import <module> flag for pre-loading ESM modules