Skip to content

Commit 3d5261c

Browse files
fixed the runner
1 parent 070e595 commit 3d5261c

249 files changed

Lines changed: 483 additions & 246 deletions

File tree

Some content is hidden

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

playground/gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:generate go1.19.13 run ./internal/cmd/precompile
2-
//go:generate go1.19.13 install github.com/gopherjs/gopherjs
1+
//go:generate go1.20.14 run ./internal/cmd/precompile
2+
//go:generate go1.20.14 install github.com/gopherjs/gopherjs
33
//go:generate env GOOS=js GOARCH=ecmascript gopherjs build -m .
44

55
package main

playground/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/google/go-cmp v0.5.8
7-
github.com/gopherjs/gopherjs v1.19.0-beta2.0.20260112215734-09f0b7ce5c99
7+
github.com/gopherjs/gopherjs v1.19.0-beta2.0.20260119142308-2cf5f59df243
88
golang.org/x/tools v0.16.0
99
honnef.co/go/js/xhr v0.0.0-20150307031022-00e3346113ae
1010
)

playground/go.sum

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

playground/internal/cmd/precompile/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/grantnelson-wf/gopherjs.github.io/playground/internal/cmd/prec
33
go 1.20
44

55
require (
6-
github.com/gopherjs/gopherjs v1.19.0-beta2.0.20260112215734-09f0b7ce5c99
6+
github.com/gopherjs/gopherjs v1.19.0-beta2.0.20260119142308-2cf5f59df243
77
github.com/sirupsen/logrus v1.8.3
88
)
99

playground/internal/cmd/precompile/go.sum

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

playground/internal/page/globals.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/gopherjs/gopherjs.github.io/playground/internal/undoRedo"
1010
)
1111

12+
const verbose = true
13+
1214
// globals are the global objects used by the react components.
1315
//
1416
// Since passing Go structs through React props will cause problems
@@ -25,13 +27,13 @@ var globals = struct {
2527
}{
2628
UndoRedo: OnceValue(undoRedo.NewStack),
2729
SnippetsStore: OnceValue(snippets.NewLocalStore), // TODO(grantnelson-wf): Switch to snippets.NewStore before deploying
28-
Runner: OnceValue(func() common.Runner { return runner.New(runner.NewFetcher()) }),
30+
Runner: OnceValue(func() common.Runner { return runner.New(runner.NewFetcher(verbose)) }),
2931
}
3032

3133
// OnceValue initializes a value on the first call
3234
// then all following calls returns the initial value.
3335
//
34-
// TODO: Replace with sync.OnceValue when we reach Go 1.21
36+
// TODO(grantnelson-wf): Replace with sync.OnceValue when we reach Go 1.21
3537
func OnceValue[T any](init func() T) func() T {
3638
var (
3739
initFn func() T = init

playground/internal/page/outputBox.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (o *outputImpl) Clear() {
2727

2828
func (o *outputImpl) AddError(err error) {
2929
o.setOutput.Invoke(func(items []any) []any {
30+
// TODO(grantnelson-wf): Need to move errlist.ErrorList out of internal so that we can split it out here
3031
if list, ok := err.(scanner.ErrorList); ok {
3132
for _, entry := range list {
3233
items = append(items, map[string]any{typeKey: errType, contextKey: entry.Error()})
@@ -86,7 +87,9 @@ func outputBoxComponent(props react.Props) *react.Element {
8687
return react.Div(react.Props{
8788
`id`: `output-box`,
8889
`ref`: outputBoxRef,
89-
}, children...)
90+
}, react.Div(react.Props{
91+
`id`: `output-box-inner`,
92+
}, children...))
9093
}
9194

9295
// hasNonErrors determines if any output is not an error,

playground/internal/page/playground.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,14 @@ func playgroundComponent(props react.Props) *react.Element {
125125
// TODO(grantnelson-wf): Implement a periodic read of the code after a change to preload packages.
126126

127127
onRun := react.UseCallback(func() {
128+
if asyncOpInProgress.Current() {
129+
return
130+
}
128131
asyncOpInProgress.SetCurrent(true)
132+
output := Output(setOutput)
133+
output.Clear()
134+
output.AddOutput(`Compiling...`)
135+
129136
// TODO(grantnelson-wf): Finish implementing and debugging.
130137
globals.Runner().Compile(code, func(jsCode string, err error) {
131138
defer asyncOpInProgress.SetCurrent(false)

playground/internal/runner/fetcher.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,40 @@ import (
1313
"github.com/gopherjs/gopherjs.github.io/playground/internal/common"
1414
)
1515

16-
type fetcher struct{}
16+
type fetcher struct {
17+
verbose bool
18+
}
1719

18-
func NewFetcher() common.Fetcher {
19-
return &fetcher{}
20+
func NewFetcher(verbose bool) common.Fetcher {
21+
return &fetcher{verbose: verbose}
2022
}
2123

22-
func (f *fetcher) FetchPackage(importPath string) (srcs *sources.Sources, err error) {
24+
// See comments in [common.Fetcher]
25+
func (f *fetcher) FetchPackage(importPath string) (*sources.Sources, error) {
26+
if f.verbose {
27+
println("Fetching package:", importPath)
28+
}
29+
2330
data, err := f.fetchFile(importPath)
2431
if err != nil {
2532
return nil, err
2633
}
2734

28-
zr, err := gzip.NewReader(bytes.NewReader(data))
35+
srcs, err := f.readPackage(importPath, data)
2936
if err != nil {
30-
return nil, fmt.Errorf(`failed to create gzip reader for package %q: %v`, importPath, err)
37+
return nil, err
3138
}
32-
defer func() {
33-
if closeErr := zr.Close(); err == nil && closeErr != nil {
34-
err = fmt.Errorf(`failed to close gzip reader for package %q: %w`, importPath, closeErr)
35-
}
36-
}()
3739

38-
srcs = &sources.Sources{}
39-
if err := srcs.Read(gob.NewDecoder(zr).Decode); err != nil {
40-
return nil, fmt.Errorf(`failed to decode package %q: %v`, importPath, err)
40+
if f.verbose {
41+
println("Package ready: ", importPath)
4142
}
42-
4343
return srcs, nil
4444
}
4545

4646
func (f *fetcher) fetchFile(importPath string) ([]byte, error) {
4747
const (
4848
pkgBaseURL = `pkg/`
49-
pkgExt = `.a.js`
49+
pkgExt = `.a.js` // TODO(grantnelson-wf): Should probably pick a better extension for precompiled packages since they aren't JS anymore, maybe .zip
5050
)
5151

5252
req := xhr.NewRequest(`GET`, pkgBaseURL+importPath+pkgExt)
@@ -60,3 +60,22 @@ func (f *fetcher) fetchFile(importPath string) ([]byte, error) {
6060
data := js.Global.Get(`Uint8Array`).New(req.Response).Interface().([]byte)
6161
return data, nil
6262
}
63+
64+
func (f *fetcher) readPackage(importPath string, data []byte) (srcs *sources.Sources, err error) {
65+
zr, err := gzip.NewReader(bytes.NewReader(data))
66+
if err != nil {
67+
return nil, fmt.Errorf(`failed to create gzip reader for package %q: %v`, importPath, err)
68+
}
69+
defer func() {
70+
if closeErr := zr.Close(); err == nil && closeErr != nil {
71+
err = fmt.Errorf(`failed to close gzip reader for package %q: %w`, importPath, closeErr)
72+
}
73+
}()
74+
75+
srcs = &sources.Sources{}
76+
if err := srcs.Read(gob.NewDecoder(zr).Decode); err != nil {
77+
return nil, fmt.Errorf(`failed to decode package %q: %v`, importPath, err)
78+
}
79+
80+
return srcs, nil
81+
}

playground/internal/runner/packageCache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (pc *packageCache) syncLoad(importPath string) syncLoadFunc {
7070
// The given cached sources must be the sources that are already loaded in the cache.
7171
func (pc *packageCache) alreadyLoaded(cached *sources.Sources) syncLoadFunc {
7272
return func(srcs *sources.Sources) (loadResult, error) {
73-
*srcs = *cached // Copy the cached sources.
73+
*srcs = *cached // Shallow copy the cached sources.
7474
return loadCached, nil
7575
}
7676
}
@@ -86,7 +86,7 @@ func (pc *packageCache) alreadyInprogress(importPath string, ch chan struct{}) s
8686
defer pc.lock.Unlock()
8787

8888
if cached, found := pc.cached[importPath]; found {
89-
*srcs = *cached // Copy the cached sources.
89+
*srcs = *cached // Shallow copy the cached sources.
9090
return loadCached, nil
9191
}
9292
return loadFailed, fmt.Errorf(`failed to find package %q in cache after waiting load`, importPath)
@@ -107,7 +107,7 @@ func (pc *packageCache) startLoading(importPath string, ch chan struct{}) syncLo
107107
defer pc.lock.Unlock()
108108

109109
pc.cached[importPath] = fetched
110-
*srcs = *fetched // Copy the fetched sources.
110+
*srcs = *fetched // Shallow copy the fetched sources.
111111
delete(pc.inprogress, importPath)
112112
close(ch)
113113
return loadFetched, nil

0 commit comments

Comments
 (0)