diff options
author | Cheng Zhao <zcbenz@gmail.com> | 2021-08-16 09:58:58 +0900 |
---|---|---|
committer | Beth Griggs <bgriggs@redhat.com> | 2021-09-22 00:27:11 +0100 |
commit | 9a672961fafd896f68a39e2d55f744a625417a4d (patch) | |
tree | 893cea70524e3285db86df1ea4b5f8bfd9405e10 | |
parent | 51f9ad489707c728125d02457a48cab33bb3cc26 (diff) | |
download | node-new-9a672961fafd896f68a39e2d55f744a625417a4d.tar.gz |
src: add --no-global-search-paths cli option
PR-URL: https://github.com/nodejs/node/pull/39754
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
-rw-r--r-- | doc/api/cli.md | 9 | ||||
-rw-r--r-- | doc/node.1 | 3 | ||||
-rw-r--r-- | src/env-inl.h | 3 | ||||
-rw-r--r-- | src/node_options.cc | 5 | ||||
-rw-r--r-- | src/node_options.h | 1 |
5 files changed, 20 insertions, 1 deletions
diff --git a/doc/api/cli.md b/doc/api/cli.md index 7c0d5e88d4..f6e9e6cfca 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -619,6 +619,14 @@ added: v9.0.0 Disables runtime checks for `async_hooks`. These will still be enabled dynamically when `async_hooks` is enabled. +### `--no-global-search-paths` +<!-- YAML +added: REPLACEME +--> + +Do not search modules from global paths like `$HOME/.node_modules` and +`$NODE_PATH`. + ### `--no-warnings` <!-- YAML added: v6.0.0 @@ -1431,6 +1439,7 @@ Node.js options that are allowed are: * `--no-deprecation` * `--no-experimental-repl-await` * `--no-force-async-hooks-checks` +* `--no-global-search-paths` * `--no-warnings` * `--node-memory-debug` * `--openssl-config` diff --git a/doc/node.1 b/doc/node.1 index 9b285dedad..d127bb84cc 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -282,6 +282,9 @@ 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. . +.It Fl -no-global-search-paths +Do not search modules from global paths. +. .It Fl -no-warnings Silence all process warnings (including deprecations). . diff --git a/src/env-inl.h b/src/env-inl.h index 7c3838dd71..2b000ed9ac 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -887,7 +887,8 @@ inline bool Environment::hide_console_windows() const { } inline bool Environment::no_global_search_paths() const { - return flags_ & EnvironmentFlags::kNoGlobalSearchPaths; + return (flags_ & EnvironmentFlags::kNoGlobalSearchPaths) || + !options_->global_search_paths; } bool Environment::filehandle_close_warning() const { diff --git a/src/node_options.cc b/src/node_options.cc index 519dd4ce01..c7f153f1d8 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -407,6 +407,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { &EnvironmentOptions::allow_native_addons, kAllowedInEnvironment, true); + AddOption("--global-search-paths", + "disable global module search paths", + &EnvironmentOptions::global_search_paths, + kAllowedInEnvironment, + true); AddOption("--warnings", "silence all process warnings", &EnvironmentOptions::warnings, diff --git a/src/node_options.h b/src/node_options.h index d3899c4c39..e43bb15a9a 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -122,6 +122,7 @@ class EnvironmentOptions : public Options { bool deprecation = true; bool force_async_hooks_checks = true; bool allow_native_addons = true; + bool global_search_paths = true; bool warnings = true; bool force_context_aware = false; bool pending_deprecation = false; |