Skip to content

Commit bc14859

Browse files
committed
src: add --no-global-search-paths cli option
1 parent efc5ddb commit bc14859

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

doc/api/cli.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,14 @@ added: v9.0.0
629629
Disables runtime checks for `async_hooks`. These will still be enabled
630630
dynamically when `async_hooks` is enabled.
631631

632+
### `--no-global-search-paths`
633+
<!-- YAML
634+
added: REPLACEME
635+
-->
636+
637+
Do not search modules from global paths like `$HOME/.node_modules` and
638+
`$NODE_PATH`.
639+
632640
### `--no-warnings`
633641
<!-- YAML
634642
added: v6.0.0
@@ -1442,6 +1450,7 @@ Node.js options that are allowed are:
14421450
* `--no-experimental-repl-await`
14431451
* `--no-extra-info-on-fatal-exception`
14441452
* `--no-force-async-hooks-checks`
1453+
* `--no-global-search-paths`
14451454
* `--no-warnings`
14461455
* `--node-memory-debug`
14471456
* `--openssl-config`

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ Disable the `node-addons` exports condition as well as disable loading native
285285
addons. When `--no-addons` is specified, calling `process.dlopen` or requiring
286286
a native C++ addon will fail and throw an exception.
287287
.
288+
.It Fl -no-global-search-paths
289+
Do not search modules from global paths.
290+
.
288291
.It Fl -no-warnings
289292
Silence all process warnings (including deprecations).
290293
.

src/env-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ inline bool Environment::hide_console_windows() const {
887887
}
888888

889889
inline bool Environment::no_global_search_paths() const {
890-
return flags_ & EnvironmentFlags::kNoGlobalSearchPaths;
890+
return (flags_ & EnvironmentFlags::kNoGlobalSearchPaths) ||
891+
!options_->global_search_paths;
891892
}
892893

893894
bool Environment::filehandle_close_warning() const {

src/node_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
407407
&EnvironmentOptions::allow_native_addons,
408408
kAllowedInEnvironment,
409409
true);
410+
AddOption("--global-search-paths",
411+
"disable global module search paths",
412+
&EnvironmentOptions::global_search_paths,
413+
kAllowedInEnvironment,
414+
true);
410415
AddOption("--warnings",
411416
"silence all process warnings",
412417
&EnvironmentOptions::warnings,

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class EnvironmentOptions : public Options {
122122
bool deprecation = true;
123123
bool force_async_hooks_checks = true;
124124
bool allow_native_addons = true;
125+
bool global_search_paths = true;
125126
bool warnings = true;
126127
bool force_context_aware = false;
127128
bool pending_deprecation = false;

0 commit comments

Comments
 (0)