Skip to content

Commit 3c74d21

Browse files
authored
Merge pull request #75 from gopherjs/go1.18
Upgrade Playground to GopherJS 1.18.0-beta1
2 parents 9480d85 + 302f27f commit 3c74d21

File tree

220 files changed

+293
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+293
-165
lines changed

playground/README.md

Lines changed: 9 additions & 0 deletions

playground/gen.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
//go:generate ./update.sh
1+
//go:generate go run ./internal/cmd/precompile
2+
//go:generate go install github.com/gopherjs/gopherjs
3+
//go:generate gopherjs build -m .
24

35
package main

playground/go.mod

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ module github.com/gopherjs/gopherjs.github.io/playground
33
go 1.17
44

55
require (
6-
github.com/gopherjs/gopherjs v0.0.0-20211108205335-ed9a9b14a747
6+
github.com/gopherjs/gopherjs v1.18.0-beta1
77
github.com/neelance/go-angularjs v0.0.0-20170205214111-8c6312cca6e2
8-
golang.org/x/tools v0.1.7
8+
github.com/sirupsen/logrus v1.8.1
9+
golang.org/x/tools v0.1.12
910
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2
1011
honnef.co/go/js/xhr v0.0.0-20150307031022-00e3346113ae
1112
)
1213

1314
require (
15+
github.com/fsnotify/fsnotify v1.5.1 // indirect
1416
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86 // indirect
17+
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c // indirect
18+
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
19+
github.com/stretchr/testify v1.7.0 // indirect
20+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
21+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1522
honnef.co/go/js/util v0.0.0-20150216223935-96b8dd9d1621 // indirect
1623
)

playground/go.sum

Lines changed: 40 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Program precompile updates pre-built standard library packages for the
2+
// playground.
3+
//
4+
// This script performs the following sequence of steps:
5+
//
6+
// - Enumerate all standard packages that should be available in the playground.
7+
// - Precompile them, including transitive dependencies.
8+
// - Delete all old precompiled archive.
9+
// - Write all new precompiled archive in their place.
10+
//
11+
// This will use the same GopherJS version as specified in the playground gm.mod
12+
// to ensure consistency. The script uses GopherJS compiler API directly, so
13+
// it doesn't require the GopherJS tool to be installed.
14+
package main
15+
16+
import (
17+
"flag"
18+
"fmt"
19+
gobuild "go/build"
20+
"os"
21+
"path/filepath"
22+
"strings"
23+
24+
"github.com/gopherjs/gopherjs/build"
25+
"github.com/gopherjs/gopherjs/compiler"
26+
log "github.com/sirupsen/logrus"
27+
)
28+
29+
type logLevelFlag struct{ log.Level }
30+
31+
func (l *logLevelFlag) Set(raw string) error { return l.UnmarshalText([]byte(raw)) }
32+
33+
var (
34+
logLevel logLevelFlag = logLevelFlag{Level: log.ErrorLevel}
35+
)
36+
37+
func init() {
38+
flag.Var(&logLevel, "log_level", "Default logging level.")
39+
}
40+
41+
func run() error {
42+
s, err := build.NewSession(&build.Options{
43+
Verbose: true,
44+
Minify: true,
45+
NoCache: true,
46+
})
47+
if err != nil {
48+
return fmt.Errorf("failed to create a build session: %w", err)
49+
}
50+
51+
packages, err := s.XContext().Match([]string{"std"})
52+
if err != nil {
53+
return fmt.Errorf("failed to enumerate standard library packages")
54+
}
55+
packages = importable(packages)
56+
packages = append(packages, "github.com/gopherjs/gopherjs/js", "github.com/gopherjs/gopherjs/nosync")
57+
58+
for _, pkg := range packages {
59+
_, err := s.BuildImportPath(pkg)
60+
if err != nil {
61+
return fmt.Errorf("failed to precompile package %q: %w", pkg, err)
62+
}
63+
}
64+
65+
target, err := targetDir(s)
66+
if err := os.RemoveAll(target); err != nil {
67+
return fmt.Errorf("failed to clean out old precompiled archives: %w", err)
68+
}
69+
70+
for _, archive := range s.UpToDateArchives {
71+
if err := writeArchive(target, archive); err != nil {
72+
return fmt.Errorf("failed to write package %q archive: %w", archive.ImportPath, err)
73+
}
74+
}
75+
76+
return nil
77+
}
78+
79+
func writeArchive(target string, archive *compiler.Archive) error {
80+
path := filepath.Join(target, filepath.FromSlash(archive.ImportPath)+".a.js")
81+
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
82+
return fmt.Errorf("failed to create precompiled package directory %q: %w", filepath.Dir(path), err)
83+
}
84+
f, err := os.Create(path)
85+
if err != nil {
86+
return fmt.Errorf("failed to create precompiled archive %q: %w", path, err)
87+
}
88+
defer f.Close()
89+
90+
return compiler.WriteArchive(archive, f)
91+
}
92+
93+
// targetDir returns path to the directory where precompiled packages must be
94+
// stored.
95+
func targetDir(s *build.Session) (string, error) {
96+
pkg, err := s.XContext().Import("github.com/gopherjs/gopherjs.github.io/playground", "", gobuild.FindOnly)
97+
if err != nil {
98+
return "", fmt.Errorf("failed to find playground package directory: %w", err)
99+
}
100+
target := filepath.Join(pkg.Dir, "pkg")
101+
if _, err := os.Stat(target); os.IsNotExist(err) {
102+
return "", fmt.Errorf("target directory %q not found", target)
103+
}
104+
return target, nil
105+
}
106+
107+
// importable excludes packages that are incompatible with GopherJS or can't be
108+
// directly imported by the user code. The remaining packages will be used as a
109+
// starting points for precompilation.
110+
func importable(all []string) []string {
111+
result := []string{}
112+
for _, pkg := range all {
113+
switch {
114+
case strings.HasPrefix(pkg, "vendor/"),
115+
strings.Contains(pkg, "internal"),
116+
strings.Contains(pkg, "pprof"),
117+
strings.Contains(pkg, "plugin"):
118+
continue
119+
default:
120+
result = append(result, pkg)
121+
}
122+
}
123+
return result
124+
}
125+
126+
func main() {
127+
flag.Parse()
128+
log.SetLevel(logLevel.Level)
129+
if err := run(); err != nil {
130+
log.Fatalf("Precompilation failed: %v", err)
131+
}
132+
}

