From 0169b9c79e906f3701f896b5d3cdb2778d65905e 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 | 19 +++- doc/api/esm.md | 19 ++-- doc/api/module.md | 1 + doc/node.1 | 3 + lib/internal/modules/esm/formats.js | 5 + lib/internal/modules/esm/load.js | 3 + lib/internal/modules/esm/translators.js | 104 +++++++++++++++--- src/node_options.cc | 4 + src/node_options.h | 1 + test/addons/.gitignore | 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 | 40 +++++++ .../esm/node_modules/esm-package/package.json | 8 ++ test/addons/esm/test-esm.mjs | 58 ++++++++++ test/addons/esm/test-import-package.js | 15 +++ test/addons/esm/test-import.js | 7 ++ test/addons/esm/test-require-package.js | 12 ++ test/addons/esm/test-require.js | 6 + 20 files changed, 331 insertions(+), 26 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/node_modules/esm-package/package.json create mode 100644 test/addons/esm/test-esm.mjs create mode 100644 test/addons/esm/test-import-package.js create mode 100644 test/addons/esm/test-import.js create mode 100644 test/addons/esm/test-require-package.js create mode 100644 test/addons/esm/test-require.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 3a8e278df68f36..8ae5187c362dcd 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -45,8 +45,11 @@ 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; and with `.wasm` extensions when -[`--experimental-wasm-modules`][] is enabled. +`.mjs`, or `.cjs` extensions. With the following flags, additional file +extensions are enabled: + +* [`--experimental-wasm-modules`][] for files with `.wasm` extension. +* [`--experimental-addon-modules`][] for files with `.node` extension. ## Options @@ -880,6 +883,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-eventsource`