frontend module conversion) ui-state was the smallest, most isolated module: 35 lines, zero legacy- global dependencies, single concern (localStorage helpers under the 'ped_ui/' namespace). Ideal first migration to validate the strangler- fig pattern end-to-end. Changes: - New: client/ui-state.ts — exports get/set/del + UIState bundle. Keeps (window as any).UIState = UIState assignment so the 10+ legacy consumers (sub-nav.js, peGuide.js, app.js, etc.) keep working without modification. As each consumer is migrated, it will replace the window.UIState read with an explicit import. - client/main.ts: import './ui-state' so it gets bundled into main.js. - scripts/build-client.mjs: explicit ENTRIES list (just 'main.ts' for now) — was scanning every top-level .ts as an entry, which produced duplicate ui-state.js bundle. - public/index.html: <script defer src="/js/ui-state.js"> removed; the TS bundle (/dist/main.js) now provides window.UIState. - public/js/ui-state.js: deleted (now lives in client/). Verification: - npm run typecheck:client → 0 errors - npm run build:client → 349-byte main.js bundle (gzipped will be ~200B) - 46/46 unit tests pass - The 10 cross-file consumers of UIState.get/set/del still work because the window assignment lives in the bundle. Pattern documented for next migrations: each new client/X.ts is imported as a side-effect from main.ts. The window-bridge stays until every consumer also moves to ES imports.
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
// ============================================================
|
|
// client/main.ts — Entry point for the TypeScript frontend bundle.
|
|
//
|
|
// Built by scripts/build-client.mjs into public/dist/main.js,
|
|
// loaded by index.html via:
|
|
// <script type="module" src="/dist/main.js"></script>
|
|
//
|
|
// Strangler-fig migration: this bundle runs ALONGSIDE the legacy
|
|
// public/js/*.js IIFE files. As each legacy module is migrated, it
|
|
// moves out of public/js/ into client/<feature>/ and is imported
|
|
// from this entry point. The legacy script tag is removed from
|
|
// index.html in the same commit.
|
|
//
|
|
// Sacred files (per project memory) — DO NOT migrate without
|
|
// per-file approval from Daniel:
|
|
// - public/js/encounters.js (save/idempotency logic)
|
|
// - public/js/voiceDictation.js, sickVisit.js recording paths
|
|
// (voice/STT plumbing)
|
|
// ============================================================
|
|
|
|
// Migrated modules — each side-effect import installs its window-global
|
|
// shim for legacy consumers and self-registers any DOM listeners.
|
|
import './ui-state';
|
|
|
|
console.log('[client] TypeScript bundle loaded.');
|
|
|
|
// Marker so anything else that wants to know if the bundle reached
|
|
// the page can check window.__clientBundle === true.
|
|
(window as any).__clientBundle = true;
|
|
|
|
export {};
|