File tree Expand file tree Collapse file tree 7 files changed +31
-5
lines changed Expand file tree Collapse file tree 7 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ const {
1111
1212const {
1313 getOptionValue,
14- shouldNotRegisterESMLoader
14+ noGlobalSearchPaths,
15+ shouldNotRegisterESMLoader,
1516} = require ( 'internal/options' ) ;
1617const { reconnectZeroFillToggle } = require ( 'internal/buffer' ) ;
1718
@@ -420,7 +421,9 @@ function initializeWASI() {
420421
421422function initializeCJSLoader ( ) {
422423 const CJSLoader = require ( 'internal/modules/cjs/loader' ) ;
423- CJSLoader . Module . _initPaths ( ) ;
424+ if ( ! noGlobalSearchPaths ) {
425+ CJSLoader . Module . _initPaths ( ) ;
426+ }
424427 // TODO(joyeecheung): deprecate this in favor of a proper hook?
425428 CJSLoader . Module . runMain =
426429 require ( 'internal/modules/run_main' ) . executeUserEntryPoint ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const { getOptions, shouldNotRegisterESMLoader } = internalBinding ( 'options' ) ;
3+ const {
4+ getOptions,
5+ noGlobalSearchPaths,
6+ shouldNotRegisterESMLoader,
7+ } = internalBinding ( 'options' ) ;
48
59let warnOnAllowUnauthorized = true ;
610
@@ -57,5 +61,6 @@ module.exports = {
5761 } ,
5862 getOptionValue,
5963 getAllowUnauthorized,
60- shouldNotRegisterESMLoader
64+ noGlobalSearchPaths,
65+ shouldNotRegisterESMLoader,
6166} ;
Original file line number Diff line number Diff line change @@ -886,6 +886,10 @@ inline bool Environment::hide_console_windows() const {
886886 return flags_ & EnvironmentFlags::kHideConsoleWindows ;
887887}
888888
889+ inline bool Environment::no_global_search_paths () const {
890+ return flags_ & EnvironmentFlags::kNoGlobalSearchPaths ;
891+ }
892+
889893bool Environment::filehandle_close_warning () const {
890894 return emit_filehandle_warning_;
891895}
Original file line number Diff line number Diff line change @@ -1203,6 +1203,7 @@ class Environment : public MemoryRetainer {
12031203 inline bool owns_inspector () const ;
12041204 inline bool tracks_unmanaged_fds () const ;
12051205 inline bool hide_console_windows () const ;
1206+ inline bool no_global_search_paths () const ;
12061207 inline uint64_t thread_id () const ;
12071208 inline worker::Worker* worker_context () const ;
12081209 Environment* worker_parent_env () const ;
Original file line number Diff line number Diff line change @@ -413,7 +413,12 @@ enum Flags : uint64_t {
413413 // so that a worker thread can't load a native addon even if `execArgv`
414414 // is overwritten and `--no-addons` is not specified but was specified
415415 // for this Environment instance.
416- kNoNativeAddons = 1 << 6
416+ kNoNativeAddons = 1 << 6 ,
417+ // Set this flag to disable searching modules from global paths like
418+ // $HOME/.node_modules and $NODE_PATH. This is used by standalone apps that
419+ // do not expect to have their behaviors changed because of globally
420+ // installed modules.
421+ kNoGlobalSearchPaths = 1 << 7
417422};
418423} // namespace EnvironmentFlags
419424
Original file line number Diff line number Diff line change @@ -1078,6 +1078,12 @@ void Initialize(Local<Object> target,
10781078 Boolean::New (isolate, env->should_not_register_esm_loader ()))
10791079 .Check ();
10801080
1081+ target
1082+ ->Set (context,
1083+ FIXED_ONE_BYTE_STRING (env->isolate (), " noGlobalSearchPaths" ),
1084+ Boolean::New (isolate, env->no_global_search_paths ()))
1085+ .Check ();
1086+
10811087 Local<Object> types = Object::New (isolate);
10821088 NODE_DEFINE_CONSTANT (types, kNoOp );
10831089 NODE_DEFINE_CONSTANT (types, kV8Option );
Original file line number Diff line number Diff line change @@ -572,6 +572,8 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
572572 worker->environment_flags_ |= EnvironmentFlags::kHideConsoleWindows ;
573573 if (env->no_native_addons ())
574574 worker->environment_flags_ |= EnvironmentFlags::kNoNativeAddons ;
575+ if (env->no_global_search_paths ())
576+ worker->environment_flags_ |= EnvironmentFlags::kNoGlobalSearchPaths ;
575577}
576578
577579void Worker::StartThread (const FunctionCallbackInfo<Value>& args) {
You can’t perform that action at this time.
0 commit comments