playground/pkg/archive/tar.a.js

-119 KB
Binary file not shown.

playground/pkg/archive/zip.a.js

-72.7 KB
Binary file not shown.

playground/pkg/bufio.a.js

-29.1 KB
Binary file not shown.

playground/pkg/bytes.a.js

-33.1 KB
Binary file not shown.

playground/pkg/compress/bzip2.a.js

-22.8 KB
Binary file not shown.

playground/pkg/compress/flate.a.js

-80.3 KB
Binary file not shown.

playground/pkg/compress/gzip.a.js

-18.6 KB
Binary file not shown.

playground/pkg/compress/lzw.a.js

-16.5 KB
Binary file not shown.

playground/pkg/compress/zlib.a.js

-11 KB
Binary file not shown.

playground/pkg/container/heap.a.js

-4.45 KB
Binary file not shown.

playground/pkg/container/list.a.js

-2.69 KB
Binary file not shown.

playground/pkg/container/ring.a.js

-1.53 KB
Binary file not shown.

playground/pkg/context.a.js

-15 KB
Binary file not shown.

playground/pkg/crypto.a.js

-1.85 KB
Binary file not shown.

playground/pkg/crypto/aes.a.js

-10.3 KB
Binary file not shown.

playground/pkg/crypto/cipher.a.js

-27.4 KB
Binary file not shown.

playground/pkg/crypto/des.a.js

-12.2 KB
Binary file not shown.

playground/pkg/crypto/dsa.a.js

-9.39 KB
Binary file not shown.

playground/pkg/crypto/ecdsa.a.js

-17.5 KB
Binary file not shown.

playground/pkg/crypto/ed25519.a.js

-8.56 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

playground/pkg/crypto/elliptic.a.js

-111 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

playground/pkg/crypto/hmac.a.js

-6.26 KB
Binary file not shown.
-1.02 KB
Binary file not shown.
-269 Bytes
Binary file not shown.

playground/pkg/crypto/md5.a.js

-9.16 KB
Binary file not shown.

playground/pkg/crypto/rand.a.js

-5.43 KB
Binary file not shown.

playground/pkg/crypto/rc4.a.js

-1.72 KB
Binary file not shown.

playground/pkg/crypto/rsa.a.js

-43.9 KB
Binary file not shown.

playground/pkg/crypto/sha1.a.js

-13.8 KB
Binary file not shown.

