@@ -135,7 +135,8 @@ impl DenoRuntime {
135
135
136
136
// TODO: check for other potential main paths (eg: index.js, index.tsx)
137
137
let mut main_module_url = base_url. join ( "index.ts" ) ?;
138
- if maybe_entrypoint. is_some ( ) {
138
+ let is_some_entry_point = maybe_entrypoint. is_some ( ) ;
139
+ if is_some_entry_point {
139
140
main_module_url = Url :: parse ( & maybe_entrypoint. unwrap ( ) ) ?;
140
141
}
141
142
@@ -148,6 +149,8 @@ impl DenoRuntime {
148
149
}
149
150
150
151
let mut maybe_arc_import_map = None ;
152
+ let only_module_code =
153
+ maybe_module_code. is_some ( ) && maybe_eszip. is_none ( ) && !is_some_entry_point;
151
154
152
155
let eszip = if let Some ( eszip_payload) = maybe_eszip {
153
156
eszip_payload
@@ -170,8 +173,16 @@ impl DenoRuntime {
170
173
let arc_emitter_factory = Arc :: new ( emitter_factory) ;
171
174
172
175
let main_module_url_file_path = main_module_url. clone ( ) . to_file_path ( ) . unwrap ( ) ;
176
+
177
+ let maybe_code = if only_module_code {
178
+ maybe_module_code
179
+ } else {
180
+ None
181
+ } ;
182
+
173
183
let eszip =
174
- generate_binary_eszip ( main_module_url_file_path, arc_emitter_factory) . await ?;
184
+ generate_binary_eszip ( main_module_url_file_path, arc_emitter_factory, maybe_code)
185
+ . await ?;
175
186
176
187
EszipPayloadKind :: Eszip ( eszip)
177
188
} ;
@@ -240,7 +251,7 @@ impl DenoRuntime {
240
251
module_code,
241
252
} = rt_provider;
242
253
243
- let mod_code = module_code. or ( maybe_module_code ) ;
254
+ let mod_code = module_code;
244
255
245
256
let extensions = vec ! [
246
257
sb_core_permissions:: init_ops( net_access_disabled) ,
@@ -426,7 +437,7 @@ impl DenoRuntime {
426
437
#[ cfg( test) ]
427
438
mod test {
428
439
use crate :: deno_runtime:: DenoRuntime ;
429
- use deno_core:: ModuleCode ;
440
+ use deno_core:: { FastString , ModuleCode } ;
430
441
use sb_graph:: emitter:: EmitterFactory ;
431
442
use sb_graph:: { generate_binary_eszip, EszipPayloadKind } ;
432
443
use sb_workers:: context:: {
@@ -442,6 +453,26 @@ mod test {
442
453
use tokio:: net:: UnixStream ;
443
454
use tokio:: sync:: mpsc;
444
455
456
+ #[ tokio:: test]
457
+ async fn test_module_code_no_eszip ( ) {
458
+ let ( worker_pool_tx, _) = mpsc:: unbounded_channel :: < UserWorkerMsgs > ( ) ;
459
+ DenoRuntime :: new ( WorkerContextInitOpts {
460
+ service_path : PathBuf :: from ( "./test_cases/" ) ,
461
+ no_module_cache : false ,
462
+ import_map_path : None ,
463
+ env_vars : Default :: default ( ) ,
464
+ events_rx : None ,
465
+ maybe_eszip : None ,
466
+ maybe_entrypoint : None ,
467
+ maybe_module_code : Some ( FastString :: from ( String :: from (
468
+ "Deno.serve((req) => new Response('Hello World'));" ,
469
+ ) ) ) ,
470
+ conf : { WorkerRuntimeOpts :: MainWorker ( MainWorkerRuntimeOpts { worker_pool_tx } ) } ,
471
+ } )
472
+ . await
473
+ . expect ( "It should not panic" ) ;
474
+ }
475
+
445
476
#[ tokio:: test]
446
477
#[ allow( clippy:: arc_with_non_send_sync) ]
447
478
async fn test_eszip_with_source_file ( ) {
@@ -451,7 +482,7 @@ mod test {
451
482
. unwrap ( ) ;
452
483
let path_buf = PathBuf :: from ( "./test_cases/eszip-source-test.ts" ) ;
453
484
let emitter_factory = Arc :: new ( EmitterFactory :: new ( ) ) ;
454
- let bin_eszip = generate_binary_eszip ( path_buf, emitter_factory. clone ( ) )
485
+ let bin_eszip = generate_binary_eszip ( path_buf, emitter_factory. clone ( ) , None )
455
486
. await
456
487
. unwrap ( ) ;
457
488
fs:: remove_file ( "./test_cases/eszip-source-test.ts" ) . unwrap ( ) ;
@@ -500,7 +531,7 @@ mod test {
500
531
let file = PathBuf :: from ( "./test_cases/eszip-silly-test/index.ts" ) ;
501
532
let service_path = PathBuf :: from ( "./test_cases/eszip-silly-test" ) ;
502
533
let emitter_factory = Arc :: new ( EmitterFactory :: new ( ) ) ;
503
- let binary_eszip = generate_binary_eszip ( file, emitter_factory. clone ( ) )
534
+ let binary_eszip = generate_binary_eszip ( file, emitter_factory. clone ( ) , None )
504
535
. await
505
536
. unwrap ( ) ;
506
537
0 commit comments