Skip to content

build(dashboard): bundle via tsup so refactor can use TypeScript modules#29

Merged
esengine merged 1 commit into
mainfrom
refactor/dashboard-build-infra
May 1, 2026
Merged

build(dashboard): bundle via tsup so refactor can use TypeScript modules#29
esengine merged 1 commit into
mainfrom
refactor/dashboard-build-infra

Conversation

@esengine

@esengine esengine commented May 1, 2026

Copy link
Copy Markdown
Owner

Why

The dashboard refactor (#28) needs to extract panels into typed modules under dashboard/src/. Plain ESM-from-CDN can't follow import { x } from "./lib/format" to local sibling files at request time, so app.js has to be bundled before it lands on the browser.

The original tracking issue mistakenly listed "no build step" as a constraint. That's wrong for a TypeScript-everywhere project — src/ is already strict TS, but the dashboard was the only directory with plain .js. This PR removes that inconsistency by reusing the existing tsup pipeline.

This PR is pure infrastructure. No behavior change to the dashboard itself — dashboard/app.js passes through esbuild unmodified; CDN imports stay as live https://esm.sh/... URLs in the bundled output. The first real TS module extraction (dashboard/src/lib/format.ts) lands in the next PR.

Changes

  • tsup.config.ts — third entry: dashboard/app.jsdashboard/dist/app.js. target: es2022, platform: browser, external: [/^https:\/\//] so esm.sh imports stay as live URLs.
  • dashboard/tsconfig.json (new) — extends root config; swaps types: ["node"] for browser lib: ["ES2023", "DOM", "DOM.Iterable"]; allowJs: true so the legacy app.js compiles unmodified while new TS modules under dashboard/src/ get strict checks.
  • src/server/assets.tsloadApp() reads from dashboard/dist/app.js; new loadAppMap() serves the sourcemap (404s if missing).
  • package.json:
    • files ships dashboard/dist/ instead of the raw source app.js.
    • typecheck chains tsc --noEmit && tsc --noEmit -p dashboard.
    • verify now runs npm run build first, matching the pattern tests/bundle-smoke.test.ts already assumes.
  • tests/server-dashboard.test.ts — the asset-serving test skips when dashboard/dist/app.js is missing, mirroring the bundle-smoke convention.

Out of scope

Test plan

  • npm run build produces dashboard/dist/app.js (~136 KB) + sourcemap.
  • npm run typecheck passes both root + dashboard projects.
  • npm run lint clean (6 pre-existing warnings unrelated to this PR).
  • npm test — 1665/1665 pass.
  • CDN imports in the bundled output stay as https://esm.sh/... (verified via head dashboard/dist/app.js).
  • Manual: open the dashboard locally, confirm browser still renders the same SPA.

The dashboard refactor (#28) needs to extract panels into typed
modules. Plain ESM-from-CDN can't follow `import` paths to local
sibling files at request time, so app.js has to go through a
bundler before it lands on the browser. Reusing the existing tsup
toolchain keeps build infra consistent with src/.

- tsup.config.ts adds a third entry: `dashboard/app.js` →
  `dashboard/dist/app.js`. Browser target, externals match
  `^https://` so esm.sh imports stay as live URLs in the output.
- dashboard/tsconfig.json extends the root config, swaps Node
  types for DOM, allowJs so the legacy app.js compiles unmodified
  while new TS modules under dashboard/src/ get strict checks.
- src/server/assets.ts reads app.js from `dashboard/dist/`; new
  branch serves the sourcemap.
- typecheck script chains both root + dashboard projects; verify
  now runs build first (matches the bundle-smoke pattern that
  already assumes CI builds before tests).
- package.json files: ship `dashboard/dist/` instead of the raw
  source app.js for npm consumers.
- Asset test that touches /assets/app.js skips when
  `dashboard/dist/app.js` is missing — same convention as the
  existing tests/bundle-smoke.test.ts.

No behavioral change at the dashboard level — esbuild passes the
source through; CDN imports stay external. First real TS module
extraction follows in a separate PR.
@esengine esengine added the enhancement New feature or request label May 1, 2026
@esengine esengine merged commit 63b023a into main May 1, 2026
2 checks passed
@esengine esengine deleted the refactor/dashboard-build-infra branch May 1, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant