Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
playground/go.sum linguist-generated
playground/internal/cmd/precompile/go.sum linguist-generated

**/*.a.js linguist-generated
playground/playground.js linguist-generated

playground/internal/imports/zstdlib.go linguist-generated
63 changes: 63 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

permissions:
contents: read
pull-requests: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

env:
GO_VERSION: 1.20.14
NODE_VERSION: 18
GOLANGCI_VERSION: v1.53.3
SOURCE_MAP_SUPPORT: true
GOPATH: ${{ github.workspace }}/go
GOPHERJS_PATH: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}

jobs:
lint:
name: Lint Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: ${{ env.GOPHERJS_PATH }}
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install golangci-lint
uses: golangci/golangci-lint-action@v3
with:
working-directory: ${{ env.GOPHERJS_PATH }}/playground
version: ${{ env.GOLANGCI_VERSION }}
only-new-issues: true
- name: Check go.mod
working-directory: ${{ env.GOPHERJS_PATH }}/playground
run: go mod tidy && git diff --exit-code

go_tests:
name: Go Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: ${{ env.GOPHERJS_PATH }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup Go Environment
working-directory: ${{ env.GOPHERJS_PATH }}
shell: bash
run: echo "GOROOT=$(go env GOROOT)" >> $GITHUB_ENV
- name: Run Playground Tests
working-directory: ${{ env.GOPHERJS_PATH }}/playground
run: go test -v -race ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/playground/playground.js.map
/playground/compile.js.map
.DS_Store
7 changes: 7 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go 1.20

use (
./playground
./playground/internal/cmd/compile
./playground/internal/cmd/precompile
)
610 changes: 610 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

74 changes: 68 additions & 6 deletions playground/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,85 @@

The playground is a place where users can explore GopherJS without needing to install anything, or to share code with others.

- [Building the playgound](#building-the-playgound)
- [Development](#development)
- [Upgrading GopherJS release](#upgrading-gopherjs-release)
- [Adding a new predefined snippet](#adding-a-new-predefined-snippet)

## Building the playgound

To build the entire playground environment,
run `go generate`.

This assumes that your `go` matches the current version of `go` that `gopherjs` supports.
If you have a different version of `go` then install the other versions as
described in [Managing Go installations](https://go.dev/doc/manage-install).

For example, to build for [GopherJS 1.20.0 for Go 1.20.14](https://github.com/gopherjs/gopherjs/releases/tag/v1.20.0)
run `go1.20.14 generate`.

Generate will:

1. Install your local version of GopherJS compiler
2. Build the playground
3. Build the web worker compiler
4. Create precompiled standard library packages in the `pkg` directory

To manually build the playground:

1. See [GopherJS](https://github.com/gopherjs/gopherjs) documentation about building GopherJS
2. Build the playgound with `gopherjs build ./playground.go`
3. Build the web worker compiler with `gopherjs build ./internal/cmd/compile/compile.go`
4. Create the precompiled standard library packages with `go run ./internal/cmd/precompile`.
Use the same `go` as `gopherjs` as described above

## Development

To update the entire playground environment, just run `go generate github.com/gopherjs/gopherjs.github.io/playground`. It will install your local version of GopherJS compiler, build the playground, make a temporary copy of Go to /tmp/gopherjsplayground_goroot, rebuild and copy the standard library into the `pkg` directory.
Working on the playground application itself is made easier by using the
`gopherjs serve` command serve the playground locally.

Working on the playground application itself is made easier by using the `gopherjs serve` command to rebuild and serve the playground every time you refresh the browser.
Then open <http://localhost:8080?debug=true&local=true>.

```bash
gopherjs serve
```
The `debug` query will enable debugging for react and verbose output.

If running locally or from a fork, trying to access the remote store will
fail with a a CORS error. Use the `local` query to make the snippet store
(used when clicking "Share" or loading with a shared url) use local cache only.

There are a few ways to check changes. When working on the playground itself
it may be simpliest to run `gopherjs build ./playground.go && gopherjs serve`
after you have made changes so that the changes will be built and served.

Then open <http://localhost:8080/github.com/gopherjs/gopherjs.github.io/playground>.
When running code in the playground, the JS that is being run can be seen
by checking the page source files and finding the webworker that is running
the code. The webworker should have a GUID name, e.g. `fb29b3a9-d5b0-478d-aaf7-85cb60ddbd6d`,
and the JS compiled for that code will have the same name (usually without `.js`).

## Upgrading GopherJS release

To upgrade to the newest version, run

```shell
VERSION="$(go list -m -versions -f "{{ range .Versions }}{{ println . }}{{ end }}" github.com/gopherjs/gopherjs | tail -n 1)"
echo "$VERSION"
go get -v "github.com/gopherjs/gopherjs@$VERSION"
go mod tidy
```

then rebuild the playground with the correct version of `go`.

When committing the update, make sure that `compile.js` at minimum has been
updated to use the new version of GopherJS so that we can build in that version.

## Adding a new predefined snippet

The snippets are prewritten example programs such as `Hello` and `Donut`.
To add new snippets:

1. Write the code you would like to add
2. Test it in the playground and check the console to make sure it does
what you expected it to do
3. Create file in the [snippets folder](./internal/snippets) for that code and change
file extension to `.go.txt`
4. In [`snippets.go`](./internal/snippets/snippets.go) add the new file as
an embedded string and add that string to the `predefined` map.
222 changes: 222 additions & 0 deletions playground/compile.js

Large diffs are not rendered by default.

Binary file added playground/favicon-gopherjs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions playground/gen.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//go:generate go run ./internal/cmd/precompile
//go:generate go install github.com/gopherjs/gopherjs
//go:generate gopherjs build -m .
//go:generate $GOROOT/bin/go run ./internal/cmd/precompile
//go:generate $GOROOT/bin/go install github.com/gopherjs/gopherjs
//go:generate env GOOS=js GOARCH=ecmascript gopherjs build -m ./internal/cmd/compile/.
//go:generate env GOOS=js GOARCH=ecmascript gopherjs build -m .

package main
20 changes: 5 additions & 15 deletions playground/go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
module github.com/gopherjs/gopherjs.github.io/playground

go 1.17
go 1.20

require (
github.com/gopherjs/gopherjs v1.18.0-beta1
github.com/neelance/go-angularjs v0.0.0-20170205214111-8c6312cca6e2
github.com/sirupsen/logrus v1.8.3
golang.org/x/tools v0.1.12
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2
github.com/google/go-cmp v0.5.8
github.com/gopherjs/gopherjs v1.20.1
golang.org/x/tools v0.16.0
honnef.co/go/js/xhr v0.0.0-20150307031022-00e3346113ae
)

require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86 // indirect
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/util v0.0.0-20150216223935-96b8dd9d1621 // indirect
)
require honnef.co/go/js/util v0.0.0-20150216223935-96b8dd9d1621 // indirect
Loading