Skip to content

Commit

Permalink
src: add --no-global-search-paths cli option
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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>
  • Loading branch information
zcbenz authored and targos committed Sep 18, 2021
1 parent e4852e3 commit d9791d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/api/cli.md
Expand Up @@ -629,6 +629,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
Expand Down Expand Up @@ -1442,6 +1450,7 @@ Node.js options that are allowed are:
* `--no-experimental-repl-await`
* `--no-extra-info-on-fatal-exception`
* `--no-force-async-hooks-checks`
* `--no-global-search-paths`
* `--no-warnings`
* `--node-memory-debug`
* `--openssl-config`
Expand Down
3 changes: 3 additions & 0 deletions doc/node.1
Expand Up @@ -285,6 +285,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).
.
Expand Down
3 changes: 2 additions & 1 deletion src/env-inl.h
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/node_options.cc
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Expand Up @@ -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;
Expand Down

0 comments on commit d9791d9

Please sign in to comment.