Skip to content

Commit 9a67296

Browse files
zcbenzBethGriggs
authored andcommitted
src: add --no-global-search-paths cli option
PR-URL: #39754 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 51f9ad4 commit 9a67296

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
@@ -619,6 +619,14 @@ added: v9.0.0
619619
Disables runtime checks for `async_hooks`. These will still be enabled
620620
dynamically when `async_hooks` is enabled.
621621

622+
### `--no-global-search-paths`
623+
<!-- YAML
624+
added: REPLACEME
625+
-->
626+
627+
Do not search modules from global paths like `$HOME/.node_modules` and
628+
`$NODE_PATH`.
629+
622630
### `--no-warnings`
623631
<!-- YAML
624632
added: v6.0.0
@@ -1431,6 +1439,7 @@ Node.js options that are allowed are:
14311439
* `--no-deprecation`
14321440
* `--no-experimental-repl-await`
14331441
* `--no-force-async-hooks-checks`
1442+
* `--no-global-search-paths`
14341443
* `--no-warnings`
14351444
* `--node-memory-debug`
14361445
* `--openssl-config`

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ Disable the `node-addons` exports condition as well as disable loading native
282282
addons. When `--no-addons` is specified, calling `process.dlopen` or requiring
283283
a native C++ addon will fail and throw an exception.
284284
.
285+
.It Fl -no-global-search-paths
286+
Do not search modules from global paths.
287+
.
285288
.It Fl -no-warnings
286289
Silence all process warnings (including deprecations).
287290
.

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)