From 9e7b1bb38c11807f5da67a13adb5f432ad41f121 Mon Sep 17 00:00:00 2001 From: Dominic Elm Date: Mon, 13 Sep 2021 10:18:10 +0200 Subject: [PATCH] src: add option to disable loading native addons --- doc/api/cli.md | 10 ++++ doc/api/errors.md | 9 +++ doc/api/packages.md | 20 +++++-- doc/node.1 | 5 ++ lib/internal/modules/cjs/helpers.js | 10 +++- lib/internal/modules/esm/resolve.js | 11 +++- src/env-inl.h | 5 ++ src/env.h | 1 + src/node.h | 8 ++- src/node_binding.cc | 6 ++ src/node_errors.h | 1 + src/node_options.cc | 5 ++ src/node_options.h | 1 + src/node_worker.cc | 2 + test/addons/no-addons/binding.gyp | 9 +++ test/addons/no-addons/test-worker.js | 59 +++++++++++++++++++ test/addons/no-addons/test.js | 43 ++++++++++++++ test/es-module/test-esm-no-addons.mjs | 27 +++++++++ .../loader-with-custom-condition.mjs | 10 +++- .../node_modules/pkgexports/addons-entry.js | 3 + .../pkgexports/no-addons-entry.js | 3 + .../node_modules/pkgexports/package.json | 4 ++ .../test-no-addons-resolution-condition.js | 31 ++++++++++ 23 files changed, 274 insertions(+), 9 deletions(-) create mode 100644 test/addons/no-addons/binding.gyp create mode 100644 test/addons/no-addons/test-worker.js create mode 100644 test/addons/no-addons/test.js create mode 100644 test/es-module/test-esm-no-addons.mjs create mode 100644 test/fixtures/node_modules/pkgexports/addons-entry.js create mode 100644 test/fixtures/node_modules/pkgexports/no-addons-entry.js create mode 100644 test/parallel/test-no-addons-resolution-condition.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 222cfc0099ec40..c602104321e0a4 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -587,6 +587,15 @@ added: v7.10.0 This option is a no-op. It is kept for compatibility. +### `--no-addons` + + +Disable the `node-addons` exports condition as well as disable loading +native addons. When `--no-addons` is specified, calling `process.dlopen` or +requiring a native C++ addon will fail and throw an exception. + ### `--no-deprecation` + +Loading native addons has been disabled using [`--no-addons`][]. + ### `ERR_DLOPEN_FAILED`