@@ -17,6 +17,9 @@ lazy_static! {
17
17
r"@\d+(\.\d+){0,2}(\-[a-z0-9]+(\.[a-z0-9]+)?)?$"
18
18
)
19
19
. unwrap( ) ;
20
+ pub static ref RE_DENO_X_ALEPH_URL : Regex = Regex :: new(
21
+ r"^https?://deno.land/x/aleph(@v?[0-9a-z\.\-]+)?/"
22
+ ) . unwrap( ) ;
20
23
pub static ref RE_REACT_URL : Regex = Regex :: new(
21
24
r"^https?://(esm.sh|cdn.esm.sh|cdn.esm.sh.cn|esm.x-static.io)(/v\d+)?/react(\-dom)?(@[\^|~]{0,1}[0-9a-z\.\-]+)?([/|\?].*)?$"
22
25
)
@@ -265,13 +268,11 @@ impl Resolver {
265
268
266
269
// fix deno.land/x/aleph url
267
270
if let Some ( aleph_pkg_uri) = & self . aleph_pkg_uri {
268
- if fixed_url . starts_with ( "https://deno.land/x/aleph/" ) {
271
+ if RE_DENO_X_ALEPH_URL . is_match ( fixed_url . as_str ( ) ) {
269
272
fixed_url = format ! (
270
273
"{}/{}" ,
271
274
aleph_pkg_uri. as_str( ) ,
272
- fixed_url
273
- . strip_prefix( "https://deno.land/x/aleph/" )
274
- . unwrap( )
275
+ RE_DENO_X_ALEPH_URL . replace( fixed_url. as_str( ) , "" ) ,
275
276
) ;
276
277
}
277
278
}
@@ -753,10 +754,7 @@ mod tests {
753
754
imports. insert ( "~/" . into ( ) , "./" . into ( ) ) ;
754
755
imports. insert ( "react" . into ( ) , "https://esm.sh/react" . into ( ) ) ;
755
756
imports. insert ( "react-dom/" . into ( ) , "https://esm.sh/react-dom/" . into ( ) ) ;
756
- imports. insert (
757
- "https://deno.land/x/aleph/" . into ( ) ,
758
- "http://localhost:2020/" . into ( ) ,
759
- ) ;
757
+ imports. insert ( "aleph/" . into ( ) , "http://localhost:2020/" . into ( ) ) ;
760
758
let mut resolver = Resolver :: new (
761
759
"/pages/index.tsx" ,
762
760
"/" ,
@@ -767,7 +765,7 @@ mod tests {
767
765
true ,
768
766
false ,
769
767
vec ! [ ] ,
770
- None ,
768
+ Some ( "https://deno.land/x/[email protected] " . into ( ) ) ,
771
769
Some ( ReactOptions {
772
770
version : "17.0.2" . into ( ) ,
773
771
esm_sh_build_version : 2 ,
@@ -830,20 +828,34 @@ mod tests {
830
828
)
831
829
) ;
832
830
assert_eq ! (
833
- resolver. resolve( "https://deno.land/x/ aleph/mod.ts" , false ) ,
831
+ resolver. resolve( "aleph/mod.ts" , false ) ,
834
832
(
835
833
"http://localhost:2020/mod.ts" . into( ) ,
836
834
"http://localhost:2020/mod.ts" . into( )
837
835
)
838
836
) ;
837
+ assert_eq ! (
838
+ resolver. resolve( "https://deno.land/x/aleph/mod.ts" , false ) ,
839
+ (
840
+ "https://deno.land/x/[email protected] /mod.ts" . into
( ) ,
841
+ "https://deno.land/x/[email protected] /mod.ts" . into
( )
842
+ )
843
+ ) ;
844
+ assert_eq ! (
845
+ resolver. resolve( "aleph/framework/react/components/Link.ts" , false ) ,
846
+ (
847
+ "http://localhost:2020/framework/react/components/Link.ts" . into( ) ,
848
+ "http://localhost:2020/framework/react/components/Link.ts" . into( )
849
+ )
850
+ ) ;
839
851
assert_eq ! (
840
852
resolver. resolve(
841
- "https://deno.land/x/aleph/framework/react/components/Link.ts" ,
853
+ "https://deno.land/x/aleph@v0.2.0 /framework/react/components/Link.ts" ,
842
854
false
843
855
) ,
844
856
(
845
- "http ://localhost:2020 /framework/react/components/Link.ts" . into( ) ,
846
- "http ://localhost:2020 /framework/react/components/Link.ts" . into( )
857
+ "https ://deno.land/x/[email protected] /framework/react/components/Link.ts" . into
( ) ,
858
+ "https ://deno.land/x/[email protected] /framework/react/components/Link.ts" . into
( )
847
859
)
848
860
) ;
849
861
assert_eq ! (
0 commit comments