/** * vapor-chamber - Vite plugins: HMR (serve) and build-time Vue wiring (build) * * Three plugins (the history is in CHANGELOG.md): * - `vaporChamberHMR()`, serve-only: marks each hot update, so the stores * keep their states and a handler registered again raises no warning. * - `vaporChamberWire()`: in a build it resolves the bare 'vapor-chamber' * specifier to a virtual module that imports 'vapor-chamber/vue' (or * '/vapor') for its side effect and re-exports the real root, so an app * importing from the root is wired in production with no import changed. * It also defines `__VC_WIRED_BUILD__` there, which folds the root's * runtime Vue probe out of the build (chamber.ts). * Under the dev server it does not redirect and defines `__VC_WIRED__`, * which chamber.ts's DEV probe hint reads: a dev-time redirect over a * pre-bundled install put two chamber modules in the page (see the * function's note). In both it defines `__VC_LEAN__`, the build profile * (the `profile` option), unless the app defines it. * - `vaporChamberTest()`: the Vitest plugin for `vapor-chamber/vitest` * (setup file, shared-bus exclusions, the island project). * * The rules the HMR shim keeps: * - SCRIPTS ONLY. `enforce: 'pre'` runs ahead of @vitejs/plugin-vue, and * compiler-sfc discards text outside every block without a diagnostic, so * a shim prepended to an SFC is never delivered. The shim goes on the SAME * line as the first import, so no line moves and Vite's identity source * map stays correct (see transform()). * - It primes the library's Vue slot (`globalThis.__VAPOR_CHAMBER_VUE__`, * never Vue's own `__VUE__`) from the consumer's 'vue' through a * companion virtual module that evaluates before 'vapor-chamber': the * async probe's bare-specifier import cannot resolve in a browser, so * without it `createVaporChamberApp()` throws on every dev page load. The * module is emitted only when 'vue' resolves. * - The bus is persisted at most once per HMR update however many parent * reloads fire (Vue dedupes them too), and inside try/catch, so a failed * pass cannot latch global state (Vue resets its own `isHmrUpdating` flag * the same way, 991a885). * - `__vapor` is tracked across reloads, so a component switching render * mode keeps its bus state. * - The preserved bus is why a hot reload must tear down the old * generation's listeners: Vue's per-render EffectScope (rc.6, 9ab65a1) * disposes the setup scopes `useCommand()` hangs its cleanup on, and * without it one dispatch fired a listener once per generation ever * rendered (tests/hmr-render-scope-fixture.test.ts). * * The shared bus lives in the library's module, which a hot update of the * app's modules does not re-run, so it keeps its handlers with or without * this plugin. A module that builds its own bus gets a new one on each re-run. * The plugin marks each update, so a store a re-run module replaces keeps its * state (store-base.ts) and the handlers it registers again raise no * overwrite warning (command-bus.ts register()). Without the plugin, the store * starts from `state()` and each action registered again warns. Other state a * re-run module creates, such as a `signal()`, is built again from its * initial value. tests/examples/feature-vite-hmr.test.ts, * tests/register-hot-update.test.ts. * * Tested against: * - Vite >= 7.0.0 (programmatic build API + library mode) * - @vitejs/plugin-vue >= 5.0.0 (Vue 3.6 Vapor SFC support - earlier * plugin-vue versions only handle 3.5 VDOM and silently skip vapor blocks) * - Vue >= 3.5.0 (composables) or >= 3.6.0-beta.14 (full Vapor surface) * * If you're on plugin-vue v4 the HMR plugin still works for VDOM SFCs but * you'll miss Vapor support entirely - Vapor `