From 1992c20dbf186bf1c754e287e668d4db9de27d9a Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 13 Nov 2024 23:38:08 +0000 Subject: [PATCH 1/4] 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 + .../node_modules/esm-package | 1 + .../esm-package-dependent/test-import.js | 15 +++ .../esm-package-dependent/test-require.js | 12 ++ .../esm-package/binding-export-default.cc | 17 +++ .../esm-package/binding-export-primitive.cc | 17 +++ test/addons/esm-package/binding.cc | 17 +++ test/addons/esm-package/binding.gyp | 19 ++++ test/addons/esm-package/package.json | 11 ++ test/addons/esm-package/test-esm.mjs | 57 ++++++++++ test/addons/esm-package/test-import.js | 7 ++ test/addons/esm-package/test-require.js | 6 + 20 files changed, 312 insertions(+), 26 deletions(-) create mode 120000 test/addons/esm-package-dependent/node_modules/esm-package create mode 100644 test/addons/esm-package-dependent/test-import.js create mode 100644 test/addons/esm-package-dependent/test-require.js create mode 100644 test/addons/esm-package/binding-export-default.cc create mode 100644 test/addons/esm-package/binding-export-primitive.cc create mode 100644 test/addons/esm-package/binding.cc create mode 100644 test/addons/esm-package/binding.gyp create mode 100644 test/addons/esm-package/package.json create mode 100644 test/addons/esm-package/test-esm.mjs create mode 100644 test/addons/esm-package/test-import.js create mode 100644 test/addons/esm-package/test-require.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 9efcf3953ffddf..d71542638b694f 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`