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:
@@ -82,7 +82,7 @@ Rules from the owner:
|
||||
|
||||
## 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.
|
||||
- Keep the protection against version downgrades.
|
||||
|
||||
|
||||
+7
-7
@@ -50,17 +50,17 @@ Source: `scripts/buildInstaller.mjs`.
|
||||
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.
|
||||
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.
|
||||
6. Runs `tauri build --no-bundle --config <override> -- --locked`. This runs `pnpm build` and compiles the release app.
|
||||
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.
|
||||
`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`.
|
||||
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.
|
||||
8. 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.
|
||||
10. Writes the new version to `tauri.conf.json`, `Cargo.toml`, and `Cargo.lock`.
|
||||
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.
|
||||
7. Runs `tauri bundle --bundles nsis --config <override>`. Tauri uses its stock NSIS template with the [installer hooks](#installer-hooks).
|
||||
8. Moves the setup file into `releases/<version>/`, writes `host.json`, and removes the bundle-folder copy.
|
||||
9. Writes the new version to `package.json`, `tauri.conf.json`, `Cargo.toml`, and `Cargo.lock`.
|
||||
|
||||
### 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.
|
||||
If the process is killed before this cleanup, copy the `*.before` files of the attempt back to their original names.
|
||||
|
||||
|
||||
@@ -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.
|
||||
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.
|
||||
|
||||
## Install on macOS
|
||||
|
||||
+11
-11
@@ -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];
|
||||
// Tauri merges this override into tauri.conf.json for the build script, the app, and the bundler.
|
||||
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.
|
||||
@@ -82,15 +84,15 @@ export function describePlan(plan, overridePath = '<attempt folder>/tauri.versio
|
||||
`Release version: ${plan.next.version} (current ${plan.current.version})`,
|
||||
`Toolchain version: ${plan.next.toolchain}. Windows version: ${plan.next.windows}.`,
|
||||
`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.`,
|
||||
...buildCommands(plan, overridePath).map((entry, index) => `${index + 2}. ${entry.step}: ${[entry.command, ...entry.args].join(' ')}`),
|
||||
`5. 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(', ')}.`,
|
||||
`Environment: ${Object.entries(plan.env).map(([key, value]) => `${key}=${value}`).join(' ')}`,
|
||||
...buildCommands(plan, overridePath).map((entry, index) => `${index + 1}. ${entry.step}: ${[entry.command, ...entry.args].join(' ')}`),
|
||||
`4. Move the setup file to ${relative(plan.artifacts.release)} and write ${relative(plan.artifacts.metadata)}.`,
|
||||
`5. Write the new version to ${versionFiles.join(', ')}.`,
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
// 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) {
|
||||
const { files, before, updated, artifacts } = plan;
|
||||
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');
|
||||
let complete = false;
|
||||
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);
|
||||
await fs.access(artifacts.bundled);
|
||||
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') };
|
||||
await fs.writeFile(artifacts.metadata, JSON.stringify(metadata, null, 2) + '\n', { flag: 'wx' });
|
||||
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;
|
||||
return artifacts.release;
|
||||
} finally {
|
||||
@@ -136,8 +136,8 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
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('\\', '/') };
|
||||
// Ctrl+C also stops the child build. Keep this process alive so that package.json is restored.
|
||||
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 the cleanup runs.
|
||||
let interrupted = false;
|
||||
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, () => { interrupted = true; process.exitCode = 130; });
|
||||
async function run(command, parameters) {
|
||||
|
||||
@@ -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";
|
||||
@@ -12,7 +12,8 @@
|
||||
import Icon from "$lib/ui/Icon.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 { 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 }: {
|
||||
settings: AppSettings;
|
||||
|
||||
@@ -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 })),
|
||||
buildCommands(plan, overridePath).map(({ command, args }) => ({ command, args })));
|
||||
for (const call of calls) {
|
||||
// The front end reads package.json. Tauri, Cargo, and the bundler get the version from the override.
|
||||
assert.equal(JSON.parse(call.files[0]).version, next.version);
|
||||
assert.deepEqual(call.files.slice(1), before.slice(1), 'Only package.json changes during the build.');
|
||||
// Tauri, Cargo, and the bundler get the version from the override. The front end gets it from plan.env.
|
||||
assert.deepEqual(call.files, before, 'No version file 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(await readFile(installer, 'utf8'), 'setup');
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { sveltekit } from "@sveltejs/kit/vite";
|
||||
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 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/
|
||||
export default defineConfig(() => ({
|
||||
plugins: [sveltekit()],
|
||||
define: {
|
||||
__RUNESTONE_VERSION__: JSON.stringify(appVersion),
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"monaco-editor-css": monacoCss,
|
||||
|
||||
Reference in New Issue
Block a user