Skip to content

Commit d7b27f2

Browse files
authored
add dom.extras and handle file url in fileExists (microsoft#6)
* add dom.extras lib * do not crash on file url in default fileexists
1 parent e035e69 commit d7b27f2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

internal/api/server.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"encoding/binary"
77
"fmt"
88
"io"
9+
"net/url"
10+
"path/filepath"
911
"runtime/debug"
1012
"strconv"
1113
"strings"
@@ -668,6 +670,18 @@ func (s *Server) DirectoryExists(path string) bool {
668670
return s.fs.DirectoryExists(path)
669671
}
670672

673+
func fileURLToPath(rawURL string) (string, error) {
674+
u, err := url.Parse(rawURL)
675+
if err != nil {
676+
return "", err
677+
}
678+
if u.Scheme != "file" {
679+
return "", fmt.Errorf("not a file URL: %s", u.Scheme)
680+
}
681+
// On Windows, url.Path starts with "/", e.g. /C:/path/to/file
682+
return filepath.FromSlash(u.Path), nil
683+
}
684+
671685
// FileExists implements vfs.FS.
672686
func (s *Server) FileExists(path string) bool {
673687
if s.enabledCallbacks&CallbackFileExists != 0 {
@@ -679,6 +693,13 @@ func (s *Server) FileExists(path string) bool {
679693
return string(result) == "true"
680694
}
681695
}
696+
if strings.HasPrefix(path, "file://") {
697+
path, err := fileURLToPath(path)
698+
if err != nil {
699+
panic(err)
700+
}
701+
return s.fs.FileExists(path)
702+
}
682703
return s.fs.FileExists(path)
683704
}
684705

internal/tsoptions/enummaps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ var LibMap = collections.NewOrderedMapFromList([]collections.MapEntry[string, an
130130
{Key: "deno.webgpu", Value: "lib.deno.webgpu.d.ts"},
131131
{Key: "deno.shared_globals", Value: "lib.deno.shared_globals.d.ts"},
132132
{Key: "deno.unstable", Value: "lib.deno.unstable.d.ts"},
133+
{Key: "dom.extras", Value: "lib.dom.extras.d.ts"},
133134
})
134135

135136
var (

0 commit comments

Comments
 (0)