From 3a8a4c3cd0b114141815de2c6b0004d37e2782ee Mon Sep 17 00:00:00 2001 From: Dominic Elm Date: Thu, 2 Sep 2021 15:17:42 +0200 Subject: [PATCH 1/9] src: add option to disable loading native addons --- doc/api/cli.md | 10 +++++++ doc/node.1 | 4 +++ lib/internal/modules/cjs/helpers.js | 4 +++ lib/internal/modules/esm/resolve.js | 3 ++- src/node_binding.cc | 5 ++++ src/node_options.cc | 5 ++++ src/node_options.h | 1 + test/addons/no-addons/binding.gyp | 9 +++++++ test/addons/no-addons/test-worker.js | 15 +++++++++++ test/addons/no-addons/test.js | 19 ++++++++++++++ .../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 | 26 +++++++++++++++++++ 14 files changed, 110 insertions(+), 1 deletion(-) 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/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 48bfd090f65ce4..4eb618775b2a86 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -613,6 +613,14 @@ added: v9.0.0 Disables runtime checks for `async_hooks`. These will still be enabled dynamically when `async_hooks` is enabled. +### `--no-addons` + + +Enable a `no-addons` resolution 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-warnings` -Enable a `no-addons` resolution 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. +Enable a `no-addons` resolution 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-warnings` + +Enable a `no-addons` resolution 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` - -Enable a `no-addons` resolution 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-warnings` + +Loading native addons has been disabled using [`--no-addons`][]. + ### `ERR_DLOPEN_FAILED` -Enable a `no-addons` resolution 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. +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`