From af0921d877fcf6b572251283da51a24c02854c8e Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 31 Jul 2022 06:08:02 +0300 Subject: [PATCH] esm: add `--import` flag PR-URL: https://github.com/nodejs/node/pull/43942 Fixes: https://github.com/nodejs/node/issues/40110 Reviewed-By: Geoffrey Booth Reviewed-By: Benjamin Gruenbaum Reviewed-By: Jacob Smith Reviewed-By: Antoine du Hamel --- doc/api/cli.md | 25 ++- lib/internal/main/check_syntax.js | 27 ++- lib/internal/main/eval_stdin.js | 4 +- lib/internal/main/eval_string.js | 4 +- lib/internal/modules/run_main.js | 7 +- lib/internal/process/esm_loader.js | 29 ++- lib/internal/process/execution.js | 61 +++--- src/node_options.cc | 8 +- src/node_options.h | 4 +- test/es-module/test-esm-import-flag.mjs | 185 ++++++++++++++++++ .../test-esm-loader-http-imports.mjs | 38 +++- .../es-modules/esm-top-level-await.mjs | 5 + test/fixtures/es-modules/print-3.mjs | 1 + test/message/eval_messages.out | 4 + test/message/stdin_messages.out | 8 +- 15 files changed, 346 insertions(+), 64 deletions(-) create mode 100644 test/es-module/test-esm-import-flag.mjs create mode 100644 test/fixtures/es-modules/esm-top-level-await.mjs create mode 100644 test/fixtures/es-modules/print-3.mjs diff --git a/doc/api/cli.md b/doc/api/cli.md index b44eb542f8e0e8..f89573f77611c6 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -445,7 +445,8 @@ Only the root context is supported. There is no guarantee that `globalThis.Array` is indeed the default intrinsic reference. Code may break under this flag. -To allow polyfills to be added, `--require` runs before freezing intrinsics. +To allow polyfills to be added, +[`--require`][] and [`--import`][] both run before freezing intrinsics. ### `--force-node-api-uncaught-exceptions-policy` @@ -594,6 +595,18 @@ added: v0.11.15 Specify ICU data load path. (Overrides `NODE_ICU_DATA`.) +### `--import=module` + + + +Preload the specified module at startup. + +Follows [ECMAScript module][] resolution rules. +Use [`--require`][] to load a [CommonJS module][]. +Modules preloaded with `--require` will run before modules preloaded with `--import`. + ### `--input-type=type`