@@ -720,6 +720,7 @@ pub fn execute_stateless(
720720 wasm_default_max_bytes : usize ,
721721 fetch_config : Option < & fetch:: FetchConfig > ,
722722 console_tree : Option < sled:: Tree > ,
723+ module_loader_config : Option < & module_loader:: ModuleLoaderConfig > ,
723724) -> ( Result < String , String > , bool ) {
724725 let oom_flag = Arc :: new ( AtomicBool :: new ( false ) ) ;
725726
@@ -738,7 +739,10 @@ pub fn execute_stateless(
738739 // When the code contains ES module syntax (import/export) we need a
739740 // module loader that can resolve npm:/jsr:/URL specifiers.
740741 let module_loader: Option < Rc < dyn deno_core:: ModuleLoader > > = if use_modules {
741- Some ( Rc :: new ( module_loader:: NetworkModuleLoader :: new ( ) ) )
742+ match module_loader_config {
743+ Some ( config) => Some ( Rc :: new ( module_loader:: NetworkModuleLoader :: with_config ( config. clone ( ) ) ) ) ,
744+ None => Some ( Rc :: new ( module_loader:: NetworkModuleLoader :: new ( ) ) ) ,
745+ }
742746 } else {
743747 None
744748 } ;
@@ -825,6 +829,7 @@ pub fn execute_stateful(
825829 wasm_default_max_bytes : usize ,
826830 fetch_config : Option < & fetch:: FetchConfig > ,
827831 console_tree : Option < sled:: Tree > ,
832+ module_loader_config : Option < & module_loader:: ModuleLoaderConfig > ,
828833) -> ( Result < ( String , Vec < u8 > , String ) , String > , bool ) {
829834 let oom_flag = Arc :: new ( AtomicBool :: new ( false ) ) ;
830835
@@ -859,7 +864,10 @@ pub fn execute_stateful(
859864 }
860865
861866 let module_loader: Option < Rc < dyn deno_core:: ModuleLoader > > = if use_modules {
862- Some ( Rc :: new ( module_loader:: NetworkModuleLoader :: new ( ) ) )
867+ match module_loader_config {
868+ Some ( config) => Some ( Rc :: new ( module_loader:: NetworkModuleLoader :: with_config ( config. clone ( ) ) ) ) ,
869+ None => Some ( Rc :: new ( module_loader:: NetworkModuleLoader :: new ( ) ) ) ,
870+ }
863871 } else {
864872 None
865873 } ;
@@ -989,6 +997,8 @@ pub struct Engine {
989997 fetch_config : Option < Arc < fetch:: FetchConfig > > ,
990998 /// Execution registry for async execution tracking and console output.
991999 execution_registry : Option < Arc < ExecutionRegistry > > ,
1000+ /// Module loader configuration controlling external module access and OPA auditing.
1001+ module_loader_config : Arc < module_loader:: ModuleLoaderConfig > ,
9921002}
9931003
9941004impl Engine {
@@ -1009,6 +1019,11 @@ impl Engine {
10091019 wasm_modules : Arc :: new ( Vec :: new ( ) ) ,
10101020 fetch_config : None ,
10111021 execution_registry : None ,
1022+ module_loader_config : Arc :: new ( module_loader:: ModuleLoaderConfig {
1023+ allow_external : false ,
1024+ opa_client : None ,
1025+ opa_module_policy : None ,
1026+ } ) ,
10121027 }
10131028 }
10141029
@@ -1032,6 +1047,11 @@ impl Engine {
10321047 wasm_modules : Arc :: new ( Vec :: new ( ) ) ,
10331048 fetch_config : None ,
10341049 execution_registry : None ,
1050+ module_loader_config : Arc :: new ( module_loader:: ModuleLoaderConfig {
1051+ allow_external : false ,
1052+ opa_client : None ,
1053+ opa_module_policy : None ,
1054+ } ) ,
10351055 }
10361056 }
10371057
@@ -1059,6 +1079,12 @@ impl Engine {
10591079 self
10601080 }
10611081
1082+ /// Configure module loader settings (external module access and OPA auditing).
1083+ pub fn with_module_loader_config ( mut self , config : module_loader:: ModuleLoaderConfig ) -> Self {
1084+ self . module_loader_config = Arc :: new ( config) ;
1085+ self
1086+ }
1087+
10621088 /// Submit code for async execution. Returns an execution ID immediately.
10631089 /// V8 runs in a background task. Use `get_execution()` to poll status and
10641090 /// `get_execution_output()` to read console output.
@@ -1150,8 +1176,9 @@ impl Engine {
11501176 let wasm_default = self . wasm_default_max_bytes ;
11511177 let fc = self . fetch_config . clone ( ) ;
11521178 let ct = console_tree;
1179+ let mlc = self . module_loader_config . clone ( ) ;
11531180 let mut join_handle = tokio:: task:: spawn_blocking ( move || {
1154- execute_stateless ( & code, max_bytes, ih, & wasm, wasm_default, fc. as_deref ( ) , Some ( ct) )
1181+ execute_stateless ( & code, max_bytes, ih, & wasm, wasm_default, fc. as_deref ( ) , Some ( ct) , Some ( & mlc ) )
11551182 } ) ;
11561183
11571184 // Publish isolate handle for cancellation once it's available.
@@ -1201,11 +1228,12 @@ impl Engine {
12011228 let wasm_default = self . wasm_default_max_bytes ;
12021229 let fc = self . fetch_config . clone ( ) ;
12031230 let ct = console_tree;
1231+ let mlc = self . module_loader_config . clone ( ) ;
12041232
12051233 let snap_mutex = self . snapshot_mutex . clone ( ) ;
12061234 let mut join_handle = tokio:: task:: spawn_blocking ( move || {
12071235 let _guard = snap_mutex. blocking_lock ( ) ;
1208- execute_stateful ( & code, raw_snapshot, max_bytes, ih, & wasm, wasm_default, fc. as_deref ( ) , Some ( ct) )
1236+ execute_stateful ( & code, raw_snapshot, max_bytes, ih, & wasm, wasm_default, fc. as_deref ( ) , Some ( ct) , Some ( & mlc ) )
12091237 } ) ;
12101238
12111239 // Publish isolate handle for cancellation.
0 commit comments