@@ -36,19 +36,20 @@ impl ImportMap {
36
36
let mut imports = IndexMap :: new ( ) ;
37
37
let mut scopes = IndexMap :: new ( ) ;
38
38
for ( k, v) in map. imports . iter ( ) {
39
- if v. starts_with ( "./" ) {
40
- imports. insert (
41
- k. into ( ) ,
39
+ let alias = if v. starts_with ( "./" ) {
40
+ let path = if v. ends_with ( "/" ) {
42
41
RelativePath :: new ( v)
43
42
. normalize ( )
44
- . to_path ( Path :: new ( "/" ) )
45
- . to_slash ( )
46
- . unwrap ( )
47
- . into ( ) ,
48
- ) ;
43
+ . to_relative_path_buf ( )
44
+ . join ( "/" )
45
+ } else {
46
+ RelativePath :: new ( v) . normalize ( ) . to_relative_path_buf ( )
47
+ } ;
48
+ format ! ( "/{}" , path)
49
49
} else {
50
- imports. insert ( k. into ( ) , v. into ( ) ) ;
51
- }
50
+ v. into ( )
51
+ } ;
52
+ imports. insert ( k. into ( ) , alias) ;
52
53
}
53
54
for ( k, v) in map. scopes . iter ( ) {
54
55
let mut map = IndexMap :: new ( ) ;
@@ -118,6 +119,8 @@ mod tests {
118
119
let mut scope_imports: SpecifierHashMap = HashMap :: new ( ) ;
119
120
imports. insert ( "@/" . into ( ) , "./" . into ( ) ) ;
120
121
imports. insert ( "~/" . into ( ) , "./" . into ( ) ) ;
122
+ imports. insert ( "comps/" . into ( ) , "./components/" . into ( ) ) ;
123
+ imports. insert ( "lib" . into ( ) , "./lib/mod.ts" . into ( ) ) ;
121
124
imports. insert ( "react" . into ( ) , "https://esm.sh/react" . into ( ) ) ;
122
125
imports. insert ( "react-dom/" . into ( ) , "https://esm.sh/react-dom/" . into ( ) ) ;
123
126
imports. insert (
@@ -135,6 +138,11 @@ mod tests {
135
138
import_map. resolve( "/pages/index.tsx" , "~/components/logo.tsx" ) ,
136
139
"/components/logo.tsx"
137
140
) ;
141
+ assert_eq ! (
142
+ import_map. resolve( "/pages/index.tsx" , "comps/logo.tsx" ) ,
143
+ "/components/logo.tsx"
144
+ ) ;
145
+ assert_eq ! ( import_map. resolve( "/pages/index.tsx" , "lib" ) , "/lib/mod.ts" ) ;
138
146
assert_eq ! (
139
147
import_map. resolve( "/app.tsx" , "react" ) ,
140
148
"https://esm.sh/react"
0 commit comments