Skip to content

Commit

Permalink
Migrate to NPM and cleanup Playground (#1951)
Browse files Browse the repository at this point in the history
This Pull Request closes #1912 by migrating to a NPM based build, hopefully making it easier to contribute to the Playground.

Also, reduces the number of features of the editor, since most of them were support for other languages or features that don't make sense in a playground environment. This considerably reduces the number of fetched files per page load and the total size of the playground.
  • Loading branch information
jedel1043 committed Mar 20, 2022
1 parent 3b4708c commit f25ce46
Show file tree
Hide file tree
Showing 11 changed files with 8,557 additions and 2,913 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ jobs:
- uses: actions/checkout@v3
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: Borales/actions-yarn@v2.3.0
- uses: actions/setup-node@v3
with:
cmd: install
- name: Cache yarn build
node-version: "16"
- run: npm ci
- name: Cache npm build
uses: actions/cache@v2.1.7
with:
path: |
Expand All @@ -35,10 +36,8 @@ jobs:
boa_wasm/pkg
~/.cargo/git
~/.cargo/registry
key: ${{ runner.os }}-yarn-build-target-${{ hashFiles('**/yarn.lock') }}
- uses: Borales/actions-yarn@v2.3.0
with:
cmd: build:prod
key: ${{ runner.os }}-npm-build-target-${{ hashFiles('**/package-lock.json') }}
- run: npm run build:prod
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/webassembly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
profile: minimal
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Cache yarn build
- name: Cache npm build
uses: actions/cache@v2.1.7
with:
path: |
Expand All @@ -41,10 +41,9 @@ jobs:
~/.cargo/git
~/.cargo/registry
boa_wasm/pkg
key: ${{ runner.os }}-yarn-build-target-${{ hashFiles('**/yarn.lock') }}
- uses: Borales/actions-yarn@v2.3.0
key: ${{ runner.os }}-npm-build-target-${{ hashFiles('**/package-lock.json') }}
- uses: actions/setup-node@v3
with:
cmd: install
- uses: Borales/actions-yarn@v2.3.0
with:
cmd: build
node-version: "16"
- run: npm ci
- run: npm run build
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cargo run --release --bin boa_tester -- run -vv -d -s test/language/types/number
## Communication

We have a Discord server, feel free to ask questions here:
https://discord.gg/tUFFk9Y
<https://discord.gg/tUFFk9Y>

[issues]: https://github.com/boa-dev/boa/issues
[rustup]: https://rustup.rs/
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Currently, it has support for some of the language.

[![Build Status][build_badge]][build_link]
[![codecov](https://codecov.io/gh/boa-dev/boa/branch/main/graph/badge.svg)](https://codecov.io/gh/boa-dev/boa)
[![](https://img.shields.io/crates/v/Boa.svg)](https://crates.io/crates/Boa)
[![](https://docs.rs/Boa/badge.svg)](https://docs.rs/Boa/)
[![Crates.io](https://img.shields.io/crates/v/Boa.svg)](https://crates.io/crates/Boa)
[![Docs.rs](https://docs.rs/Boa/badge.svg)](https://docs.rs/Boa/)
[![Discord](https://img.shields.io/discord/595323158140158003?logo=discord)](https://discord.gg/tUFFk9Y)

[build_badge]: https://github.com/boa-dev/boa/actions/workflows/rust.yml/badge.svg?event=push&branch=main
Expand Down Expand Up @@ -50,12 +50,17 @@ This interpreter can be exposed to JavaScript!
You can build the example locally with:

```shell
$ yarn install
$ yarn serve
npm run build
```

In the console you can use `window.evaluate` to pass JavaScript in.
To develop on the web assembly side you can run `yarn serve` then go to `http://localhost:8080`.
To develop on the web assembly side you can run:

```shell
npm run serve
```

then go to `http://localhost:8080`.

## Usage

Expand Down
1 change: 1 addition & 0 deletions boa_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "Unlicense/MIT"

[dependencies]
boa_engine = { path = "../boa_engine", features = ["console"], version = "0.14.0" }
# BUG: Pump when 0.2.80 releases. See https://github.com/rustwasm/wasm-bindgen/issues/2774
wasm-bindgen = "=0.2.78"
getrandom = { version = "0.2.5", features = ["js"] }

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
display: flex;
align-items: center;
}

.demo__img {
width: 170px;
display: block;
Expand Down
32 changes: 5 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
// Note that a dynamic `import` statement here is required due to
// webpack/webpack#6615, but in theory `import { greet } from './pkg/hello_world';`
// will work here one day as well!
const rust = import("./boa_wasm/pkg");
import * as monaco from "monaco-editor";
import { evaluate } from "./boa_wasm/pkg";

window.MonacoEnvironment = {
getWorkerUrl: function (moduleId, label) {
if (label === "json") {
return "./json.worker.js";
}
if (label === "css") {
return "./css.worker.js";
}
if (label === "html") {
return "./html.worker.js";
}
if (label === "typescript" || label === "javascript") {
return "./ts.worker.js";
}
return "./editor.worker.js";
},
};
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

const initialCode = `\
function greet(targetName) {
Expand All @@ -47,12 +27,10 @@ window.addEventListener("resize", () => {
editor.layout();
});

rust.then((m) => {
window.evaluate = m.evaluate;
window.evaluate = evaluate;

editor.getModel().onDidChangeContent(inputHandler);
inputHandler(); // Evaluate initial code
});
editor.getModel().onDidChangeContent(inputHandler);
inputHandler(); // Evaluate initial code

function inputHandler(evt) {
const text = editor.getValue();
Expand Down
Loading

0 comments on commit f25ce46

Please sign in to comment.