From 70715763bd110f955c0351b3816e791105670953 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 19 May 2026 11:20:47 +0800 Subject: [PATCH] fix(core): wire @snowluma/proton vite plugin into the production build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The proton plugin was only in `vitest.config.ts`, so tests and typecheck passed but the bundled `dist/index.mjs` shipped with the unsubstituted generic shells — every `protobuf_encode()` / `protobuf_decode()` call hit the runtime fallback and threw: "protobuf_encode() was not transformed by the @snowluma/proton Vite plugin. …" at every msg-push, rkey/friend/group/profile warmup, etc. on the Win/Linux releases. Add `protobufVitePlugin()` to the shared `BaseConfigPlugin` so the transform runs in both dev (`vite build --mode development`) and prod (`vite build`). Sanity-check on a fresh `vite build` shows the bundle now contains 481 distinct monomorphized codecs (704 encode + 511 decode call-site replacements), and the only remaining "was not transformed" string is the dead runtime fallback that no longer has a caller. --- packages/core/vite.config.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/core/vite.config.ts b/packages/core/vite.config.ts index 99b4d5af..79cefc18 100644 --- a/packages/core/vite.config.ts +++ b/packages/core/vite.config.ts @@ -4,6 +4,7 @@ import fs from 'fs'; import path from 'path'; import { builtinModules } from 'module'; import cp from 'vite-plugin-cp'; +import protobufVitePlugin from '@snowluma/proton/vite'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(__dirname, '..', '..'); @@ -76,6 +77,14 @@ if (missingNatives.length > 0) { } const BaseConfigPlugin: PluginOption[] = [ + // Proton substitutes every `protobuf_encode` / `protobuf_decode` + // call site with a monomorphized codec at build time. WITHOUT this + // plugin in the plugins array the runtime fallback in + // `@snowluma/proton/runtime.ts` throws on the first call (and the + // packaged Win/Linux release does exactly that). It MUST appear + // before `cp` so the transform runs on every source file Vite asks + // for, regardless of where `cp` later copies emitted assets. + protobufVitePlugin(), cp({ targets: [ ...runtimeDistFiles.map((file) => ({