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 {
11
11
12
12
const {
13
13
getOptionValue,
14
- shouldNotRegisterESMLoader
14
+ noGlobalSearchPaths,
15
+ shouldNotRegisterESMLoader,
15
16
} = require ( 'internal/options' ) ;
16
17
const { reconnectZeroFillToggle } = require ( 'internal/buffer' ) ;
17
18
@@ -420,7 +421,9 @@ function initializeWASI() {
420
421
421
422
function initializeCJSLoader ( ) {
422
423
const CJSLoader = require ( 'internal/modules/cjs/loader' ) ;
423
- CJSLoader . Module . _initPaths ( ) ;
424
+ if ( ! noGlobalSearchPaths ) {
425
+ CJSLoader . Module . _initPaths ( ) ;
426
+ }
424
427
// TODO(joyeecheung): deprecate this in favor of a proper hook?
425
428
CJSLoader . Module . runMain =
426
429
require ( 'internal/modules/run_main' ) . executeUserEntryPoint ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- const { getOptions, shouldNotRegisterESMLoader } = internalBinding ( 'options' ) ;
3
+ const {
4
+ getOptions,
5
+ noGlobalSearchPaths,
6
+ shouldNotRegisterESMLoader,
7
+ } = internalBinding ( 'options' ) ;
4
8
5
9
let warnOnAllowUnauthorized = true ;
6
10
@@ -57,5 +61,6 @@ module.exports = {
57
61
} ,
58
62
getOptionValue,
59
63
getAllowUnauthorized,
60
- shouldNotRegisterESMLoader
64
+ noGlobalSearchPaths,
65
+ shouldNotRegisterESMLoader,
61
66
} ;
Original file line number Diff line number Diff line change @@ -886,6 +886,10 @@ inline bool Environment::hide_console_windows() const {
886
886
return flags_ & EnvironmentFlags::kHideConsoleWindows ;
887
887
}
888
888
889
+ inline bool Environment::no_global_search_paths () const {
890
+ return flags_ & EnvironmentFlags::kNoGlobalSearchPaths ;
891
+ }
892
+
889
893
bool Environment::filehandle_close_warning () const {
890
894
return emit_filehandle_warning_;
891
895
}
Original file line number Diff line number Diff line change @@ -1203,6 +1203,7 @@ class Environment : public MemoryRetainer {
1203
1203
inline bool owns_inspector () const ;
1204
1204
inline bool tracks_unmanaged_fds () const ;
1205
1205
inline bool hide_console_windows () const ;
1206
+ inline bool no_global_search_paths () const ;
1206
1207
inline uint64_t thread_id () const ;
1207
1208
inline worker::Worker* worker_context () const ;
1208
1209
Environment* worker_parent_env () const ;
Original file line number Diff line number Diff line change @@ -412,7 +412,12 @@ enum Flags : uint64_t {
412
412
// so that a worker thread can't load a native addon even if `execArgv`
413
413
// is overwritten and `--no-addons` is not specified but was specified
414
414
// for this Environment instance.
415
- kNoNativeAddons = 1 << 6
415
+ kNoNativeAddons = 1 << 6 ,
416
+ // Set this flag to disable searching modules from global paths like
417
+ // $HOME/.node_modules and $NODE_PATH. This is used by standalone apps that
418
+ // do not expect to have their behaviors changed because of globally
419
+ // installed modules.
420
+ kNoGlobalSearchPaths = 1 << 7
416
421
};
417
422
} // namespace EnvironmentFlags
418
423
Original file line number Diff line number Diff line change @@ -1073,6 +1073,12 @@ void Initialize(Local<Object> target,
1073
1073
Boolean::New (isolate, env->should_not_register_esm_loader ()))
1074
1074
.Check ();
1075
1075
1076
+ target
1077
+ ->Set (context,
1078
+ FIXED_ONE_BYTE_STRING (env->isolate (), " noGlobalSearchPaths" ),
1079
+ Boolean::New (isolate, env->no_global_search_paths ()))
1080
+ .Check ();
1081
+
1076
1082
Local<Object> types = Object::New (isolate);
1077
1083
NODE_DEFINE_CONSTANT (types, kNoOp );
1078
1084
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) {
572
572
worker->environment_flags_ |= EnvironmentFlags::kHideConsoleWindows ;
573
573
if (env->no_native_addons ())
574
574
worker->environment_flags_ |= EnvironmentFlags::kNoNativeAddons ;
575
+ if (env->no_global_search_paths ())
576
+ worker->environment_flags_ |= EnvironmentFlags::kNoGlobalSearchPaths ;
575
577
}
576
578
577
579
void Worker::StartThread (const FunctionCallbackInfo<Value>& args) {
You can’t perform that action at this time.
0 commit comments