ADR 0017 — Examples Run from Source, Each with a Demo
Status: Accepted
Context
Section titled “Context”The siblings’ examples (xtandard-flags, xtandard-webhooks) depend on the package via
file:../.., and their runner (scripts/example.ts) requires bun run build and runs
bun install in each example on first use. bun install copies the package, dist/ included,
so an example keeps running the build it was installed with until it is reinstalled, and each
install duplicates the framework packages the repo already has. Their examples are also
interactive servers: nothing checks in CI that they still work against the current code.
Decision
Section titled “Decision”- Same layout and runner as the siblings:
examples/<name>/with its ownpackage.json("@xtandard/entitlements": "file:../..") and README,scripts/example.ts,bun run examples:<name>, a free port viaget-port-please,typecheck:examples. - In the repo, examples run from source.
examples/tsconfig.jsonmaps every@xtandard/entitlements/*specifier tosrc/— Bun honors tsconfigpathsat runtime, so the same file that makes them typecheck makes them run — and framework packages resolve from the rootnode_modules. No build, no per-example install. The admin UI is still the builtdist/uibundle (the APIs work without it).test/examples.test.tskeeps the map complete for everyexportskey. - Exceptions:
nextinstalls Next.js into the example on its first interactive run (the root has nonext) and points Turbopack and its own tsconfig at the source;elysia2runs withbun --tsconfig-override=tsconfig.jsonsoelysiaresolves to the rootelysia-v2alias for both the example and the adapter source.react-appis a Vite app, and Vite does not read tsconfigpaths: itsvite.config.tsaliases the@xtandard/entitlements/react*imports tosrc/and builds the embed’s Tailwind stylesheet from source, scoped as the package build scopesdist/react.css(only when it finds the repo’ssrc/, so a copied-out app uses the installed package unchanged). - Every example has
src/demo.ts: a non-interactive, end-to-end script that exits 0 — in-process throughapp.fetch/app.handlewhere the framework allows, over a port-0 server otherwise.bun run examples:<name> --demoruns one;bun run examples:demosruns them all. Services that may be absent (Postgres, Redis) make a demo skip with a clear message, never fail. - One catalog (
examples/shared/catalog.ts) and one set of seeded customers are shared by every example; the server examples share one scenario (examples/shared/scenario.ts) so the adapters are shown to behave identically.
Consequences
Section titled “Consequences”- Examples always exercise the code in the working tree; a breaking change shows up in
typecheck:examplesand in the demos, not after the next release. - Copying an example out takes one more step than in the siblings (copy
shared/, drop the in-repo tsconfigpaths); each README says so.