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

Commit dd5912a

Browse files
committed
compiler: properly handle import map subdirs
1 parent f318f83 commit dd5912a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

compiler/src/import_map.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ impl ImportMap {
3939
if v.starts_with("./") {
4040
imports.insert(
4141
k.into(),
42-
RelativePath::new(v)
43-
.normalize()
44-
.to_path(Path::new("/"))
45-
.to_slash()
46-
.unwrap()
47-
.into(),
42+
format!(
43+
"/{}",
44+
RelativePath::new(v)
45+
.normalize()
46+
.to_relative_path_buf()
47+
.join("/")
48+
.to_string()
49+
),
4850
);
4951
} else {
5052
imports.insert(k.into(), v.into());
@@ -118,6 +120,7 @@ mod tests {
118120
let mut scope_imports: SpecifierHashMap = HashMap::new();
119121
imports.insert("@/".into(), "./".into());
120122
imports.insert("~/".into(), "./".into());
123+
imports.insert("comps/".into(), "./components/".into());
121124
imports.insert("react".into(), "https://esm.sh/react".into());
122125
imports.insert("react-dom/".into(), "https://esm.sh/react-dom/".into());
123126
imports.insert(
@@ -135,6 +138,10 @@ mod tests {
135138
import_map.resolve("/pages/index.tsx", "~/components/logo.tsx"),
136139
"/components/logo.tsx"
137140
);
141+
assert_eq!(
142+
import_map.resolve("/pages/index.tsx", "comps/logo.tsx"),
143+
"/components/logo.tsx"
144+
);
138145
assert_eq!(
139146
import_map.resolve("/app.tsx", "react"),
140147
"https://esm.sh/react"

0 commit comments

Comments
 (0)