From 829cfc6896fc0db5fb32286bc3decda4c57ac4e6 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 13 Nov 2024 23:38:08 +0000 Subject: [PATCH] esm: add experimental support for addon modules --- doc/api/cli.md | 15 +++- doc/api/esm.md | 19 ++-- doc/node.1 | 3 + lib/internal/modules/esm/formats.js | 5 ++ lib/internal/modules/esm/load.js | 3 + lib/internal/modules/esm/translators.js | 97 ++++++++++++++++++--- src/node_options.cc | 4 + src/node_options.h | 1 + test/addons/esm/binding-export-default.cc | 17 ++++ test/addons/esm/binding-export-primitive.cc | 17 ++++ test/addons/esm/binding.cc | 17 ++++ test/addons/esm/binding.gyp | 19 ++++ test/addons/esm/test-esm.mjs | 50 +++++++++++ test/addons/esm/test-import.js | 8 ++ test/addons/esm/test-require.js | 6 ++ 15 files changed, 258 insertions(+), 23 deletions(-) create mode 100644 test/addons/esm/binding-export-default.cc create mode 100644 test/addons/esm/binding-export-primitive.cc create mode 100644 test/addons/esm/binding.cc create mode 100644 test/addons/esm/binding.gyp create mode 100644 test/addons/esm/test-esm.mjs create mode 100644 test/addons/esm/test-import.js create mode 100644 test/addons/esm/test-require.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 9492aa2204dd6b..9e66b6df36b36c 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -48,7 +48,8 @@ Otherwise, the file is loaded using the CommonJS module loader. See When loading, the [ES module loader][Modules loaders] loads the program entry point, the `node` command will accept as input only files with `.js`, `.mjs`, or `.cjs` extensions; with `.wasm` extensions when -[`--experimental-wasm-modules`][] is enabled; and with no extension when +[`--experimental-wasm-modules`][] is enabled; with `.node` extensions when +[`--experimental-addon-modules`][] is enabled; and with no extension when [`--experimental-default-type=module`][] is passed. ## Options @@ -896,6 +897,16 @@ and `"` are usable. It is possible to run code containing inline types by passing [`--experimental-strip-types`][]. +### `--experimental-addon-modules` + + + +> Stability: 1.0 - Early development + +Enable experimental import support for `.node` addons. + ### `--experimental-default-type=type`