From 01fcb9e2a8d0b29fca2d59bca2f63735df22323a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sun, 8 May 2022 15:06:08 +0200 Subject: [PATCH] build: Resolve waforth import from examples --- .eslintignore | 1 + README.md | 2 +- build-package.js | 2 +- build-web.js | 15 ++++++++++++++- doc/Design.md | 2 +- package.json | 2 +- src/web/benchmarks/benchmarks.js | 2 +- src/web/examples/prompt/prompt.ts | 2 +- src/web/shell/shell.js | 2 +- src/web/tests/suite.js | 2 +- src/web/{WAForth.ts => waforth.ts} | 0 tsconfig.json | 5 +++-- tsconfig.package.json | 2 +- 13 files changed, 27 insertions(+), 12 deletions(-) rename src/web/{WAForth.ts => waforth.ts} (100%) diff --git a/.eslintignore b/.eslintignore index 830e21f..d5497ff 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ public/waforth/dist build/ dist/ +src/web/benchmarks/sieve/sieve-c.js diff --git a/README.md b/README.md index 0b39f52..a234f41 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ document](doc/Design.md). You can embed WAForth in any JavaScript application. -A simple example to illustrate starting WAForth, and binding JavaScript functions: +A [simple example](https://github.com/remko/waforth/blob/master/src/web/examples/prompt/prompt.ts) to illustrate starting WAForth, and binding JavaScript functions: ```typescript import WAForth from "waforth"; diff --git a/build-package.js b/build-package.js index e6af07f..7f239e6 100755 --- a/build-package.js +++ b/build-package.js @@ -9,7 +9,7 @@ const { wasmTextPlugin } = require("./scripts/esbuild/wasm-text"); let buildConfig = { bundle: true, logLevel: "info", - entryPoints: [path.join(__dirname, "src", "web", "WAForth")], + entryPoints: [path.join(__dirname, "src", "web", "waforth")], outfile: path.join(__dirname, "dist", "index.js"), minify: true, format: "cjs", diff --git a/build-web.js b/build-web.js index f8a34da..00ccaec 100755 --- a/build-web.js +++ b/build-web.js @@ -81,7 +81,20 @@ let buildConfig = { }, sourcemap: true, metafile: true, - plugins: [wasmTextPlugin({ debug: true }), forthPlugin()], + plugins: [ + wasmTextPlugin({ debug: true }), + forthPlugin(), + + // Resolve 'waforth' to the main entrypoint (for examples) + { + name: "waforth", + setup: (build) => { + build.onResolve({ filter: /^waforth$/ }, () => { + return { path: path.join(__dirname, "src", "web", "waforth.ts") }; + }); + }, + }, + ], }; const INDEX_TEMPLATE = ` diff --git a/doc/Design.md b/doc/Design.md index a7a9efe..541aa3f 100644 --- a/doc/Design.md +++ b/doc/Design.md @@ -59,7 +59,7 @@ shared function table is large enough for the module to register itself. ## The Shell The shell is [a JavaScript -class](https://github.com/remko/waforth/blob/master/src/shell/WAForth.js) that +class](https://github.com/remko/waforth/blob/master/src/web/waforth.ts) that wraps the WebAssembly module, and loads it in the browser. It provides the I/O primitives to the WebAssembly module to read and write characters to a terminal, and externally provides a `interpret()` function to execute a fragment of diff --git a/package.json b/package.json index 6ca15af..54d049b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "react-dom": "^18.0.0", "typescript": "^4.6.4" }, - "types": "dist/WAForth.d.ts", + "types": "dist/waforth.d.ts", "main": "dist/index.js", "files": [ "dist" diff --git a/src/web/benchmarks/benchmarks.js b/src/web/benchmarks/benchmarks.js index c2aa25d..3b26257 100644 --- a/src/web/benchmarks/benchmarks.js +++ b/src/web/benchmarks/benchmarks.js @@ -1,6 +1,6 @@ import React from "react"; import { createRoot } from "react-dom/client"; -import WAForth from "../WAForth"; +import WAForth from "../waforth"; import sieve from "../../examples/sieve.f"; import sieveWasmModule from "./sieve/sieve.wat"; import sieveJS from "./sieve/sieve.js"; diff --git a/src/web/examples/prompt/prompt.ts b/src/web/examples/prompt/prompt.ts index bddc94c..7f88f4b 100644 --- a/src/web/examples/prompt/prompt.ts +++ b/src/web/examples/prompt/prompt.ts @@ -4,7 +4,7 @@ */ import "./prompt.css"; -import WAForth from "../../WAForth"; +import WAForth from "waforth"; (async () => { // Create the UI diff --git a/src/web/shell/shell.js b/src/web/shell/shell.js index 2251ca1..921d5f3 100644 --- a/src/web/shell/shell.js +++ b/src/web/shell/shell.js @@ -1,6 +1,6 @@ /* global WAFORTH_VERSION */ -import WAForth from "../WAForth"; +import WAForth from "../waforth"; import sieve from "../../examples/sieve.f"; import "./shell.css"; diff --git a/src/web/tests/suite.js b/src/web/tests/suite.js index b905002..952680b 100644 --- a/src/web/tests/suite.js +++ b/src/web/tests/suite.js @@ -1,4 +1,4 @@ -import WAForth from "../WAForth"; +import WAForth from "../waforth"; import sieve from "../../examples/sieve.f"; import standardTestSuiteTester from "../../standard-testsuite/tester.f"; import standardCoreWordsTestSuite from "../../standard-testsuite/core.f"; diff --git a/src/web/WAForth.ts b/src/web/waforth.ts similarity index 100% rename from src/web/WAForth.ts rename to src/web/waforth.ts diff --git a/tsconfig.json b/tsconfig.json index 2d0fb74..db8a9c4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,9 @@ "strict": true, "target": "es2015", "typeRoots": ["./src/web/types"], - "types": ["node"] + "types": ["node"], + "baseUrl": "./src/web" }, - "include": ["src/web"], + "include": ["./src/web"], "exclude": ["node_modules", "dist", "build"] } diff --git a/tsconfig.package.json b/tsconfig.package.json index 706853f..4848efe 100644 --- a/tsconfig.package.json +++ b/tsconfig.package.json @@ -9,6 +9,6 @@ "declaration": true, "emitDeclarationOnly": true }, - "include": ["src/web/WAForth.ts", "src/web/types"], + "include": ["src/web/waforth.ts", "src/web/types"], "exclude": ["node_modules", "dist", "build"] }