playground/pkg/crypto/sha256.a.js

-10.1 KB
Binary file not shown.

playground/pkg/crypto/sha512.a.js

-7.81 KB
Binary file not shown.

playground/pkg/crypto/subtle.a.js

-774 Bytes
Binary file not shown.

playground/pkg/crypto/tls.a.js

-451 KB
Binary file not shown.

playground/pkg/crypto/x509.a.js

-219 KB
Binary file not shown.

playground/pkg/crypto/x509/pkix.a.js

-8.95 KB
Binary file not shown.

playground/pkg/database/sql.a.js

-174 KB
Binary file not shown.
-15.6 KB
Binary file not shown.

playground/pkg/debug/buildinfo.a.js

28.6 KB
Binary file not shown.

playground/pkg/debug/dwarf.a.js

-105 KB
Binary file not shown.

playground/pkg/debug/elf.a.js

-80.8 KB
Binary file not shown.

playground/pkg/debug/gosym.a.js

-27.4 KB
Binary file not shown.

playground/pkg/debug/macho.a.js

-37.8 KB
Binary file not shown.

playground/pkg/debug/pe.a.js

-43.7 KB
Binary file not shown.

playground/pkg/debug/plan9obj.a.js

-10.1 KB
Binary file not shown.

playground/pkg/embed.a.js

-7.99 KB
Binary file not shown.

playground/pkg/encoding.a.js

-338 Bytes
Binary file not shown.

playground/pkg/encoding/ascii85.a.js

-7.94 KB
Binary file not shown.

playground/pkg/encoding/asn1.a.js

-82.6 KB
Binary file not shown.

playground/pkg/encoding/base32.a.js

-15.3 KB
Binary file not shown.

playground/pkg/encoding/base64.a.js

-16.1 KB
Binary file not shown.

playground/pkg/encoding/binary.a.js

-46.8 KB
Binary file not shown.

playground/pkg/encoding/csv.a.js

-16 KB
Binary file not shown.

playground/pkg/encoding/gob.a.js

-228 KB
Binary file not shown.

playground/pkg/encoding/hex.a.js

-9.74 KB
Binary file not shown.

playground/pkg/encoding/json.a.js

-140 KB
Binary file not shown.

playground/pkg/encoding/pem.a.js

-16.5 KB
Binary file not shown.

playground/pkg/encoding/xml.a.js

-148 KB
Binary file not shown.

playground/pkg/errors.a.js

-4.26 KB
Binary file not shown.

playground/pkg/expvar.a.js

-14.1 KB
Binary file not shown.

playground/pkg/flag.a.js

-38.5 KB
Binary file not shown.

playground/pkg/fmt.a.js

-107 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

playground/pkg/go/ast.a.js

-128 KB
Binary file not shown.

playground/pkg/go/build.a.js

-101 KB
Binary file not shown.
-19.9 KB
Binary file not shown.

playground/pkg/go/constant.a.js

-70.6 KB
Binary file not shown.

playground/pkg/go/doc.a.js

-86.7 KB
Binary file not shown.

playground/pkg/go/format.a.js

-8.76 KB
Binary file not shown.

playground/pkg/go/importer.a.js

-4.59 KB
Binary file not shown.
-91.9 KB
Binary file not shown.
-39.1 KB
Binary file not shown.
-13.8 KB
Binary file not shown.
-262 Bytes
Binary file not shown.

playground/pkg/go/parser.a.js

-149 KB
Binary file not shown.

playground/pkg/go/printer.a.js

-123 KB
Binary file not shown.

playground/pkg/go/scanner.a.js

-36.3 KB
Binary file not shown.

playground/pkg/go/token.a.js

-17.8 KB
Binary file not shown.

playground/pkg/go/types.a.js

-499 KB
Binary file not shown.

playground/pkg/hash.a.js

-394 Bytes
Binary file not shown.

playground/pkg/hash/adler32.a.js

-1.58 KB
Binary file not shown.

playground/pkg/hash/crc32.a.js

-9.79 KB
Binary file not shown.

playground/pkg/hash/crc64.a.js

-9.87 KB
Binary file not shown.

playground/pkg/hash/fnv.a.js

-6.14 KB
Binary file not shown.

playground/pkg/hash/maphash.a.js

133 Bytes
Binary file not shown.

playground/pkg/html.a.js

-17.1 KB
Binary file not shown.

playground/pkg/html/template.a.js

-115 KB
Binary file not shown.

