Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 5f0c1d6

Browse files
committed
Fix aleph_pkg_uri resolve
1 parent 442c51c commit 5f0c1d6

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

compiler/src/resolver.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ lazy_static! {
1717
r"@\d+(\.\d+){0,2}(\-[a-z0-9]+(\.[a-z0-9]+)?)?$"
1818
)
1919
.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();
2023
pub static ref RE_REACT_URL: Regex = Regex::new(
2124
r"^https?://(esm.sh|cdn.esm.sh|cdn.esm.sh.cn|esm.x-static.io)(/v\d+)?/react(\-dom)?(@[\^|~]{0,1}[0-9a-z\.\-]+)?([/|\?].*)?$"
2225
)
@@ -265,13 +268,11 @@ impl Resolver {
265268

266269
// fix deno.land/x/aleph url
267270
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()) {
269272
fixed_url = format!(
270273
"{}/{}",
271274
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(), ""),
275276
);
276277
}
277278
}
@@ -753,10 +754,7 @@ mod tests {
753754
imports.insert("~/".into(), "./".into());
754755
imports.insert("react".into(), "https://esm.sh/react".into());
755756
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());
760758
let mut resolver = Resolver::new(
761759
"/pages/index.tsx",
762760
"/",
@@ -767,7 +765,7 @@ mod tests {
767765
true,
768766
false,
769767
vec![],
770-
None,
768+
Some("https://deno.land/x/[email protected]".into()),
771769
Some(ReactOptions {
772770
version: "17.0.2".into(),
773771
esm_sh_build_version: 2,
@@ -830,20 +828,34 @@ mod tests {
830828
)
831829
);
832830
assert_eq!(
833-
resolver.resolve("https://deno.land/x/aleph/mod.ts", false),
831+
resolver.resolve("aleph/mod.ts", false),
834832
(
835833
"http://localhost:2020/mod.ts".into(),
836834
"http://localhost:2020/mod.ts".into()
837835
)
838836
);
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+
);
839851
assert_eq!(
840852
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",
842854
false
843855
),
844856
(
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()
847859
)
848860
);
849861
assert_eq!(

0 commit comments

Comments
 (0)