From e4b3e9871664b4bef881e5a34413549364b7304d Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 31 Jul 2022 00:17:10 +0300 Subject: [PATCH 1/3] esm: add `--import` flag --- 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 | 169 ++++++++++++++++++ .../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, 330 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..2d0c5d756d1178 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`