feat(module): the bundle skeleton (phase 3, slice 0)
The first real module. It registers nothing, deliberately: what slice 0 proves
is the delivery path itself, end to end, before a single UO file moves into it.
Server half: module.json, an entry point that takes (ctx, api) and registers
nothing, a test suite built on a fake ctx, and scripts/checkImports.js -- the
MODULE_API.md §5.1 boundary check. Client half: the Vite library build, four
shims re-exporting react / react-dom/client / react-router-dom / jsx-runtime
from window.__rg, an entry that verifies each is identity-equal to core's copy,
and scripts/checkExternals.js. 29 server tests, 9 client tests, both new.
Verified against a real core: the module loads, mounts its zero routes, runs to
`started`, and is published by /api/v1/public/modules. Its chunk serves from
the entry's directory with `Cache-Control: no-cache` while the module's server
source, module.json and package.json all 404. In Chrome, under the enforced
`script-src 'self'`, the chunk evaluates and reports all four shared
dependencies OK, with zero CSP reports and no console errors.
Three findings, each of which had produced a green build that was wrong.
MODULE_API.md §3.6 shows `external` alongside the aliases and they do not
compose. Rollup asks `external` BEFORE Vite's alias resolver runs, so a
specifier in both is marked external and never aliased -- the chunk then ships
bare `import "react"`, which no browser can resolve without an import map, and
CSP forbids one. Built cleanly and emitted exactly that; checkExternals caught
it. So: alias only, `external` empty, and vite.config.js grows a resolution-time
guard that fails the build if a shared dependency resolves into node_modules.
That guard was wrong twice before it worked. Written against Rollup's `load`
hook it never ran -- `load` is first-wins and an earlier plugin had already
claimed the module -- so a deliberately-broken alias produced a 24 kB chunk with
react-router welded in, and a green build. And its forbidden-package list was
derived from the alias list "so the two cannot disagree", which meant deleting
an alias also deleted the guard against what that alias prevented. It states the
contract now, and a test asserts the aliases stay inside it.
checkImports failed on its own documentation the first time it ran: the comment
naming require("../../etc/passwd") as an example of what to catch, and index.js
explaining why the module must never require("express"). A boundary check that
cannot survive being described is one people stop writing comments around. It
strips comments and template literals with a character walk rather than a
regexp, because a URL in a string contains a comment opener and a comment
contains quotes -- and it has its own test suite, since a check never shown to
fail is a check nobody knows the state of.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
69
README.md
69
README.md
@@ -24,36 +24,69 @@ The module's **id** is `uo` — that is what appears in `module.json`, in the `i
|
||||
table, in the `modules/<id>/` path on disk and in the URL segment (`/uo/*`, `/admin/uo/*`,
|
||||
`/player/uo/*`). `Module-uo` is the repository; `module-uo` is the module and its release artifact.
|
||||
|
||||
## Status: planning — no module code exists yet
|
||||
## Status: the bundle skeleton exists; the extraction has started
|
||||
|
||||
This repo currently holds governance scaffolding only. The design of record is
|
||||
The design of record is
|
||||
[`website/MODULE_SYSTEM.md`](https://gitea.whitlocktech.com/RunicGateway/docs/src/branch/main/website/MODULE_SYSTEM.md)
|
||||
in the docs repo — **read it before opening a PR here.** It defines the module API surface, the
|
||||
packaging, the state machine, the install/uninstall/purge model, and the phases.
|
||||
and the normative contract is
|
||||
[`website/MODULE_API.md`](https://gitea.whitlocktech.com/RunicGateway/docs/src/branch/main/website/MODULE_API.md)
|
||||
in the docs repo — **read them before opening a PR here.** Where the two differ, the contract wins.
|
||||
|
||||
| Phase | Where it happens | State |
|
||||
|---|---|---|
|
||||
| 0 — CI trigger fix, cut `website` `edge`, bootstrap this repo | `website`, here | 🟡 in progress |
|
||||
| 1 — module API contract (`docs/website/MODULE_API.md`) + the atlas spike | `docs`, `website` | ⬜ blocking |
|
||||
| 2 — core scaffolding: loader, `installed_modules`, registries, client registry | `website` | ⬜ |
|
||||
| 3 — extract the UO half of the site into this repo | `website`, here | ⬜ |
|
||||
| 0 — CI trigger fix, cut `website` `edge`, bootstrap this repo | `website`, here | ✅ done |
|
||||
| 1 — module API contract (`docs/website/MODULE_API.md`) + the atlas spike | `docs`, `website` | ✅ done |
|
||||
| 2 — core scaffolding: loader, `installed_modules`, registries, client registry | `website` | ✅ done |
|
||||
| 3 — extract the UO half of the site into this repo | `website`, here | 🟡 in progress |
|
||||
| 4 — delivery: the admin Modules screen + the Docker path | `website` | ⬜ |
|
||||
|
||||
Nothing lands here until Phase 1 has settled the contract this module is written against. Phase 3 is
|
||||
what fills the repo.
|
||||
Phase 3 moves the UO half of `website/` here in ten slices (`MODULE_SYSTEM.md` §2.7.1), server-first
|
||||
and then client. Each slice is one PR here that adds, and one PR in `website` that deletes — this one
|
||||
merging first, so `website`'s `edge` branch serves the feature from core right up to the moment core
|
||||
drops it.
|
||||
|
||||
## What it will contain
|
||||
**Slice 0 is the bundle skeleton, and it registers nothing on purpose.** What it proves is the
|
||||
delivery path itself: core discovers the module, validates `module.json`, calls `register()`, serves
|
||||
the client chunk, injects it, and reports the module `started` — and the chunk resolves React, the
|
||||
renderer and the router from core's `window.__rg` rather than bundling its own. Every slice after
|
||||
this one adds registrations to `server/index.js` and `client/src/entry.jsx`.
|
||||
|
||||
## Working on it
|
||||
|
||||
```bash
|
||||
npm ci --prefix server && npm test --prefix server && npm run check:imports --prefix server
|
||||
npm ci --prefix client && npm test --prefix client && npm run build --prefix client
|
||||
npm run check:externals --prefix client # asks the BUILT chunk, so it runs after the build
|
||||
```
|
||||
|
||||
The two `check:*` scripts are the contract's acceptance criteria rather than this module's own tests:
|
||||
no import may escape the module root (`MODULE_API.md` §5.1), and no bare specifier may survive into
|
||||
the built chunk (§3.6). The matching failure — a shared dependency being *bundled* — fails the build
|
||||
itself, from a guard inside `vite.config.js`.
|
||||
|
||||
Running it against a real core means checking this repo out as `website/modules/uo`, building the
|
||||
client half, and booting core. The four-step browser smoke in `MODULE_API.md` §7.7 is the only thing
|
||||
that proves the client half works: its real failure modes are timing and module resolution, and
|
||||
neither has a shape a DOM-less test runner can see.
|
||||
|
||||
## What it contains
|
||||
|
||||
One repo, one bundle: the server half and the client half live side by side and version together, so
|
||||
a route and the screen that calls it can never be mismatched.
|
||||
a route and the screen that calls it can never be mismatched. A ✅ is in the tree today.
|
||||
|
||||
```
|
||||
module.json id, version, coreApi range, mounts, extensions
|
||||
server/ routers, controllers, models, utils
|
||||
server/db/schema.sql idempotent fragment, replayed by core's ensureSchema()
|
||||
server/db/purge.sql destructive; only ever run by an explicit purge
|
||||
client/src/ route components, nav registrations, feature provider
|
||||
client/dist/ PREBUILT ESM chunk, built by CI — never by an operator
|
||||
module.json ✅ id, version, coreApi range, mounts, extensions
|
||||
server/index.js ✅ the entry point — register(ctx, api), synchronous, no database
|
||||
server/scripts/ ✅ checkImports.js — the §5.1 boundary check
|
||||
server/test/ ✅ node --test, with a fake ctx standing in for core
|
||||
server/ routers, controllers, models, utils
|
||||
server/db/schema.sql idempotent fragment, replayed by core's ensureSchema()
|
||||
server/db/purge.sql destructive; only ever run by an explicit purge
|
||||
client/src/entry.jsx ✅ the chunk's entry — registers routes, nav, feature provider
|
||||
client/src/shim/ ✅ react, react-dom, react-router-dom, jsx-runtime, from window.__rg
|
||||
client/vite.config.js ✅ the library build, the aliases, the not-bundled guard
|
||||
client/src/ route components, nav registrations, feature provider
|
||||
client/dist/ ✅ PREBUILT ESM chunk, built by CI — never by an operator
|
||||
```
|
||||
|
||||
Release artifact: `module-uo-<version>.tar.gz`, plus a manifest carrying its `sha256`.
|
||||
|
||||
Reference in New Issue
Block a user