From 9f3a015b6072b193ad127fef502e790f6c2d0052 Mon Sep 17 00:00:00 2001 From: Dominic Elm Date: Thu, 2 Sep 2021 15:17:42 +0200 Subject: [PATCH] src: add option to disable loading native addons PR-URL: https://github.com/nodejs/node/pull/39977 Reviewed-By: Anna Henningsen Reviewed-By: Bradley Farias Reviewed-By: Guy Bedford Reviewed-By: Michael Dawson --- 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 | 29 +++++++++ 23 files changed, 272 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 e3294958f8c1d8..7c0d5e88d4d640 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -595,6 +595,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`