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

Commit 604d8c1

Browse files
committed
compiler: properly handle import map files
1 parent 032ef43 commit 604d8c1

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

compiler/dist/wasm-checksum.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<<<<<<< HEAD
2-
export const checksum = "7ae5ad874d024de2aa74d70607950875e8454ba5";
3-
=======
4-
export const checksum = "28cae3200e5875b6d03667a2dfe4c446ff29c15e";
5-
>>>>>>> Build compiler wasm
1+
export const checksum = "7ae5ad874d024de2aa74d70607950875e8454ba5";

compiler/dist/wasm.js

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/src/import_map.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,20 @@ impl ImportMap {
3636
let mut imports = IndexMap::new();
3737
let mut scopes = IndexMap::new();
3838
for (k, v) in map.imports.iter() {
39-
if v.starts_with("./") {
40-
imports.insert(
41-
k.into(),
42-
format!(
43-
"/{}",
44-
RelativePath::new(v)
45-
.normalize()
46-
.to_relative_path_buf()
47-
.join("/")
48-
.to_string()
49-
),
50-
);
39+
let alias = if v.starts_with("./") {
40+
let path = if v.ends_with("/") {
41+
RelativePath::new(v)
42+
.normalize()
43+
.to_relative_path_buf()
44+
.join("/")
45+
} else {
46+
RelativePath::new(v).normalize().to_relative_path_buf()
47+
};
48+
format!("/{}", path)
5149
} else {
52-
imports.insert(k.into(), v.into());
53-
}
50+
v.into()
51+
};
52+
imports.insert(k.into(), alias);
5453
}
5554
for (k, v) in map.scopes.iter() {
5655
let mut map = IndexMap::new();
@@ -121,6 +120,7 @@ mod tests {
121120
imports.insert("@/".into(), "./".into());
122121
imports.insert("~/".into(), "./".into());
123122
imports.insert("comps/".into(), "./components/".into());
123+
imports.insert("lib".into(), "./lib/mod.ts".into());
124124
imports.insert("react".into(), "https://esm.sh/react".into());
125125
imports.insert("react-dom/".into(), "https://esm.sh/react-dom/".into());
126126
imports.insert(
@@ -142,6 +142,7 @@ mod tests {
142142
import_map.resolve("/pages/index.tsx", "comps/logo.tsx"),
143143
"/components/logo.tsx"
144144
);
145+
assert_eq!(import_map.resolve("/pages/index.tsx", "lib"), "/lib/mod.ts");
145146
assert_eq!(
146147
import_map.resolve("/app.tsx", "react"),
147148
"https://esm.sh/react"

0 commit comments

Comments
 (0)