Give the front end its version through the build environment

vite.config.js reads RUNESTONE_VERSION and falls back to package.json.
The installer build sets RUNESTONE_VERSION and writes all four version
files only after the installer exists. Before, it wrote package.json
before the build and restored it after a failure.

The installation guide and CLAUDE.md now say that setup replaces the
installed app in place. The installer no longer shows a maintenance page.
This commit is contained in:
Knotty Wyvern
2026-10-27 22:59:22 -07:00
parent 7914942698
commit 70510a114f
8 changed files with 37 additions and 24 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ Rules from the owner:
## Windows installer ## Windows installer
- An existing installation defaults to reinstall, also for the same version. Users never need to uninstall first. - Setup replaces an existing installation in place, also for the same version. Users never need to uninstall first.
- Reinstall and update preserve workspace files and user settings. - Reinstall and update preserve workspace files and user settings.
- Keep the protection against version downgrades. - Keep the protection against version downgrades.
+7 -7
View File
@@ -50,17 +50,17 @@ Source: `scripts/buildInstaller.mjs`.
A dry run prints the plan and stops here. A dry run prints the plan and stops here.
4. Saves copies of the four version files as `*.before` in `output/installer-build/<version>/<time>/`, a new folder for each attempt. 4. Saves copies of the four version files as `*.before` in `output/installer-build/<version>/<time>/`, a new folder for each attempt.
It also writes the configuration override `tauri.version.json` to that folder. The override sets the toolchain version, for example `{"version": "0.1.23+1"}`. It also writes the configuration override `tauri.version.json` to that folder. The override sets the toolchain version, for example `{"version": "0.1.23+1"}`.
5. Writes the new version to `package.json`. The front-end build reads this version for the Settings dialog. 5. Runs `tauri build --no-bundle --config <override> -- --locked` with `RUNESTONE_VERSION` set to the release version. This runs `pnpm build` and compiles the release app.
6. Runs `tauri build --no-bundle --config <override> -- --locked`. This runs `pnpm build` and compiles the release app. `vite.config.js` gives `RUNESTONE_VERSION` to the front end for the Settings dialog. Without it, the front end uses the version in `package.json`.
Tauri gives the override to the Rust build script and to the app. Cargo keeps the previous package version, so the app must not use `CARGO_PKG_VERSION`. Tauri gives the override to the Rust build script and to the app. Cargo keeps the previous package version, so the app must not use `CARGO_PKG_VERSION`.
7. Runs `scripts/setWindowsVersion.ps1`. It writes the release version to the `FileVersion` and `ProductVersion` strings of `runestone.exe`. Tauri can write only a SemVer version to these strings. 6. Runs `scripts/setWindowsVersion.ps1`. It writes the release version to the `FileVersion` and `ProductVersion` strings of `runestone.exe`. Tauri can write only a SemVer version to these strings.
8. Runs `tauri bundle --bundles nsis --config <override>`. Tauri uses its stock NSIS template with the [installer hooks](#installer-hooks). 7. Runs `tauri bundle --bundles nsis --config <override>`. Tauri uses its stock NSIS template with the [installer hooks](#installer-hooks).
9. Moves the setup file into `releases/<version>/`, writes `host.json`, and removes the bundle-folder copy. 8. Moves the setup file into `releases/<version>/`, writes `host.json`, and removes the bundle-folder copy.
10. Writes the new version to `tauri.conf.json`, `Cargo.toml`, and `Cargo.lock`. 9. Writes the new version to `package.json`, `tauri.conf.json`, `Cargo.toml`, and `Cargo.lock`.
### Failure and rollback ### Failure and rollback
If a step fails, or you press Ctrl+C, the script restores `package.json`. The other version files change only in step 10. If step 10 fails, the script restores them too. The version files change only in step 9. If a step fails, or you press Ctrl+C, the version files keep the previous version. If step 9 fails, the script restores them.
It moves partial setup files and `host.json` into the folder of that attempt with a `.failed-<timestamp>` suffix. It moves partial setup files and `host.json` into the folder of that attempt with a `.failed-<timestamp>` suffix.
If the process is killed before this cleanup, copy the `*.before` files of the attempt back to their original names. If the process is killed before this cleanup, copy the `*.before` files of the attempt back to their original names.
+1 -1
View File
@@ -26,7 +26,7 @@ Each release file includes the app and its built-in browser. You do not need Nod
3. Open the installer for the same or a newer version. 3. Open the installer for the same or a newer version.
4. Complete setup. 4. Complete setup.
You do not need to uninstall first. Setup selects reinstall by default, also for the same version. You do not need to uninstall first. Setup replaces the installed app in place, also for the same version.
Setup keeps your workspace files and settings. It does not install an older version over a newer one. Setup keeps your workspace files and settings. It does not install an older version over a newer one.
## Install on macOS ## Install on macOS
+11 -11
View File
@@ -61,7 +61,9 @@ export async function planInstallerBuild(root, requestedVersion) {
const updated = [JSON.stringify(packageJson, null, 2) + '\n', JSON.stringify(config, null, 2) + '\n', cargo, lock]; const updated = [JSON.stringify(packageJson, null, 2) + '\n', JSON.stringify(config, null, 2) + '\n', cargo, lock];
// Tauri merges this override into tauri.conf.json for the build script, the app, and the bundler. // Tauri merges this override into tauri.conf.json for the build script, the app, and the bundler.
const override = { version: next.toolchain }; const override = { version: next.toolchain };
return { root, files, before, updated, current, next, override, releaseDir, artifacts }; // vite.config.js gives this version to the front end, so package.json can wait until the build completes.
const env = { RUNESTONE_VERSION: next.version };
return { root, files, before, updated, current, next, override, env, releaseDir, artifacts };
} }
// The commands of a build, in order. overridePath is the file with plan.override. // The commands of a build, in order. overridePath is the file with plan.override.
@@ -82,15 +84,15 @@ export function describePlan(plan, overridePath = '<attempt folder>/tauri.versio
`Release version: ${plan.next.version} (current ${plan.current.version})`, `Release version: ${plan.next.version} (current ${plan.current.version})`,
`Toolchain version: ${plan.next.toolchain}. Windows version: ${plan.next.windows}.`, `Toolchain version: ${plan.next.toolchain}. Windows version: ${plan.next.windows}.`,
`Configuration override: ${JSON.stringify(plan.override)}`, `Configuration override: ${JSON.stringify(plan.override)}`,
`1. Write version ${plan.next.version} to package.json. The front-end build reads it. A failed build restores it.`, `Environment: ${Object.entries(plan.env).map(([key, value]) => `${key}=${value}`).join(' ')}`,
...buildCommands(plan, overridePath).map((entry, index) => `${index + 2}. ${entry.step}: ${[entry.command, ...entry.args].join(' ')}`), ...buildCommands(plan, overridePath).map((entry, index) => `${index + 1}. ${entry.step}: ${[entry.command, ...entry.args].join(' ')}`),
`5. Move the setup file to ${relative(plan.artifacts.release)} and write ${relative(plan.artifacts.metadata)}.`, `4. Move the setup file to ${relative(plan.artifacts.release)} and write ${relative(plan.artifacts.metadata)}.`,
`6. Write the new version to ${versionFiles.slice(1).join(', ')}.`, `5. Write the new version to ${versionFiles.join(', ')}.`,
].join('\n'); ].join('\n');
} }
// Runs the build. run(command, args) must reject when a command fails. // Runs the build. run(command, args) must reject when a command fails.
// The tracked version files change only when the build completes, except package.json during the build. // The tracked version files change only when the build completes.
export async function runInstallerBuild(plan, run, staging) { export async function runInstallerBuild(plan, run, staging) {
const { files, before, updated, artifacts } = plan; const { files, before, updated, artifacts } = plan;
await fs.mkdir(staging, { recursive: true }); await fs.mkdir(staging, { recursive: true });
@@ -99,8 +101,6 @@ export async function runInstallerBuild(plan, run, staging) {
await fs.writeFile(overridePath, JSON.stringify(plan.override, null, 2) + '\n'); await fs.writeFile(overridePath, JSON.stringify(plan.override, null, 2) + '\n');
let complete = false; let complete = false;
try { try {
// src/lib/layout/SettingsDialog.svelte imports the version from package.json.
await fs.writeFile(files[0], updated[0]);
for (const { command, args } of buildCommands(plan, overridePath)) await run(command, args); for (const { command, args } of buildCommands(plan, overridePath)) await run(command, args);
await fs.access(artifacts.bundled); await fs.access(artifacts.bundled);
if (artifacts.bundled !== artifacts.renamed) await fs.rename(artifacts.bundled, artifacts.renamed); if (artifacts.bundled !== artifacts.renamed) await fs.rename(artifacts.bundled, artifacts.renamed);
@@ -111,7 +111,7 @@ export async function runInstallerBuild(plan, run, staging) {
file: path.basename(artifacts.release), bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') }; file: path.basename(artifacts.release), bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') };
await fs.writeFile(artifacts.metadata, JSON.stringify(metadata, null, 2) + '\n', { flag: 'wx' }); await fs.writeFile(artifacts.metadata, JSON.stringify(metadata, null, 2) + '\n', { flag: 'wx' });
await fs.unlink(artifacts.renamed); await fs.unlink(artifacts.renamed);
for (let i = 1; i < files.length; i++) await fs.writeFile(files[i], updated[i]); for (let i = 0; i < files.length; i++) await fs.writeFile(files[i], updated[i]);
complete = true; complete = true;
return artifacts.release; return artifacts.release;
} finally { } finally {
@@ -136,8 +136,8 @@ async function main() {
return; return;
} }
if (process.platform !== 'win32') throw Error('Build the Windows installer on Windows.'); if (process.platform !== 'win32') throw Error('Build the Windows installer on Windows.');
const env = { ...process.env, GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'safe.directory', GIT_CONFIG_VALUE_0: root.replaceAll('\\', '/') }; const env = { ...process.env, ...plan.env, GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'safe.directory', GIT_CONFIG_VALUE_0: root.replaceAll('\\', '/') };
// Ctrl+C also stops the child build. Keep this process alive so that package.json is restored. // Ctrl+C also stops the child build. Keep this process alive so that the cleanup runs.
let interrupted = false; let interrupted = false;
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, () => { interrupted = true; process.exitCode = 130; }); for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, () => { interrupted = true; process.exitCode = 130; });
async function run(command, parameters) { async function run(command, parameters) {
+4
View File
@@ -0,0 +1,4 @@
declare const __RUNESTONE_VERSION__: string | undefined;
/** The release version. vite.config.js defines it from RUNESTONE_VERSION or package.json. */
export const appVersion: string = typeof __RUNESTONE_VERSION__ === "string" ? __RUNESTONE_VERSION__ : "dev";
+2 -1
View File
@@ -12,7 +12,8 @@
import Icon from "$lib/ui/Icon.svelte"; import Icon from "$lib/ui/Icon.svelte";
import IconButton, { type IconName } from "$lib/ui/IconButton.svelte"; import IconButton, { type IconName } from "$lib/ui/IconButton.svelte";
import { DEFAULT_SETTINGS, MIN_AUTOSAVE_SECONDS, MAX_AUTOSAVE_SECONDS, validAutosaveSeconds, type AppSettings } from "$lib/workspace/settings"; import { DEFAULT_SETTINGS, MIN_AUTOSAVE_SECONDS, MAX_AUTOSAVE_SECONDS, validAutosaveSeconds, type AppSettings } from "$lib/workspace/settings";
import { version, license } from "../../../package.json"; import { license } from "../../../package.json";
import { appVersion as version } from "../appVersion";
let { settings, help = false, standalone = false, windowError = "", windowControls, onSave, onClose }: { let { settings, help = false, standalone = false, windowError = "", windowControls, onSave, onClose }: {
settings: AppSettings; settings: AppSettings;
+3 -3
View File
@@ -58,9 +58,9 @@ test('a completed build sets the version fields only after the installer exists'
assert.deepEqual(calls.map(({ command, args }) => ({ command, args })), assert.deepEqual(calls.map(({ command, args }) => ({ command, args })),
buildCommands(plan, overridePath).map(({ command, args }) => ({ command, args }))); buildCommands(plan, overridePath).map(({ command, args }) => ({ command, args })));
for (const call of calls) { for (const call of calls) {
// The front end reads package.json. Tauri, Cargo, and the bundler get the version from the override. // Tauri, Cargo, and the bundler get the version from the override. The front end gets it from plan.env.
assert.equal(JSON.parse(call.files[0]).version, next.version); assert.deepEqual(call.files, before, 'No version file changes during the build.');
assert.deepEqual(call.files.slice(1), before.slice(1), 'Only package.json changes during the build.'); assert.deepEqual(plan.env, { RUNESTONE_VERSION: next.version });
} }
assert.equal(installer, path.join(root, 'releases', next.version, `RuneStone_${next.version}_x64-setup.exe`)); assert.equal(installer, path.join(root, 'releases', next.version, `RuneStone_${next.version}_x64-setup.exe`));
assert.equal(await readFile(installer, 'utf8'), 'setup'); assert.equal(await readFile(installer, 'utf8'), 'setup');
+8
View File
@@ -1,6 +1,11 @@
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite"; import { sveltekit } from "@sveltejs/kit/vite";
import process from "node:process"; import process from "node:process";
import { readFileSync } from "node:fs";
// The installer build sets RUNESTONE_VERSION. It writes package.json only after the build completes.
const packageVersion = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
const appVersion = process.env.RUNESTONE_VERSION || packageVersion;
const host = process.env.TAURI_DEV_HOST; const host = process.env.TAURI_DEV_HOST;
const monacoCss = `${process.cwd().replaceAll("\\", "/")}/node_modules/monaco-editor/min/vs/editor/editor.main.css`; const monacoCss = `${process.cwd().replaceAll("\\", "/")}/node_modules/monaco-editor/min/vs/editor/editor.main.css`;
@@ -8,6 +13,9 @@ const monacoCss = `${process.cwd().replaceAll("\\", "/")}/node_modules/monaco-ed
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig(() => ({ export default defineConfig(() => ({
plugins: [sveltekit()], plugins: [sveltekit()],
define: {
__RUNESTONE_VERSION__: JSON.stringify(appVersion),
},
resolve: { resolve: {
alias: { alias: {
"monaco-editor-css": monacoCss, "monaco-editor-css": monacoCss,