Skip to content

Commit a4af087

Browse files
committed
compiler/gopherjspkg: Add package.
This package embeds the core GopherJS packages (js, nosync). It's similar to how native overrides for stdlib are embedded in the compiler/natives package. Pick only files in /fs and /nosync, and no subdirectories (if any are added, they won't get included by default).
1 parent f681903 commit a4af087

File tree

4 files changed

+283
-8
lines changed

4 files changed

+283
-8
lines changed

compiler/gopherjspkg/doc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Package gopherjspkg provides core GopherJS packages via a virtual filesystem.
2+
//
3+
// Core GopherJS packages are packages that are critical for GopherJS compiler
4+
// operation. They are needed to build the Go standard library with GopherJS.
5+
// Currently, they include:
6+
//
7+
// github.com/gopherjs/gopherjs/js
8+
// github.com/gopherjs/gopherjs/nosync
9+
//
10+
package gopherjspkg
11+
12+
//go:generate vfsgendev -source="github.com/gopherjs/gopherjs/compiler/gopherjspkg".FS -tag=gopherjsdev

compiler/gopherjspkg/fs.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// +build gopherjsdev
2+
3+
package gopherjspkg
4+
5+
import (
6+
"go/build"
7+
"log"
8+
"net/http"
9+
"os"
10+
pathpkg "path"
11+
12+
"github.com/shurcooL/httpfs/filter"
13+
)
14+
15+
// FS is a virtual filesystem that contains core GopherJS packages.
16+
var FS = filter.Keep(
17+
http.Dir(importPathToDir("github.com/gopherjs/gopherjs")),
18+
func(path string, fi os.FileInfo) bool {
19+
return path == "/" ||
20+
path == "/js" || (pathpkg.Dir(path) == "/js" && !fi.IsDir()) ||
21+
path == "/nosync" || (pathpkg.Dir(path) == "/nosync" && !fi.IsDir())
22+
},
23+
)
24+
25+
func importPathToDir(importPath string) string {
26+
p, err := build.Import(importPath, "", build.FindOnly)
27+
if err != nil {
28+
log.Fatalln(err)
29+
}
30+
return p.Dir
31+
}

0 commit comments

Comments
 (0)