playground/pkg/image.a.js

-39.8 KB
Binary file not shown.

playground/pkg/image/color.a.js

-16.2 KB
Binary file not shown.
-10.4 KB
Binary file not shown.

playground/pkg/image/draw.a.js

-11.1 KB
Binary file not shown.

playground/pkg/image/gif.a.js

-40.6 KB
Binary file not shown.
-4.46 KB
Binary file not shown.

playground/pkg/image/jpeg.a.js

-74.3 KB
Binary file not shown.

playground/pkg/image/png.a.js

-69.8 KB
Binary file not shown.

playground/pkg/index/suffixarray.a.js

-45.3 KB
Binary file not shown.

playground/pkg/internal/abi.a.js

955 Bytes
Binary file not shown.

playground/pkg/internal/buildcfg.a.js

-13.3 KB
Binary file not shown.

playground/pkg/internal/bytealg.a.js

-4.83 KB
Binary file not shown.

playground/pkg/internal/cpu.a.js

-3.66 KB
Binary file not shown.

playground/pkg/internal/execabs.a.js

-4.49 KB
Binary file not shown.

playground/pkg/internal/fmtsort.a.js

-8.78 KB
Binary file not shown.

playground/pkg/internal/goarch.a.js

2.64 KB
Binary file not shown.

playground/pkg/internal/godebug.a.js

2.12 KB
Binary file not shown.
-182 Bytes
Binary file not shown.

playground/pkg/internal/goroot.a.js

-6.8 KB
Binary file not shown.
23 Bytes
Binary file not shown.

playground/pkg/internal/intern.a.js

7.49 KB
Binary file not shown.

playground/pkg/internal/itoa.a.js

-349 Bytes
Binary file not shown.
-5.22 KB
Binary file not shown.

playground/pkg/internal/nettrace.a.js

-534 Bytes
Binary file not shown.

playground/pkg/internal/oserror.a.js

-81 Bytes
Binary file not shown.

playground/pkg/internal/poll.a.js

-97.1 KB
Binary file not shown.

playground/pkg/internal/race.a.js

-383 Bytes
Binary file not shown.
-72.7 KB
Binary file not shown.
-4.75 KB
Binary file not shown.
-856 Bytes
Binary file not shown.
-9.47 KB
Binary file not shown.

playground/pkg/internal/sysinfo.a.js

-608 Bytes
Binary file not shown.

playground/pkg/internal/testlog.a.js

-2.54 KB
Binary file not shown.
-198 Bytes
Binary file not shown.

playground/pkg/internal/xcoff.a.js

-43.5 KB
Binary file not shown.

playground/pkg/io.a.js

-30.2 KB
Binary file not shown.

playground/pkg/io/fs.a.js

-24.2 KB
Binary file not shown.

playground/pkg/io/ioutil.a.js

-4.14 KB
Binary file not shown.

playground/pkg/log.a.js

-12.9 KB
Binary file not shown.

playground/pkg/log/syslog.a.js

-13.5 KB
Binary file not shown.

playground/pkg/math.a.js

-29 KB
Binary file not shown.

playground/pkg/math/big.a.js

-204 KB
Binary file not shown.

playground/pkg/math/bits.a.js

-8.09 KB
Binary file not shown.

playground/pkg/math/cmplx.a.js

-6.55 KB
Binary file not shown.

playground/pkg/math/rand.a.js

-25.5 KB
Binary file not shown.

playground/pkg/mime.a.js

-46.3 KB
Binary file not shown.

playground/pkg/mime/multipart.a.js

-29.5 KB
Binary file not shown.
-12.5 KB
Binary file not shown.

playground/pkg/net.a.js

-552 KB
Binary file not shown.

playground/pkg/net/http.a.js

-819 KB
Binary file not shown.

playground/pkg/net/http/cgi.a.js

-23.4 KB
Binary file not shown.
-19 KB
Binary file not shown.

playground/pkg/net/http/fcgi.a.js

-23.9 KB
Binary file not shown.

playground/pkg/net/http/httptest.a.js

-25.5 KB
Binary file not shown.
-7.87 KB
Binary file not shown.

playground/pkg/net/http/httputil.a.js

-55.9 KB
Binary file not shown.

playground/pkg/net/http/internal.a.js

-7.31 KB
Binary file not shown.
-1.12 KB
Binary file not shown.
1.15 KB
Binary file not shown.

playground/pkg/net/mail.a.js

