Skip to content

Commit

Permalink
src: add --no-global-search-paths cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Aug 16, 2021
1 parent 48c880d commit d3ea98b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ added: v6.0.0

Silence all process warnings (including deprecations).

### `--no-global-search-paths`
<!-- YAML
added: v16.?.?
-->

Do not search modules from global paths like `$HOME/.node_modules` and
`$NODE_PATH`.

### `--node-memory-debug`
<!-- YAML
added: v15.0.0
Expand Down Expand Up @@ -1424,6 +1432,7 @@ Node.js options that are allowed are:
* `--no-experimental-repl-await`
* `--no-force-async-hooks-checks`
* `--no-warnings`
* `--no-global-search-paths`
* `--node-memory-debug`
* `--openssl-config`
* `--pending-deprecation`
Expand Down
3 changes: 3 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ These will still be enabled dynamically when `async_hooks` is enabled.
.It Fl -no-warnings
Silence all process warnings (including deprecations).
.
.It Fl -no-global-search-paths
Do not search modules from global paths.
.
.It Fl -node-memory-debug
Enable extra debug checks for memory leaks in Node.js internals. This is
usually only useful for developers debugging Node.js itself.
Expand Down
4 changes: 4 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ Environment::Environment(IsolateData* isolate_data,
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
options_->debug_options().host_port);

if (!options_->global_search_paths) {
flags_ |= EnvironmentFlags::kNoGlobalSearchPaths;
}

if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
set_abort_on_uncaught_exception(false);
}
Expand Down
5 changes: 5 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
&EnvironmentOptions::warnings,
kAllowedInEnvironment,
true);
AddOption("--global-search-paths",
"disable global module search paths",
&EnvironmentOptions::global_search_paths,
kAllowedInEnvironment,
true);
AddOption("--force-context-aware",
"disable loading non-context-aware addons",
&EnvironmentOptions::force_context_aware,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class EnvironmentOptions : public Options {
bool deprecation = true;
bool force_async_hooks_checks = true;
bool warnings = true;
bool global_search_paths = true;
bool force_context_aware = false;
bool pending_deprecation = false;
bool preserve_symlinks = false;
Expand Down

0 comments on commit d3ea98b

Please sign in to comment.