From 31c6fcf85d1ff2e4efc76c24178be49a513c8ffd 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 | 63 +++--- 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 +++- test/fixtures/errors/force_colors.snapshot | 2 +- .../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 +- 16 files changed, 348 insertions(+), 66 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 a60ef3929c6feb..206c75d4af95ae 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -530,7 +530,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` @@ -679,6 +680,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`