Skip to content

Commit b9de51d

Browse files
committed
Replace vfsgen with go:embed
1 parent 559256d commit b9de51d

File tree

6 files changed

+26
-281
lines changed

6 files changed

+26
-281
lines changed

compiler/gopherjspkg/fs.go

+5-23
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
1-
//go:build gopherjsdev
2-
// +build gopherjsdev
3-
41
package gopherjspkg
52

63
import (
7-
"go/build"
4+
"io/fs"
85
"net/http"
9-
"os"
10-
pathpkg "path"
11-
12-
"github.com/shurcooL/httpfs/filter"
13-
log "github.com/sirupsen/logrus"
146
)
157

168
// FS is a virtual filesystem that contains core GopherJS packages.
17-
var FS = filter.Keep(
18-
http.Dir(importPathToDir("github.com/gopherjs/gopherjs")),
19-
func(path string, fi os.FileInfo) bool {
20-
return path == "/" ||
21-
path == "/js" || (pathpkg.Dir(path) == "/js" && !fi.IsDir()) ||
22-
path == "/nosync" || (pathpkg.Dir(path) == "/nosync" && !fi.IsDir())
23-
},
24-
)
9+
var FS http.FileSystem
2510

26-
func importPathToDir(importPath string) string {
27-
p, err := build.Import(importPath, "", build.FindOnly)
28-
if err != nil {
29-
log.Fatalln(err)
30-
}
31-
return p.Dir
11+
// RegisterFS allows setting the embedded fs from another package.
12+
func RegisterFS(fs fs.ReadDirFS) {
13+
FS = http.FS(fs)
3214
}

compiler/gopherjspkg/fs_vfsdata.go

-241
This file was deleted.

compiler/gopherjspkg/gen.go

-11
This file was deleted.

embed.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file exists to embed the js/ and nosync/ directories. The "embed"
2+
// package only supports embedding files stored beneath the directory level
3+
// of the go:embed directive, so we do the embedding here, then inject the
4+
// fs reference to the gopherjspkg package, where it's used. In the future we
5+
// may wish to refactor that, as the gopherjspkg package may not really be
6+
// necessary at all any more.
7+
8+
package main
9+
10+
import (
11+
"embed"
12+
13+
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
14+
)
15+
16+
//go:embed js nosync
17+
var fs embed.FS
18+
19+
func init() {
20+
gopherjspkg.RegisterFS(fs)
21+
}

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ require (
88
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86
99
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c
1010
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636
11-
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
12-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
1311
github.com/sirupsen/logrus v1.8.1
1412
github.com/spf13/cobra v1.2.1
1513
github.com/spf13/pflag v1.0.5

go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
209209
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
210210
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ=
211211
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
212-
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
213-
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
214212
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
215-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=
216-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
217213
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
218214
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
219215
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=

0 commit comments

Comments
 (0)