@@ -29,6 +29,9 @@ pub struct DenoDir {
29
29
// This is where we cache compilation outputs. Example:
30
30
// /Users/rld/.deno/gen/f39a473452321cacd7c346a870efb0e3e1264b43.js
31
31
pub deps : PathBuf ,
32
+ // This splits to http and https deps
33
+ pub deps_http : PathBuf ,
34
+ pub deps_https : PathBuf ,
32
35
// If remote resources should be reloaded.
33
36
reload : bool ,
34
37
}
@@ -50,19 +53,27 @@ impl DenoDir {
50
53
} ;
51
54
let gen = root. as_path ( ) . join ( "gen" ) ;
52
55
let deps = root. as_path ( ) . join ( "deps" ) ;
56
+ let deps_http = deps. join ( "http" ) ;
57
+ let deps_https = deps. join ( "https" ) ;
53
58
54
59
let deno_dir = DenoDir {
55
60
root,
56
61
gen,
57
62
deps,
63
+ deps_http,
64
+ deps_https,
58
65
reload,
59
66
} ;
60
67
deno_fs:: mkdir ( deno_dir. gen . as_ref ( ) , 0o755 ) ?;
61
68
deno_fs:: mkdir ( deno_dir. deps . as_ref ( ) , 0o755 ) ?;
69
+ deno_fs:: mkdir ( deno_dir. deps_http . as_ref ( ) , 0o755 ) ?;
70
+ deno_fs:: mkdir ( deno_dir. deps_https . as_ref ( ) , 0o755 ) ?;
62
71
63
72
debug ! ( "root {}" , deno_dir. root. display( ) ) ;
64
73
debug ! ( "gen {}" , deno_dir. gen . display( ) ) ;
65
74
debug ! ( "deps {}" , deno_dir. deps. display( ) ) ;
75
+ debug ! ( "deps_http {}" , deno_dir. deps_http. display( ) ) ;
76
+ debug ! ( "deps_https {}" , deno_dir. deps_https. display( ) ) ;
66
77
67
78
Ok ( deno_dir)
68
79
}
@@ -236,13 +247,24 @@ impl DenoDir {
236
247
fn src_file_to_url ( self : & DenoDir , filename : & str ) -> String {
237
248
let filename_path = Path :: new ( filename) ;
238
249
if filename_path. starts_with ( & self . deps ) {
239
- let rest = filename_path. strip_prefix ( & self . deps ) . unwrap ( ) ;
250
+ let ( rest, prefix) = if filename_path. starts_with ( & self . deps_https ) {
251
+ let rest = filename_path. strip_prefix ( & self . deps_https ) . unwrap ( ) ;
252
+ let prefix = "https://" . to_string ( ) ;
253
+ ( rest, prefix)
254
+ } else if filename_path. starts_with ( & self . deps_http ) {
255
+ let rest = filename_path. strip_prefix ( & self . deps_http ) . unwrap ( ) ;
256
+ let prefix = "http://" . to_string ( ) ;
257
+ ( rest, prefix)
258
+ } else {
259
+ // TODO(kevinkassimo): change this to support other protocols than http
260
+ unimplemented ! ( )
261
+ } ;
240
262
// Windows doesn't support ":" in filenames, so we represent port using a
241
263
// special string.
242
264
// TODO(ry) This current implementation will break on a URL that has
243
265
// the default port but contains "_PORT" in the path.
244
266
let rest = rest. to_str ( ) . unwrap ( ) . replacen ( "_PORT" , ":" , 1 ) ;
245
- "http://" . to_string ( ) + & rest
267
+ prefix + & rest
246
268
} else {
247
269
String :: from ( filename)
248
270
}
@@ -290,12 +312,20 @@ impl DenoDir {
290
312
module_name = p. clone ( ) ;
291
313
filename = p;
292
314
}
293
- _ => {
315
+ "https" => {
316
+ module_name = j. to_string ( ) ;
317
+ filename = deno_fs:: normalize_path (
318
+ get_cache_filename ( self . deps_https . as_path ( ) , j) . as_ref ( ) ,
319
+ )
320
+ }
321
+ "http" => {
294
322
module_name = j. to_string ( ) ;
295
323
filename = deno_fs:: normalize_path (
296
- get_cache_filename ( self . deps . as_path ( ) , j) . as_ref ( ) ,
324
+ get_cache_filename ( self . deps_http . as_path ( ) , j) . as_ref ( ) ,
297
325
)
298
326
}
327
+ // TODO(kevinkassimo): change this to support other protocols than http
328
+ _ => unimplemented ! ( ) ,
299
329
}
300
330
301
331
debug ! ( "module_name: {}, filename: {}" , module_name, filename) ;
@@ -492,7 +522,7 @@ fn test_src_file_to_url_1() {
492
522
let ( _temp_dir, deno_dir) = test_setup ( ) ;
493
523
assert_eq ! ( "hello" , deno_dir. src_file_to_url( "hello" ) ) ;
494
524
assert_eq ! ( "/hello" , deno_dir. src_file_to_url( "/hello" ) ) ;
495
- let x = deno_dir. deps . join ( "hello/world.txt" ) ;
525
+ let x = deno_dir. deps_http . join ( "hello/world.txt" ) ;
496
526
assert_eq ! (
497
527
"http://hello/world.txt" ,
498
528
deno_dir. src_file_to_url( x. to_str( ) . unwrap( ) )
@@ -502,13 +532,35 @@ fn test_src_file_to_url_1() {
502
532
#[ test]
503
533
fn test_src_file_to_url_2 ( ) {
504
534
let ( _temp_dir, deno_dir) = test_setup ( ) ;
505
- let x = deno_dir. deps . join ( "localhost_PORT4545/world.txt" ) ;
535
+ assert_eq ! ( "hello" , deno_dir. src_file_to_url( "hello" ) ) ;
536
+ assert_eq ! ( "/hello" , deno_dir. src_file_to_url( "/hello" ) ) ;
537
+ let x = deno_dir. deps_https . join ( "hello/world.txt" ) ;
538
+ assert_eq ! (
539
+ "https://hello/world.txt" ,
540
+ deno_dir. src_file_to_url( x. to_str( ) . unwrap( ) )
541
+ ) ;
542
+ }
543
+
544
+ #[ test]
545
+ fn test_src_file_to_url_3 ( ) {
546
+ let ( _temp_dir, deno_dir) = test_setup ( ) ;
547
+ let x = deno_dir. deps_http . join ( "localhost_PORT4545/world.txt" ) ;
506
548
assert_eq ! (
507
549
"http://localhost:4545/world.txt" ,
508
550
deno_dir. src_file_to_url( x. to_str( ) . unwrap( ) )
509
551
) ;
510
552
}
511
553
554
+ #[ test]
555
+ fn test_src_file_to_url_4 ( ) {
556
+ let ( _temp_dir, deno_dir) = test_setup ( ) ;
557
+ let x = deno_dir. deps_https . join ( "localhost_PORT4545/world.txt" ) ;
558
+ assert_eq ! (
559
+ "https://localhost:4545/world.txt" ,
560
+ deno_dir. src_file_to_url( x. to_str( ) . unwrap( ) )
561
+ ) ;
562
+ }
563
+
512
564
// https://github.com/denoland/deno/blob/golang/os_test.go#L16-L87
513
565
#[ test]
514
566
fn test_resolve_module_1 ( ) {
@@ -568,7 +620,7 @@ fn test_resolve_module_2() {
568
620
"http://localhost:4545/testdata/subdir/print_hello.ts" ;
569
621
let expected_filename = deno_fs:: normalize_path (
570
622
deno_dir
571
- . deps
623
+ . deps_http
572
624
. join ( "localhost_PORT4545/testdata/subdir/print_hello.ts" )
573
625
. as_ref ( ) ,
574
626
) ;
@@ -585,14 +637,14 @@ fn test_resolve_module_3() {
585
637
let ( _temp_dir, deno_dir) = test_setup ( ) ;
586
638
587
639
let module_specifier_ =
588
- deno_dir
. deps . join ( "unpkg.com/[email protected] /index.ts" ) ;
640
+ deno_dir
. deps_http . join ( "unpkg.com/[email protected] /index.ts" ) ;
589
641
let module_specifier = module_specifier_. to_str ( ) . unwrap ( ) ;
590
642
let containing_file = "." ;
591
643
592
644
let expected_module_name =
"http://unpkg.com/[email protected] /index.ts" ;
593
645
let expected_filename = deno_fs:: normalize_path (
594
646
deno_dir
595
- . deps
647
+ . deps_http
596
648
. join ( "unpkg.com/[email protected] /index.ts" )
597
649
. as_ref ( ) ,
598
650
) ;
@@ -609,12 +661,17 @@ fn test_resolve_module_4() {
609
661
let ( _temp_dir, deno_dir) = test_setup ( ) ;
610
662
611
663
let module_specifier = "./util" ;
612
- let containing_file_ = deno_dir
. deps . join ( "unpkg.com/[email protected] /index.ts" ) ;
664
+ let containing_file_ =
665
+ deno_dir
. deps_http . join ( "unpkg.com/[email protected] /index.ts" ) ;
613
666
let containing_file = containing_file_. to_str ( ) . unwrap ( ) ;
614
667
668
+ // http containing files -> load relative import with http
615
669
let expected_module_name =
"http://unpkg.com/[email protected] /util" ;
616
670
let expected_filename = deno_fs:: normalize_path (
617
- deno_dir
. deps . join ( "unpkg.com/[email protected] /util" ) . as_ref ( ) ,
671
+ deno_dir
672
+ . deps_http
673
+ . join ( "unpkg.com/[email protected] /util" )
674
+ . as_ref ( ) ,
618
675
) ;
619
676
620
677
let ( module_name, filename) = deno_dir
@@ -628,12 +685,37 @@ fn test_resolve_module_4() {
628
685
fn test_resolve_module_5 ( ) {
629
686
let ( _temp_dir, deno_dir) = test_setup ( ) ;
630
687
688
+ let module_specifier = "./util" ;
689
+ let containing_file_ =
690
+ deno_dir
. deps_https . join ( "unpkg.com/[email protected] /index.ts" ) ;
691
+ let containing_file = containing_file_. to_str ( ) . unwrap ( ) ;
692
+
693
+ // https containing files -> load relative import with https
694
+ let expected_module_name =
"https://unpkg.com/[email protected] /util" ;
695
+ let expected_filename = deno_fs:: normalize_path (
696
+ deno_dir
697
+ . deps_https
698
+ . join ( "unpkg.com/[email protected] /util" )
699
+ . as_ref ( ) ,
700
+ ) ;
701
+
702
+ let ( module_name, filename) = deno_dir
703
+ . resolve_module ( module_specifier, containing_file)
704
+ . unwrap ( ) ;
705
+ assert_eq ! ( module_name, expected_module_name) ;
706
+ assert_eq ! ( filename, expected_filename) ;
707
+ }
708
+
709
+ #[ test]
710
+ fn test_resolve_module_6 ( ) {
711
+ let ( _temp_dir, deno_dir) = test_setup ( ) ;
712
+
631
713
let module_specifier = "http://localhost:4545/tests/subdir/mod2.ts" ;
632
714
let containing_file = add_root ! ( "/deno/tests/006_url_imports.ts" ) ;
633
715
let expected_module_name = "http://localhost:4545/tests/subdir/mod2.ts" ;
634
716
let expected_filename = deno_fs:: normalize_path (
635
717
deno_dir
636
- . deps
718
+ . deps_http
637
719
. join ( "localhost_PORT4545/tests/subdir/mod2.ts" )
638
720
. as_ref ( ) ,
639
721
) ;
0 commit comments