Skip to content

build(core): ship pre-built worker + SW bundles in dist/#19

Merged
joelshejar merged 1 commit into
mainfrom
build/core-ships-worker-bundles
May 10, 2026
Merged

build(core): ship pre-built worker + SW bundles in dist/#19
joelshejar merged 1 commit into
mainfrom
build/core-ships-worker-bundles

Conversation

@joelshejar
Copy link
Copy Markdown
Member

Summary

First execution PR after the grilling pass. Moves the SharedWorker and Service Worker bundling out of the playground and into `@tabmesh/core` itself, so consumers who install from npm get ready-to-deploy bundles without needing to find the source inside `node_modules` and run their own bundler.

What changes

`packages/core`

  • New script `scripts/build-bundles.mjs` runs esbuild over the worker and SW entry points and emits IIFE bundles to `dist/tabmesh-worker.js` and `dist/tabmesh-sw.js`.
  • Build script wires it in: `tsc && vite build && node scripts/build-bundles.mjs`.
  • New subpath exports in `package.json`: `./worker.js` → `./dist/tabmesh-worker.js`, `./sw.js` → `./dist/tabmesh-sw.js`. Bundler-aware consumers can do `import workerUrl from '@tabmesh/core/worker.js?url'`. Manual-copy users do `cp node_modules/@tabmesh/core/dist/tabmesh-worker.js public/`.

`packages/playground`

  • `scripts/build-worker.mjs` and `scripts/build-sw.mjs` reduce to copies from `packages/core/dist/` instead of running their own esbuild. Single source of truth for the bundle bytes.
  • Playground's `public/` no longer has bundle drift relative to what npm would ship.

Documentation

  • ADR-0003 — worker bundle distribution decision (drafted during the grilling pass).
  • ADR-0004 — VitePress single-site decision (also from the grilling pass).

Why this is the right first step

The grilling pass surfaced that publishing to npm without pre-built bundles ships a paperweight — consumers can't trivially get the worker file out of `node_modules`. ADR-0003 settled the choice (pre-built bundles + manual copy + documented in README) and this PR is the implementation. Everything else (npm publish workflow, VitePress site, version bump to `0.1.0-alpha.0`) depends on this being in place.

Test plan

  • `pnpm --filter @tabmesh/core build` produces `dist/tabmesh-worker.js` (18.0kb) and `dist/tabmesh-sw.js` (2.7kb)
  • `pnpm --filter @tabmesh/playground build:worker && build:sw` copies them into the playground's `public/`
  • `pnpm exec vitest --run` — 122/122 pass
  • `pnpm exec playwright test --project=chromium` — 11/11 pass
  • Biome clean

Move the SharedWorker and Service Worker bundling from the playground
into @tabmesh/core itself, so consumers who install from npm get
ready-to-deploy bundles without needing to find the .ts source inside
node_modules and run their own bundler.

Per ADR-0003 and ADR-0004:

- Add `packages/core/scripts/build-bundles.mjs` (esbuild → IIFE).
- Wire it into the core build script so `dist/tabmesh-worker.js` and
  `dist/tabmesh-sw.js` are produced alongside `dist/index.js`.
- Add `./worker.js` and `./sw.js` subpath exports in package.json so
  bundler-aware consumers can `import workerUrl from
  '@tabmesh/core/worker.js?url'` (Vite/Webpack pattern).
- Reduce the playground's build:worker / build:sw scripts to copies
  from the core dist — single source of truth for the bundle bytes.

Existing build pipeline (used by the Playwright webServer in CI)
already runs `pnpm --filter "@tabmesh/playground^..." build` first, so
the playground copy step finds the freshly-built core dist.

Verified: 122 unit tests + 11 Playwright tests pass, biome clean.

ADR-0003 (worker bundle distribution) and ADR-0004 (VitePress single
site) are also captured in this commit — they were drafted during the
grilling pass and codify the release/docs strategy that motivates this
build change.
@joelshejar joelshejar merged commit fb0eb79 into main May 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant