-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1fc23db
Showing
23 changed files
with
729 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"semi": "error", | ||
"eqeqeq": "error", | ||
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }], | ||
"no-constant-condition": ["error", { "checkLoops": false }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
patreon: whitequark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
on: [push, pull_request] | ||
name: Test & publish | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out source code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Run tests | ||
run: | | ||
./test/run.sh | ||
- name: Run lints | ||
run: | | ||
npm run lint | ||
check: # group all `test (*)` workflows into one for the required status check | ||
needs: test | ||
if: always() && !contains(needs.*.result, 'cancelled') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: ${{ contains(needs.*.result, 'failure') && 'false' || 'true' }} | ||
# publish: | ||
# needs: check | ||
# runs-on: ubuntu-latest | ||
# environment: publish | ||
# permissions: | ||
# id-token: write | ||
# steps: | ||
# - name: Check out source code | ||
# uses: actions/checkout@v3 | ||
# with: | ||
# fetch-depth: 0 | ||
# - name: Set up Python | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: '3.x' | ||
# - name: Install dependencies | ||
# run: | | ||
# pip install build | ||
# - name: Build wheel | ||
# run: | | ||
# python -m build -w | ||
# - name: Publish wheel to Test PyPI | ||
# if: github.event_name == 'push' && github.event.ref == 'refs/heads/develop' | ||
# uses: pypa/gh-action-pypi-publish@release/v1 | ||
# with: | ||
# repository-url: https://test.pypi.org/legacy/ | ||
# - name: Publish wheel to PyPI | ||
# if: github.event_name == 'push' && github.event.ref == 'refs/heads/release' | ||
# uses: pypa/gh-action-pypi-publish@release/v1 | ||
# release: | ||
# needs: check | ||
# runs-on: ubuntu-latest | ||
# if: "contains(github.event.head_commit.message, 'autorelease') && github.event_name == 'push' && github.ref == 'refs/heads/develop'" | ||
# steps: | ||
# - name: Check out source code | ||
# uses: actions/checkout@v3 | ||
# with: | ||
# token: ${{ secrets.PUSH_TOKEN }} | ||
# fetch-depth: 0 # fetch the release branch as well | ||
# - name: Update release branch | ||
# run: | | ||
# git push origin develop:release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/package-lock.json | ||
/node_modules | ||
/dist | ||
/gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ISC License | ||
|
||
Copyright (C) Catherine <whitequark@whitequark.org> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
YoWASP JavaScript runtime | ||
========================= | ||
|
||
This package is an internal support package for the [YoWASP project][yowasp]. It handles interfacing with the [WebAssembly][] runtime and the supported execution environments (Node.js and the browser). Do not depend on this package in your own code. | ||
|
||
[webassembly]: https://webassembly.org/ | ||
[yowasp]: https://yowasp.github.io/ | ||
|
||
|
||
License | ||
------- | ||
|
||
This package is covered by the [ISC license](LICENSE.txt). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
|
||
import { readdir, readFile, writeFile } from 'fs/promises'; | ||
|
||
async function packDirectory(root) { | ||
const files = await readdir(root, { withFileTypes: true }); | ||
const packedFiles = {}; | ||
for (const file of files) { | ||
const filePath = `${root}/${file.name}`; | ||
if (file.isDirectory()) | ||
packedFiles[file.name] = await packDirectory(filePath); | ||
if (file.isFile()) | ||
packedFiles[file.name] = await readFile(filePath, {encoding: 'utf-8'}); | ||
} | ||
return packedFiles; | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
if (args.length !== 2) { | ||
console.error(`Usage: yowasp-pack-resources <directory> <file.json>`); | ||
process.exit(1); | ||
} | ||
|
||
await writeFile(args[1], JSON.stringify(await packDirectory(args[0]))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Exit, Environment, directoryFromTree, directoryIntoTree } from './wasi-virt.js'; | ||
|
||
export { Exit } from './wasi-virt.js'; | ||
|
||
export class BaseApplication { | ||
constructor(getResources, wasmModules, instantiate) { | ||
this._resources = null; | ||
this.getResources = getResources; | ||
this.wasmModules = wasmModules; | ||
this.instantiate = instantiate; | ||
} | ||
|
||
async run(args, files, printLine = console.log) { | ||
if (this._resources === null) | ||
this._resources = await this.getResources(); | ||
|
||
const environment = new Environment(); | ||
environment.args = args; | ||
environment.root = directoryFromTree(files); | ||
for (const [dirName, resourceFiles] of Object.entries(this._resources)) | ||
environment.root.files[dirName] = directoryFromTree(resourceFiles); | ||
environment.printLine = printLine; | ||
|
||
const wasmCommand = await this.instantiate( | ||
(filename) => this.wasmModules[filename], | ||
{ runtime: environment.exports }); | ||
try { | ||
wasmCommand.run.run(); | ||
} catch (e) { | ||
if (!(e instanceof Exit && e.code === 0)) | ||
throw e; | ||
} | ||
|
||
for (const dirName of Object.keys(this._resources)) | ||
delete environment.root[dirName]; | ||
return directoryIntoTree(environment.root); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BaseApplication } from './api-base.js'; | ||
|
||
export { Exit } from './api-base.js'; | ||
|
||
export class Application extends BaseApplication { | ||
constructor(baseURL, resourceFilenames, wasmFilenames, instantiate) { | ||
async function getResources() { | ||
const resources = {}; | ||
for (const [dirName, jsonFilename] of Object.entries(resourceFilenames)) | ||
resources[dirName] = JSON.parse(await fetch(new URL(jsonFilename, baseURL))); | ||
return resources; | ||
} | ||
|
||
const wasmModules = {}; | ||
for (const [modName, wasmFilename] of Object.entries(wasmFilenames)) | ||
wasmModules[modName] = fetch(new URL(wasmFilename, baseURL)).then(WebAssembly.compileStreaming); | ||
|
||
super(getResources, wasmModules, instantiate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { readFile } from 'fs/promises'; | ||
import { BaseApplication } from './api-base.js'; | ||
|
||
export { Exit } from './api-base.js'; | ||
|
||
export class Application extends BaseApplication { | ||
constructor(baseURL, resourceFilenames, wasmFilenames, instantiate) { | ||
async function getResources() { | ||
const resources = {}; | ||
for (const [dirName, jsonFilename] of Object.entries(resourceFilenames)) | ||
resources[dirName] = JSON.parse(await readFile(new URL(jsonFilename, baseURL))); | ||
return resources; | ||
} | ||
|
||
const wasmModules = {}; | ||
for (const [modName, wasmFilename] of Object.entries(wasmFilenames)) | ||
wasmModules[modName] = readFile(new URL(wasmFilename, baseURL)).then(WebAssembly.compile); | ||
|
||
super(getResources, wasmModules, instantiate); | ||
} | ||
} |
Oops, something went wrong.