-34.2 KB
Binary file not shown.

playground/pkg/net/netip.a.js

83.1 KB
Binary file not shown.

playground/pkg/net/rpc.a.js

-49.4 KB
Binary file not shown.

playground/pkg/net/rpc/jsonrpc.a.js

-7.99 KB
Binary file not shown.

playground/pkg/net/smtp.a.js

-25.9 KB
Binary file not shown.

playground/pkg/net/textproto.a.js

-32.6 KB
Binary file not shown.

playground/pkg/net/url.a.js

-25.3 KB
Binary file not shown.

playground/pkg/os.a.js

-129 KB
Binary file not shown.

playground/pkg/os/exec.a.js

-32.5 KB
Binary file not shown.

playground/pkg/os/signal.a.js

-12 KB
Binary file not shown.

playground/pkg/os/user.a.js

-13.2 KB
Binary file not shown.

playground/pkg/path.a.js

-6.16 KB
Binary file not shown.

playground/pkg/path/filepath.a.js

-27.7 KB
Binary file not shown.

playground/pkg/reflect.a.js

-140 KB
Binary file not shown.

playground/pkg/regexp.a.js

-82.9 KB
Binary file not shown.

playground/pkg/regexp/syntax.a.js

-54.5 KB
Binary file not shown.

playground/pkg/runtime.a.js

-3.49 KB
Binary file not shown.

playground/pkg/runtime/debug.a.js

4.83 KB
Binary file not shown.
-1.3 KB
Binary file not shown.

playground/pkg/runtime/metrics.a.js

-1.51 KB
Binary file not shown.

playground/pkg/runtime/race.a.js

22 Bytes
Binary file not shown.

playground/pkg/runtime/trace.a.js

-5.61 KB
Binary file not shown.

playground/pkg/sort.a.js

-39.2 KB
Binary file not shown.

playground/pkg/strconv.a.js

-56.5 KB
Binary file not shown.

playground/pkg/strings.a.js

-39 KB
Binary file not shown.

playground/pkg/sync.a.js

-29.4 KB
Binary file not shown.

playground/pkg/sync/atomic.a.js

-2.96 KB
Binary file not shown.

playground/pkg/syscall.a.js

-589 KB
Binary file not shown.

playground/pkg/syscall/js.a.js

-11.5 KB
Binary file not shown.

playground/pkg/testing.a.js

-46.4 KB
Binary file not shown.

playground/pkg/testing/fstest.a.js

-47.3 KB
Binary file not shown.

playground/pkg/testing/iotest.a.js

-24.1 KB
Binary file not shown.

playground/pkg/testing/quick.a.js

-24.4 KB
Binary file not shown.

playground/pkg/text/scanner.a.js

-25.4 KB
Binary file not shown.

playground/pkg/text/tabwriter.a.js

-12.2 KB
Binary file not shown.

playground/pkg/text/template.a.js

-120 KB
Binary file not shown.
-80.9 KB
Binary file not shown.

playground/pkg/time.a.js

-97.3 KB
Binary file not shown.

playground/pkg/time/tzdata.a.js

-5.91 KB
Binary file not shown.

playground/pkg/unicode.a.js

-71.3 KB
Binary file not shown.

playground/pkg/unicode/utf16.a.js

-1.26 KB
Binary file not shown.

playground/pkg/unicode/utf8.a.js

-6.61 KB
Binary file not shown.

playground/pkg/unsafe.a.js

-223 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

playground/playground.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,19 @@ func main() {
174174
}
175175

176176
data := js.Global.Get("Uint8Array").New(req.Response).Interface().([]byte)
177-
packages[path], err = compiler.ReadArchive(path+".a", path, bytes.NewReader(data), importContext.Packages)
177+
packages[path], err = compiler.ReadArchive(path+".a", bytes.NewReader(data))
178178
if err != nil {
179179
scope.Apply(func() {
180180
scope.Set("output", []Line{Line{"type": "err", "content": err.Error()}})
181181
})
182182
return
183183
}
184+
if err := packages[path].RegisterTypes(importContext.Packages); err != nil {
185+
scope.Apply(func() {
186+
scope.Set("output", []Line{Line{"type": "err", "content": err.Error()}})
187+
})
188+
return
189+
}
184190
pkgsReceived++
185191
if pkgsReceived == len(pkgsToLoad) {
186192
run(loadOnly)

playground/playground.js

Lines changed: 93 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playground/update.sh

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)