From b60d3970e091200e6050f9bdc32d15e621722822 Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Wed, 16 Sep 2026 17:27:53 -0400 Subject: [PATCH] fix(frontend): inline only the package version, not the whole package.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `vite.config.js` had `define: { __pkg__: version }` where `version` was the entire parsed `package.json`. Vite's `define` substitutes the full object literal at every site that reads `__pkg__.version`, so each of those sites became `{name:..., version:..., scripts:{...}, devDependencies:{...}, ...}.version` in the client bundle and the minifier kept the object. On origin/main that is 11 copies of a 22,093-byte object (npm scripts, dependency/devDependency lists, overrides) across three chunks — 243,023 bytes of package.json shipped to every browser, for a single version string. The only property ever read is `__pkg__.version` (script_helpers.ts, apps/editor/component/default-codes.ts, flows/content/s3Scripts/deno.ts), and the declarations in src/app.d.ts, src/global.d.ts and sharedUtils/sharedUtils.d.ts already type it as `{ version: string }`, so define the dotted expression `__pkg__.version` to the JSON-encoded version string instead. Any new property read would now fail `npm run check` rather than silently compile to `undefined`. Verification (npm ci, generate-backend-client, check, build): - `npm run check`: 0 errors, 82 warnings. - `grep -l '"generate-backend-client"' build/_app/immutable/**/*.js`: 3 chunks before, none after. - `grep -c 'windmill-labs/components' -r build/_app/immutable`: 11 → 0. - `npm:windmill-client@1.813.0` still appears in the chunks that build the default Deno/pgsql/S3 snippets (3 chunks, 11 sites). - build/_app/immutable apparent size: 81,815 KB → 81,578 KB (JS bytes 54,202,793 → 53,959,705, -243,088 bytes). Co-Authored-By: Claude Fable 5.1 --- frontend/vite.config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 0140c38739..36c353e28a 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -6,7 +6,10 @@ import mkcert from 'vite-plugin-mkcert' const file = fileURLToPath(new URL('package.json', import.meta.url)) const json = readFileSync(file, 'utf8') -const version = JSON.parse(json) +// Only the version is exposed to the client (see `define` below). Defining the +// whole parsed package.json would inline it — scripts, dependency lists, ... — +// into every chunk that reads `__pkg__.version`. +const { version } = JSON.parse(json) // The postinstall downloads the pinned UI Builder artifact into static/ui_builder, // which SvelteKit serves at /ui_builder. Serve that directly; only proxy to a @@ -278,7 +281,7 @@ const config = { assertAcyclicChunks(), assertLeanPublicAppRoutes() ], - define: { __pkg__: version }, + define: { '__pkg__.version': JSON.stringify(version) }, optimizeDeps: { include: ['highlight.js', 'highlight.js/lib/core', 'monaco-vim'], exclude: [