6
6
"fmt"
7
7
"io"
8
8
"io/fs"
9
+ "net/url"
9
10
"os"
10
11
"path"
11
12
"path/filepath"
@@ -54,7 +55,7 @@ func (m *ImportMap) Load(imPath string, fsys fs.FS, opts ...func(string, io.Read
54
55
if err := m .Parse (data ); err != nil {
55
56
return err
56
57
}
57
- if err := m .Resolve (imPath , fsys ); err != nil {
58
+ if err := m .Resolve (imPath ); err != nil {
58
59
return err
59
60
}
60
61
for _ , apply := range opts {
@@ -74,29 +75,29 @@ func (m *ImportMap) Parse(data []byte) error {
74
75
return nil
75
76
}
76
77
77
- func (m * ImportMap ) Resolve (imPath string , fsys fs. FS ) error {
78
+ func (m * ImportMap ) Resolve (imPath string ) error {
78
79
// Resolve all paths relative to current file
79
80
for k , v := range m .Imports {
80
- m .Imports [k ] = resolveHostPath (imPath , v , fsys )
81
+ m .Imports [k ] = resolveHostPath (imPath , v )
81
82
}
82
83
for module , mapping := range m .Scopes {
83
84
for k , v := range mapping {
84
- m.Scopes [module ][k ] = resolveHostPath (imPath , v , fsys )
85
+ m.Scopes [module ][k ] = resolveHostPath (imPath , v )
85
86
}
86
87
}
87
88
return nil
88
89
}
89
90
90
- func resolveHostPath (jsonPath , hostPath string , fsys fs. FS ) string {
91
+ func resolveHostPath (jsonPath , hostPath string ) string {
91
92
// Leave absolute paths unchanged
92
93
if path .IsAbs (hostPath ) {
93
94
return hostPath
94
95
}
95
- resolved := path .Join (path .Dir (jsonPath ), hostPath )
96
- if _ , err := fs .Stat (fsys , filepath .FromSlash (resolved )); err != nil {
97
- // Leave URLs unchanged
96
+ // Leave URLs unchanged
97
+ if parsed , err := url .Parse (hostPath ); err == nil && len (parsed .Scheme ) > 0 {
98
98
return hostPath
99
99
}
100
+ resolved := path .Join (path .Dir (jsonPath ), hostPath )
100
101
// Directory imports need to be suffixed with /
101
102
// Ref: https://deno.com/[email protected] /basics/import_maps
102
103
if strings .HasSuffix (hostPath , "/" ) {
0 commit comments