build: Resolve waforth import from examples

This commit is contained in:
Remko Tronçon 2022-05-08 15:06:08 +02:00
parent 75c6490dc5
commit 01fcb9e2a8
13 changed files with 27 additions and 12 deletions

View file

@ -1,3 +1,4 @@
public/waforth/dist
build/
dist/
src/web/benchmarks/sieve/sieve-c.js

View file

@ -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";

View file

@ -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",

View file

@ -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 = `<!doctype html>

View file

@ -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

View file

@ -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"

View file

@ -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";

View file

@ -4,7 +4,7 @@
*/
import "./prompt.css";
import WAForth from "../../WAForth";
import WAForth from "waforth";
(async () => {
// Create the UI

View file

@ -1,6 +1,6 @@
/* global WAFORTH_VERSION */
import WAForth from "../WAForth";
import WAForth from "../waforth";
import sieve from "../../examples/sieve.f";
import "./shell.css";

View file

@ -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";

View file

@ -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"]
}

View file

@ -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"]
}