Skip to content

Commit 85292ff

Browse files
committed
build, compiler/typesutil: Don't use vendor directory to resolve js, nosync.
These core GopherJS packages are already embedded into the GopherJS build system via the gopherjspkg virtual filesystem. The gopherjspkg package can be safely vendored. Therefore, there's no need to try to use vendor directory to resolve those packages. This change makes it possible to use a vendored copy of GopherJS in a project, and use it to build any Go code. Fixes #415.
1 parent aebb4ea commit 85292ff

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

build/build.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,16 @@ func importWithSrcDir(bctx *build.Context, path string, srcDir string, mode buil
143143
case "crypto/x509", "os/user":
144144
// These stdlib packages have cgo and non-cgo versions (via build tags); we want the latter.
145145
bctx.CgoEnabled = false
146+
case "github.com/gopherjs/gopherjs/js", "github.com/gopherjs/gopherjs/nosync":
147+
// These packages are already embedded via gopherjspkg.FS virtual filesystem (which can be
148+
// safely vendored). Don't try to use vendor directory to resolve them.
149+
mode |= build.IgnoreVendor
146150
}
147151
pkg, err := bctx.Import(path, srcDir, mode)
148152
if err != nil {
149153
return nil, err
150154
}
151155

152-
// TODO: Resolve issue #415 and remove this temporary workaround.
153-
if strings.HasSuffix(pkg.ImportPath, "/vendor/github.com/gopherjs/gopherjs/js") {
154-
return nil, fmt.Errorf("vendoring github.com/gopherjs/gopherjs/js package is not supported, see https://github.com/gopherjs/gopherjs/issues/415")
155-
}
156-
157156
switch path {
158157
case "os":
159158
pkg.GoFiles = excludeExecutable(pkg.GoFiles) // Need to exclude executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.

compiler/typesutil/typesutil.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package typesutil
22

3-
import (
4-
"go/types"
5-
"strings"
6-
)
3+
import "go/types"
74

85
func IsJsPackage(pkg *types.Package) bool {
9-
return pkg != nil && (pkg.Path() == "github.com/gopherjs/gopherjs/js" || strings.HasSuffix(pkg.Path(), "/vendor/github.com/gopherjs/gopherjs/js"))
6+
return pkg != nil && pkg.Path() == "github.com/gopherjs/gopherjs/js"
107
}
118

129
func IsJsObject(t types.Type) bool {

0 commit comments

Comments
 (0)