From 1ea8f333f75484f5f176805dc2a80b69bd510dab Mon Sep 17 00:00:00 2001 From: Project516 <138796702+Project516@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:29:52 -0500 Subject: [PATCH 1/5] Ship a Node entry in the package: dist/node.js exports runNode and is the java-web command, reading the packaged JDK image --- .github/workflows/release.yml | 2 + .github/workflows/test.yml | 2 + AGENTS.md | 8 ++-- README.md | 13 ++++++ docs/browser.md | 2 +- docs/node.md | 53 +++++++++++++++++++++++ package.json | 5 +++ scripts/build-web.ts | 13 +++++- src/browser/http.ts | 21 +++++---- src/image.ts | 58 +++++++++++++++++++++++++ src/node.ts | 12 ++++-- test/image.test.ts | 81 +++++++++++++++++++++++++++++++++++ 12 files changed, 253 insertions(+), 17 deletions(-) create mode 100644 docs/node.md create mode 100644 src/image.ts create mode 100644 test/image.test.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05889ca..dee22c4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,4 +37,6 @@ jobs: git -C build/ref/jdk25u sparse-checkout set test/lib test/jdk/lib test/jdk/tools/lib $dirs node scripts/jtreg/run.ts build/ref/jdk25u --only-passing --jobs 4 - run: pnpm build + - name: Node entry on the built dist/ + run: node --expose-gc --test test/image.test.ts - run: npm publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 937e176..a48c45c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,3 +34,5 @@ jobs: - run: pnpm typecheck - run: pnpm test - run: pnpm build + - name: Node entry on the built dist/ + run: node --expose-gc --test test/image.test.ts diff --git a/AGENTS.md b/AGENTS.md index 3cbc11a..5358489 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,8 +30,9 @@ Node, which is how the tests run. (`natives`, `javaProperties`), `cheerpjRunMain`, `cheerpjRunLibrary` (static String calls), `cheerpOSAddStringFile`, `cjFileBlob`, `/files/` in IndexedDB and one VM per about:blank iframe. Keep these working. -- The release form is an npm package of the built browser files only - (`java-web.js`, `java-web-worker.js`, `boot.pack`, `jdk/.jar`, +- The release form is an npm package of the built files only + (`java-web.js`, `java-web-worker.js`, `node.js` (the Node entry and the + `java-web` command), `boot.pack`, `jdk/.jar`, `jdk/javac.pack`, `jdk/jdk.localedata.txt`, and OpenJDK's notices in `jdk/legal/`), versioned, with nothing built at install. A GitHub Actions workflow triggered by a release publishes it to npm; never publish by hand. @@ -50,7 +51,8 @@ Node, which is how the tests run. `font*.ts` are the font natives (scaler, fontconfig, layout) over one TrueType font - `src/sockets.ts` sockets (`Sock`, POSIX readiness) and the in-VM loopback backend; `src/net-node.ts` host sockets, DNS and interfaces for Node -- `src/node.ts` Node entry; `scripts/build-jdk.sh` builds `build/jdk` +- `src/node.ts` Node entry, over `build/jdk` or, built as `dist/node.js`, the + packaged image (`src/image.ts`); `scripts/build-jdk.sh` builds `build/jdk` - `src/http-proxy.ts` the browser's virtual HTTP proxy (`fetch`); `scripts/tls/` the `javaweb.tls` pass-through TLS provider it relies on for `https:` diff --git a/README.md b/README.md index 44e41d7..35699b7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,19 @@ Serve `node_modules/java-web/dist/` as static files, then: `cheerpjRunMain`, `cheerpjRunLibrary` (call Java from JS), JS natives and `/files/` storage work too. See [docs/browser.md](docs/browser.md). +## Use it under Node + +```sh +npx java-web -cp classes Main # or: npx java-web -jar app.jar +``` + +```js +import { runNode } from "java-web"; +const code = await runNode({ classpath: ["classes"], mainClass: "Main" }); +``` + +See [docs/node.md](docs/node.md). + ## What runs - Console apps, libraries and javac: every Java SE module, plus `jdk.compiler`, diff --git a/docs/browser.md b/docs/browser.md index 22ead88..61eb173 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -1,7 +1,7 @@ # Using java-web in a page The npm package holds the built files: `java-web.js`, `java-web-worker.js`, -`boot.pack` and `jdk/`. Serve `node_modules/java-web/dist/` as static files +`boot.pack` and `jdk/` for pages, and `node.js` for Node ([node.md](node.md)). Serve `node_modules/java-web/dist/` as static files and load `java-web.js` with a classic `