diff --git a/.server-changes/org-settings-app-version.md b/.server-changes/org-settings-app-version.md new file mode 100644 index 0000000000..43ae2cc5c3 --- /dev/null +++ b/.server-changes/org-settings-app-version.md @@ -0,0 +1,6 @@ +--- +area: webapp +type: fix +--- + +The app version shown on the organization settings page now reports the real version instead of v0.0.0. diff --git a/apps/webapp/vite.config.ts b/apps/webapp/vite.config.ts index 2dcdf2d47c..56ddae17c0 100644 --- a/apps/webapp/vite.config.ts +++ b/apps/webapp/vite.config.ts @@ -1,7 +1,42 @@ +import { readFileSync } from "node:fs"; import { vitePlugin as remix } from "@remix-run/dev"; -import { defaultClientConditions, defaultServerConditions, defineConfig } from "vite"; +import { defaultClientConditions, defaultServerConditions, defineConfig, type Plugin } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; +const packageVersions: Record = Object.fromEntries( + ["core", "trigger-sdk"].map((pkg) => [ + pkg, + ( + JSON.parse( + readFileSync(new URL(`../../packages/${pkg}/package.json`, import.meta.url), "utf-8") + ) as { version: string } + ).version, + ]) +); + +/** + * The `@triggerdotdev/source` condition resolves workspace packages to TS source, where + * each VERSION constant is the "0.0.0" placeholder (scripts/updateVersion.ts stamps the + * real version, but only in dist output, which this bundle never reads). Stamp the version + * modules during bundling so VERSION carries the real package version everywhere it's used. + */ +function stampPackageVersions(): Plugin { + return { + name: "stamp-package-versions", + transform(code, id) { + const match = id + .split("?")[0] + .match(/packages[/\\](core|trigger-sdk)[/\\]src[/\\]version\.ts$/); + if (match) { + return { + code: code.replace('"0.0.0"', JSON.stringify(packageVersions[match[1]])), + map: null, + }; + } + }, + }; +} + export default defineConfig({ plugins: [ remix({ @@ -10,6 +45,7 @@ export default defineConfig({ serverBuildFile: "index.mjs", }), tsconfigPaths(), + stampPackageVersions(), ], resolve: { // Resolve workspace packages to TS source (same condition the CLI uses)