fix(qodana): clear the first run's findings

The first Qodana run found 74 problems in TypeScript / JavaScript and 12 in
Rust. Fixed:
- React 19.3 deprecates `FormEvent`: the three save forms take the
  `SubmitEvent` their `onSubmit` hands them.
- The URL patterns read `\S` instead of `[^\s]` (18 patterns in platforms.ts
  and playtest-platforms.ts, same characters).
- public/theme-init.js declares its browser globals and drops an unused
  catch binding.
- The two private `stable()` JSON helpers (restore.ts, library-apply.ts)
  become one `stableJson()` in src/utils/stable-json.ts, with a test.
- vitest.config.ts reuses vite.config.ts's alias map instead of a copy.
- Accordion destructures `icon` as `Icon` instead of copying it, a JSDoc
  link points at nothing any more, and i18next's `init()` promise is
  `void`ed on purpose.
- Rust: the three "show the main window" blocks become `show_main_window`.

Excluded in qodana.yaml, each with its reason: the Discord webhook secret
reference (HardcodedPasswords), escaped `]` / `}` in regexes, the
`@i18n/index` imports tsconfig needs, the three react-hooks warnings
eslint.config.js documents, the legacy `@deprecated` draft fields in the
files that migrate them; in src-tauri/qodana.yaml the module paths
`generate_handler!` needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5.5 committed 2026-11-17 10:38:59 +07:00
1 parent 5a9e7e83de
commit 3b1b17ebf1
18 files changed
+147 -105

No files matched your search

+2 -1
View File
@@ -2,6 +2,7 @@
// first paint, so a light-theme user never sees the dark default flash. A // first paint, so a light-theme user never sees the dark default flash. A
// separate file rather than an inline <script> so the Content-Security-Policy // separate file rather than an inline <script> so the Content-Security-Policy
// needs no exception. // needs no exception.
/* global document, localStorage */
(function () { (function () {
var root = document.documentElement; var root = document.documentElement;
var theme = "dark"; var theme = "dark";
@@ -14,7 +15,7 @@
// Unhealed raw storage, so only a real `true` counts. // Unhealed raw storage, so only a real `true` counts.
if (state && state.hideScrollbars === true) hideScrollbars = true; if (state && state.hideScrollbars === true) hideScrollbars = true;
if (state && typeof state.appLanguage === "string") lang = state.appLanguage; if (state && typeof state.appLanguage === "string") lang = state.appLanguage;
} catch (e) { } catch {
/* storage blocked or corrupt: keep the defaults */ /* storage blocked or corrupt: keep the defaults */
} }
root.classList.toggle("dark", theme === "dark"); root.classList.toggle("dark", theme === "dark");
+35
View File
@@ -22,3 +22,38 @@ exclude:
- .wrangler - .wrangler
# The GitHub Pages moving notice, removed on 2026-11-29 (issue #177). # The GitHub Pages moving notice, removed on 2026-11-29 (issue #177).
- migration-page - migration-page
# `${{ secrets.DISCORD_RELEASE_PIPELINE_WEBHOOK }}` is a reference to a
# repository secret, not a secret: the "discord-client-secret" rule only
# sees the word.
- name: HardcodedPasswords
paths:
- .github/workflows/notify-release-pipeline.yml
# `\]` and `\}` outside a character class stay escaped: they read as the
# literal brackets they are, and the patterns stay valid if they ever get
# the `u` or `v` flag, where a lone `]` or `}` is a syntax error. ESLint's
# no-useless-escape accepts them too.
- name: RegExpRedundantEscape
# `@i18n/index` is the form tsconfig.json's `@i18n/*` path resolves. The
# bare `@i18n` this suggests resolves only through Vite's alias, so tsc
# would no longer find the module.
- name: ES6PreferShortImport
# The three react-hooks warnings eslint.config.js documents (state synced
# from i18next, from a store number, and a useMemo the React Compiler
# can't keep): each needs a restructure, and the config keeps them as
# warnings on purpose. ESLint runs in CI's `check` job as well.
- name: Eslint
paths:
- src/hooks/use-languages-ready.ts
- src/components/editor/PlaytestEditor.tsx
- src/components/editor/StoreLinkEditor.tsx
# The legacy draft fields `spoilerWarning`, `matureWarning` and
# `endingsShown` are `@deprecated` so new code doesn't use them; these
# files carry them on purpose, to read and migrate drafts, presets and
# templates saved by older versions.
- name: JSDeprecatedSymbols
paths:
- src/config/defaults.ts
- src/store/editor-store.ts
- src/hooks/use-current-generator-input.ts
- src/engine/description-builder.ts
- src/utils/library-apply.ts
+7
View File
@@ -23,3 +23,10 @@ exclude:
# generated (Kotlin and Gradle, not Rust). # generated (Kotlin and Gradle, not Rust).
- target - target
- gen - gen
# tauri::generate_handler! needs each command's module path
# (`storage::backup_list`): the #[tauri::command] macro puts a hidden
# helper next to the function, and the handler finds it through that
# path. Without the prefix the crate no longer compiles.
- name: RsUnnecessaryQualifications
paths:
- src/lib.rs
+14 -18
View File
@@ -17,6 +17,17 @@ use tauri::{
mod file_dialog; mod file_dialog;
mod storage; mod storage;
/// Bring the main window back: show it, restore it if minimized and focus
/// it. Used by a second launch, the tray menu's "Show" and a tray click.
#[cfg(desktop)]
fn show_main_window<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();
}
}
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
// Plugins and commands shared by every platform (desktop + Android). // Plugins and commands shared by every platform (desktop + Android).
@@ -62,11 +73,7 @@ pub fn run() {
// in the *first* (already-running) instance when a second launch is // in the *first* (already-running) instance when a second launch is
// attempted: we surface its window instead of letting the second boot. // attempted: we surface its window instead of letting the second boot.
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
if let Some(window) = app.get_webview_window("main") { show_main_window(app);
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();
}
})) }))
.setup(move |app| { .setup(move |app| {
let show = MenuItem::with_id(app, "show", "Show YTDescGen", true, None::<&str>)?; let show = MenuItem::with_id(app, "show", "Show YTDescGen", true, None::<&str>)?;
@@ -83,13 +90,7 @@ pub fn run() {
.tooltip("YTDescGen — YouTube Description Generator") .tooltip("YTDescGen — YouTube Description Generator")
.menu(&menu) .menu(&menu)
.on_menu_event(move |app, event| match event.id.as_ref() { .on_menu_event(move |app, event| match event.id.as_ref() {
"show" => { "show" => show_main_window(app),
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();
}
}
"quit" => { "quit" => {
quitting_menu.store(true, Ordering::SeqCst); quitting_menu.store(true, Ordering::SeqCst);
app.exit(0); app.exit(0);
@@ -103,12 +104,7 @@ pub fn run() {
.. ..
} = event } = event
{ {
let app = tray.app_handle(); show_main_window(tray.app_handle());
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();
}
} }
}) })
.build(app)?; .build(app)?;
+2 -2
View File
@@ -1,4 +1,4 @@
import { useId, useState, type FormEvent } from "react"; import { useId, useState, type SubmitEvent } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { toast } from "sonner"; import { toast } from "sonner";
import { Modal } from "@components/ui/Modal"; import { Modal } from "@components/ui/Modal";
@@ -35,7 +35,7 @@ function PresetSaveFormBody({ onClose, editPreset }: PresetSaveFormProps) {
); );
const [fromEditor, setFromEditor] = useState(false); const [fromEditor, setFromEditor] = useState(false);
const save = (e: FormEvent) => { const save = (e: SubmitEvent) => {
e.preventDefault(); e.preventDefault();
const fields = presetFieldsFromEditor(editorDataOf(useEditorStore.getState())); const fields = presetFieldsFromEditor(editorDataOf(useEditorStore.getState()));
const name = gameName.trim() || fields.gameName.trim() || t("presets.unnamed"); const name = gameName.trim() || fields.gameName.trim() || t("presets.unnamed");
+2 -2
View File
@@ -1,4 +1,4 @@
import { useId, useState, type FormEvent } from "react"; import { useId, useState, type SubmitEvent } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { toast } from "sonner"; import { toast } from "sonner";
import { Modal } from "@components/ui/Modal"; import { Modal } from "@components/ui/Modal";
@@ -38,7 +38,7 @@ function ProfileSaveFormBody({ onClose, editProfile }: ProfileSaveFormProps) {
); );
const [fromEditor, setFromEditor] = useState(false); const [fromEditor, setFromEditor] = useState(false);
const save = (e: FormEvent) => { const save = (e: SubmitEvent) => {
e.preventDefault(); e.preventDefault();
const fields = profileFieldsFromEditor(editorDataOf(useEditorStore.getState())); const fields = profileFieldsFromEditor(editorDataOf(useEditorStore.getState()));
const finalName = name.trim() || fields.channelName.trim() || t("profiles.unnamed"); const finalName = name.trim() || fields.channelName.trim() || t("profiles.unnamed");
@@ -1,4 +1,4 @@
import { useId, useState, type FormEvent } from "react"; import { useId, useState, type SubmitEvent } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { toast } from "sonner"; import { toast } from "sonner";
import { Modal } from "@components/ui/Modal"; import { Modal } from "@components/ui/Modal";
@@ -32,7 +32,7 @@ function TemplateSaveFormBody({ onClose, editTemplate }: TemplateSaveFormProps)
const [name, setName] = useState(editTemplate?.name ?? ""); const [name, setName] = useState(editTemplate?.name ?? "");
const [fromEditor, setFromEditor] = useState(false); const [fromEditor, setFromEditor] = useState(false);
const save = (e: FormEvent) => { const save = (e: SubmitEvent) => {
e.preventDefault(); e.preventDefault();
const snapshot = structuredClone(editorDataOf(useEditorStore.getState())); const snapshot = structuredClone(editorDataOf(useEditorStore.getState()));
const finalName = name.trim() || snapshot.gameName.trim() || t("templates.unnamed"); const finalName = name.trim() || snapshot.gameName.trim() || t("templates.unnamed");
+2 -2
View File
@@ -29,7 +29,8 @@ interface AccordionProps {
export function Accordion({ export function Accordion({
id, id,
title, title,
icon, // Capitalised so JSX reads it as a component, not an HTML tag.
icon: Icon,
summary, summary,
badge, badge,
open, open,
@@ -37,7 +38,6 @@ export function Accordion({
children, children,
}: AccordionProps) { }: AccordionProps) {
const panelId = `section-${id}-panel`; const panelId = `section-${id}-panel`;
const Icon = icon;
return ( return (
<section <section
id={`section-${id}`} id={`section-${id}`}
+14 -14
View File
@@ -46,7 +46,7 @@ export const PLATFORMS: readonly PlatformConfig[] = [
// /app/, /sub/ (package) or /bundle/ + <digits>, optionally followed by // /app/, /sub/ (package) or /bundle/ + <digits>, optionally followed by
// /<slug>; or the s.team/a/<digits> short link. // /<slug>; or the s.team/a/<digits> short link.
urlPattern: urlPattern:
/^https:\/\/(?:store\.steampowered\.com\/(?:app|sub|bundle)\/\d+(?:\/[^\s]*)?|s\.team\/a\/\d+\/?)$/i, /^https:\/\/(?:store\.steampowered\.com\/(?:app|sub|bundle)\/\d+(?:\/\S*)?|s\.team\/a\/\d+\/?)$/i,
normalize: normalizeSteamUrl, normalize: normalizeSteamUrl,
}, },
{ {
@@ -54,14 +54,14 @@ export const PLATFORMS: readonly PlatformConfig[] = [
tagName: "Epic Games", tagName: "Epic Games",
label: "Epic Games Store", label: "Epic Games Store",
urlPrefix: "https://store.epicgames.com/", urlPrefix: "https://store.epicgames.com/",
urlPattern: /^https:\/\/(?:store\.epicgames\.com|www\.epicgames\.com\/store)\/[^\s]+$/i, urlPattern: /^https:\/\/(?:store\.epicgames\.com|www\.epicgames\.com\/store)\/\S+$/i,
}, },
{ {
id: "ps", id: "ps",
tagName: "PlayStation", tagName: "PlayStation",
label: "PlayStation Store", label: "PlayStation Store",
urlPrefix: "https://store.playstation.com/", urlPrefix: "https://store.playstation.com/",
urlPattern: /^https:\/\/store\.playstation\.com\/[^\s]+$/i, urlPattern: /^https:\/\/store\.playstation\.com\/\S+$/i,
}, },
{ {
id: "xbox", id: "xbox",
@@ -70,7 +70,7 @@ export const PLATFORMS: readonly PlatformConfig[] = [
urlPrefix: "https://www.xbox.com/games/", urlPrefix: "https://www.xbox.com/games/",
// xbox.com (with or without www) and the Microsoft Store web pages. // xbox.com (with or without www) and the Microsoft Store web pages.
urlPattern: urlPattern:
/^https:\/\/(?:(?:www\.)?xbox\.com|apps\.microsoft\.com|www\.microsoft\.com\/[a-z-]*\/?store)\/[^\s]*$/i, /^https:\/\/(?:(?:www\.)?xbox\.com|apps\.microsoft\.com|www\.microsoft\.com\/[a-z-]*\/?store)\/\S*$/i,
}, },
{ {
id: "nintendo", id: "nintendo",
@@ -80,14 +80,14 @@ export const PLATFORMS: readonly PlatformConfig[] = [
// Every regional site: nintendo.com/us/…, nintendo.co.uk, nintendo.de, // Every regional site: nintendo.com/us/…, nintendo.co.uk, nintendo.de,
// store.nintendo.co.uk, nintendo.co.jp … // store.nintendo.co.uk, nintendo.co.jp …
urlPattern: urlPattern:
/^https:\/\/(?:[a-z0-9-]+\.)*nintendo\.(?:com|co\.[a-z]{2}|com\.[a-z]{2}|[a-z]{2})\/[^\s]+$/i, /^https:\/\/(?:[a-z0-9-]+\.)*nintendo\.(?:com|co\.[a-z]{2}|com\.[a-z]{2}|[a-z]{2})\/\S+$/i,
}, },
{ {
id: "gog", id: "gog",
tagName: "GOG", tagName: "GOG",
label: "GOG", label: "GOG",
urlPrefix: "https://www.gog.com/game/", urlPrefix: "https://www.gog.com/game/",
urlPattern: /^https:\/\/(?:www\.)?gog\.com\/[^\s]+$/i, urlPattern: /^https:\/\/(?:www\.)?gog\.com\/\S+$/i,
}, },
{ {
id: "itchio", id: "itchio",
@@ -103,7 +103,7 @@ export const PLATFORMS: readonly PlatformConfig[] = [
tagName: "Humble Bundle", tagName: "Humble Bundle",
label: "Humble Bundle", label: "Humble Bundle",
urlPrefix: "https://www.humblebundle.com/store/", urlPrefix: "https://www.humblebundle.com/store/",
urlPattern: /^https:\/\/(?:www\.)?humblebundle\.com\/[^\s]+$/i, urlPattern: /^https:\/\/(?:www\.)?humblebundle\.com\/\S+$/i,
}, },
{ {
id: "amazon", id: "amazon",
@@ -111,21 +111,21 @@ export const PLATFORMS: readonly PlatformConfig[] = [
label: "Amazon Luna", label: "Amazon Luna",
urlPrefix: "https://luna.amazon.com/game/", urlPrefix: "https://luna.amazon.com/game/",
// Luna's own site, or the game's page on any Amazon storefront. // Luna's own site, or the game's page on any Amazon storefront.
urlPattern: /^https:\/\/(?:luna\.amazon\.com|(?:www\.)?amazon\.[a-z.]{2,6})\/[^\s]+$/i, urlPattern: /^https:\/\/(?:luna\.amazon\.com|(?:www\.)?amazon\.[a-z.]{2,6})\/\S+$/i,
}, },
{ {
id: "ea", id: "ea",
tagName: "EA app", tagName: "EA app",
label: "EA app", label: "EA app",
urlPrefix: "https://www.ea.com/games/", urlPrefix: "https://www.ea.com/games/",
urlPattern: /^https:\/\/(?:www\.)?ea\.com\/[^\s]+$/i, urlPattern: /^https:\/\/(?:www\.)?ea\.com\/\S+$/i,
}, },
{ {
id: "ubisoft", id: "ubisoft",
tagName: "Ubisoft Connect", tagName: "Ubisoft Connect",
label: "Ubisoft Store", label: "Ubisoft Store",
urlPrefix: "https://store.ubisoft.com/", urlPrefix: "https://store.ubisoft.com/",
urlPattern: /^https:\/\/(?:store\.ubisoft\.com|(?:www\.)?ubisoft\.com)\/[^\s]+$/i, urlPattern: /^https:\/\/(?:store\.ubisoft\.com|(?:www\.)?ubisoft\.com)\/\S+$/i,
}, },
{ {
id: "battlenet", id: "battlenet",
@@ -133,7 +133,7 @@ export const PLATFORMS: readonly PlatformConfig[] = [
label: "Battle.net", label: "Battle.net",
urlPrefix: "https://shop.battle.net/", urlPrefix: "https://shop.battle.net/",
// shop.battle.net and its regional hosts (us.shop.battle.net …). // shop.battle.net and its regional hosts (us.shop.battle.net …).
urlPattern: /^https:\/\/(?:[a-z0-9-]+\.)*battle\.net\/[^\s]+$/i, urlPattern: /^https:\/\/(?:[a-z0-9-]+\.)*battle\.net\/\S+$/i,
}, },
{ {
id: "googleplay", id: "googleplay",
@@ -151,7 +151,7 @@ export const PLATFORMS: readonly PlatformConfig[] = [
tagName: "iOS", tagName: "iOS",
label: "App Store", label: "App Store",
urlPrefix: "https://apps.apple.com/app/", urlPrefix: "https://apps.apple.com/app/",
urlPattern: /^https:\/\/apps\.apple\.com\/[^\s]+$/i, urlPattern: /^https:\/\/apps\.apple\.com\/\S+$/i,
}, },
{ {
id: "meta", id: "meta",
@@ -159,7 +159,7 @@ export const PLATFORMS: readonly PlatformConfig[] = [
label: "Meta Quest Store", label: "Meta Quest Store",
urlPrefix: "https://www.meta.com/experiences/", urlPrefix: "https://www.meta.com/experiences/",
// meta.com, and oculus.com links that still circulate. // meta.com, and oculus.com links that still circulate.
urlPattern: /^https:\/\/(?:www\.)?(?:meta|oculus)\.com\/[^\s]+$/i, urlPattern: /^https:\/\/(?:www\.)?(?:meta|oculus)\.com\/\S+$/i,
}, },
{ {
// Catch-all for indie / niche releases distributed only from a // Catch-all for indie / niche releases distributed only from a
@@ -170,6 +170,6 @@ export const PLATFORMS: readonly PlatformConfig[] = [
id: "publisher", id: "publisher",
label: "Publisher / Developer site", label: "Publisher / Developer site",
urlPrefix: "https://", urlPrefix: "https://",
urlPattern: /^https:\/\/[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+(?:\/[^\s]*)?$/i, urlPattern: /^https:\/\/[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+(?:\/\S*)?$/i,
}, },
] as const; ] as const;
+4 -4
View File
@@ -36,14 +36,14 @@ export const PLAYTEST_PLATFORMS: readonly PlaytestPlatformConfig[] = [
id: "steam", id: "steam",
label: "Steam Playtest", label: "Steam Playtest",
urlPrefix: "https://store.steampowered.com/app/", urlPrefix: "https://store.steampowered.com/app/",
urlPattern: /^https:\/\/store\.steampowered\.com\/app\/\d+(?:\/[^\s]*)?$/i, urlPattern: /^https:\/\/store\.steampowered\.com\/app\/\d+(?:\/\S*)?$/i,
maxInvites: 100, maxInvites: 100,
}, },
{ {
id: "epic", id: "epic",
label: "Epic Games Store", label: "Epic Games Store",
urlPrefix: "https://store.epicgames.com/", urlPrefix: "https://store.epicgames.com/",
urlPattern: /^https:\/\/store\.epicgames\.com\/[^\s]+$/i, urlPattern: /^https:\/\/store\.epicgames\.com\/\S+$/i,
maxInvites: 100, maxInvites: 100,
}, },
{ {
@@ -57,7 +57,7 @@ export const PLAYTEST_PLATFORMS: readonly PlaytestPlatformConfig[] = [
id: "discord", id: "discord",
label: "Discord / Community", label: "Discord / Community",
urlPrefix: "https://discord.gg/", urlPrefix: "https://discord.gg/",
urlPattern: /^https:\/\/(?:discord\.gg|discord\.com\/invite)\/[^\s]+$/i, urlPattern: /^https:\/\/(?:discord\.gg|discord\.com\/invite)\/\S+$/i,
maxInvites: 100, maxInvites: 100,
}, },
{ {
@@ -66,7 +66,7 @@ export const PLAYTEST_PLATFORMS: readonly PlaytestPlatformConfig[] = [
id: "other", id: "other",
label: "Other / Signup form", label: "Other / Signup form",
urlPrefix: "https://", urlPrefix: "https://",
urlPattern: /^https:\/\/[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+(?:\/[^\s]*)?$/i, urlPattern: /^https:\/\/[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+(?:\/\S*)?$/i,
maxInvites: 100, maxInvites: 100,
}, },
] as const; ] as const;
+1 -1
View File
@@ -694,7 +694,7 @@ export interface GeneratorInput {
* Video-style era opt-in (v0.22.0). When set to a non-empty era id, * Video-style era opt-in (v0.22.0). When set to a non-empty era id,
* the renderer emits a single "Edited in {era} style using {editor}" * the renderer emits a single "Edited in {era} style using {editor}"
* credit at the end of the Video Settings section. Combines with * credit at the end of the Video Settings section. Combines with
* {@link rig.video_editor}. Renders even when * the rig's `video_editor`. Renders even when
* {@link skipGraphicsSettings} is true. * {@link skipGraphicsSettings} is true.
*/ */
videoStyleEra?: string; videoStyleEra?: string;
+3 -1
View File
@@ -23,7 +23,9 @@ export const SUPPORTED_LANGUAGES = [
nativeName: string; nativeName: string;
}[]; }[];
i18n // `void`: nothing waits on init. `en` is bundled, so the first render already
// has its strings, and every other language loads on demand.
void i18n
.use(initReactI18next) .use(initReactI18next)
.use( .use(
// Vite statically analyses this template literal and emits one async // Vite statically analyses this template literal and emits one async
+6 -14
View File
@@ -11,6 +11,7 @@ import { extractData, useSettingsStore } from "@store/settings-store";
import { editorDataOf, useEditorStore, type EditorData } from "@store/editor-store"; import { editorDataOf, useEditorStore, type EditorData } from "@store/editor-store";
import type { SettingsData } from "@store/settings-heal"; import type { SettingsData } from "@store/settings-heal";
import { generateId } from "@utils/uuid"; import { generateId } from "@utils/uuid";
import { stableJson } from "@utils/stable-json";
import { PLATFORMS } from "@config/platforms"; import { PLATFORMS } from "@config/platforms";
import type { ParsedFile } from "./detect"; import type { ParsedFile } from "./detect";
import { SECTIONS, isListSection, type ListSection, type Section } from "./format"; import { SECTIONS, isListSection, type ListSection, type Section } from "./format";
@@ -78,22 +79,13 @@ export function readCurrentData(): CurrentData {
}; };
} }
/** JSON with sorted keys, so equal data compares equal whatever its key order. */
function stable(value: unknown): string {
return JSON.stringify(value, (_key, v: unknown) =>
v && typeof v === "object" && !Array.isArray(v)
? Object.fromEntries(
Object.entries(v as Record<string, unknown>).sort(([a], [b]) => (a < b ? -1 : 1)),
)
: v,
);
}
const BOOKKEEPING = new Set(["id", "createdAt", "updatedAt"]); const BOOKKEEPING = new Set(["id", "createdAt", "updatedAt"]);
/** The part of an item that matters when comparing: no id, no timestamps. */ /** The part of an item that matters when comparing: no id, no timestamps. */
function content(item: object): string { function content(item: object): string {
return stable(Object.fromEntries(Object.entries(item).filter(([key]) => !BOOKKEEPING.has(key)))); return stableJson(
Object.fromEntries(Object.entries(item).filter(([key]) => !BOOKKEEPING.has(key))),
);
} }
function changedAt(item: { createdAt: string; updatedAt?: string }): number { function changedAt(item: { createdAt: string; updatedAt?: string }): number {
@@ -191,13 +183,13 @@ export function planRestore(
if (clean.settings) { if (clean.settings) {
plan.settings = { plan.settings = {
incoming: clean.settings, incoming: clean.settings,
status: stable(clean.settings) === stable(current.settings) ? "same" : "changed", status: stableJson(clean.settings) === stableJson(current.settings) ? "same" : "changed",
}; };
} }
if (clean.draft) { if (clean.draft) {
plan.draft = { plan.draft = {
incoming: clean.draft, incoming: clean.draft,
status: stable(clean.draft) === stable(current.draft) ? "same" : "changed", status: stableJson(clean.draft) === stableJson(current.draft) ? "same" : "changed",
}; };
} }
return plan; return plan;
+4 -14
View File
@@ -7,6 +7,7 @@ import {
type EditorData, type EditorData,
} from "@store/editor-store"; } from "@store/editor-store";
import { useSettingsStore } from "@store/settings-store"; import { useSettingsStore } from "@store/settings-store";
import { stableJson } from "@utils/stable-json";
import type { Profile } from "@store/profile-store"; import type { Profile } from "@store/profile-store";
import type { GamePreset } from "@store/preset-store"; import type { GamePreset } from "@store/preset-store";
import type { EditorTemplate } from "@store/template-store"; import type { EditorTemplate } from "@store/template-store";
@@ -89,17 +90,6 @@ function isBlank(value: unknown): boolean {
return false; return false;
} }
/** JSON with sorted keys, so equal maps compare equal whatever their order. */
function stable(value: unknown): string {
return JSON.stringify(value, (_key, v: unknown) =>
v && typeof v === "object" && !Array.isArray(v)
? Object.fromEntries(
Object.entries(v as Record<string, unknown>).sort(([a], [b]) => (a < b ? -1 : 1)),
)
: v,
);
}
/** /**
* Fields a patch would overwrite that hold something else in the editor * Fields a patch would overwrite that hold something else in the editor
* right now — what "Replace N filled fields?" counts. Empty fields and * right now — what "Replace N filled fields?" counts. Empty fields and
@@ -113,8 +103,8 @@ export function overwrittenFields(editor: EditorData, patch: Partial<EditorData>
.filter( .filter(
([key, value]) => ([key, value]) =>
!isBlank(now[key]) && !isBlank(now[key]) &&
stable(now[key]) !== stable(blank[key]) && stableJson(now[key]) !== stableJson(blank[key]) &&
stable(now[key]) !== stable(value), stableJson(now[key]) !== stableJson(value),
) )
.map(([key]) => key); .map(([key]) => key);
} }
@@ -127,7 +117,7 @@ export function overwrittenFields(editor: EditorData, patch: Partial<EditorData>
export function changedSince(editor: EditorData, patch: Partial<EditorData>): string[] { export function changedSince(editor: EditorData, patch: Partial<EditorData>): string[] {
const now = editor as unknown as Record<string, unknown>; const now = editor as unknown as Record<string, unknown>;
return Object.entries(patch) return Object.entries(patch)
.filter(([key, value]) => stable(now[key] ?? "") !== stable(value ?? "")) .filter(([key, value]) => stableJson(now[key] ?? "") !== stableJson(value ?? ""))
.map(([key]) => key); .map(([key]) => key);
} }
+15
View File
@@ -0,0 +1,15 @@
/**
* JSON with every object's keys sorted, so equal data compares equal
* whatever order its keys were written in. Arrays keep their order.
* Used to compare library items (restore) and editor fields (applying a
* profile, preset or template).
*/
export function stableJson(value: unknown): string {
return JSON.stringify(value, (_key, v: unknown) =>
v && typeof v === "object" && !Array.isArray(v)
? Object.fromEntries(
Object.entries(v as Record<string, unknown>).sort(([a], [b]) => (a < b ? -1 : 1)),
)
: v,
);
}
+17
View File
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest";
import { stableJson } from "@utils/stable-json";
describe("stableJson", () => {
it("gives equal objects the same JSON whatever their key order", () => {
expect(stableJson({ b: 1, a: { d: [2, 1], c: null } })).toBe(
stableJson({ a: { c: null, d: [2, 1] }, b: 1 }),
);
expect(stableJson({ b: 1, a: 2 })).toBe('{"a":2,"b":1}');
});
it("keeps array order and tells different data apart", () => {
expect(stableJson([2, 1])).not.toBe(stableJson([1, 2]));
expect(stableJson({ a: 1 })).not.toBe(stableJson({ a: "1" }));
expect(stableJson("text")).toBe('"text"');
});
});
+14 -13
View File
@@ -6,6 +6,19 @@ import { cloudflareWebAnalytics, securityTxt } from "./build-plugins/web-only.ts
const isTauri = !!process.env.TAURI_ENV_PLATFORM; const isTauri = !!process.env.TAURI_ENV_PLATFORM;
/** Import aliases — the same as tsconfig.json's `paths`. vitest.config.ts reuses them. */
export const alias = {
"@": path.resolve(import.meta.dirname, "./src"),
"@config": path.resolve(import.meta.dirname, "./src/config"),
"@engine": path.resolve(import.meta.dirname, "./src/engine"),
"@store": path.resolve(import.meta.dirname, "./src/store"),
"@hooks": path.resolve(import.meta.dirname, "./src/hooks"),
"@components": path.resolve(import.meta.dirname, "./src/components"),
"@pages": path.resolve(import.meta.dirname, "./src/pages"),
"@utils": path.resolve(import.meta.dirname, "./src/utils"),
"@i18n": path.resolve(import.meta.dirname, "./src/i18n"),
};
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
react(), react(),
@@ -19,19 +32,7 @@ export default defineConfig({
// wrangler.jsonc) and the Tauri build from its own asset protocol. The old // wrangler.jsonc) and the Tauri build from its own asset protocol. The old
// GitHub Pages sub-path `/youtube-generator/` is gone as of v1.0.0. // GitHub Pages sub-path `/youtube-generator/` is gone as of v1.0.0.
base: "/", base: "/",
resolve: { resolve: { alias },
alias: {
"@": path.resolve(import.meta.dirname, "./src"),
"@config": path.resolve(import.meta.dirname, "./src/config"),
"@engine": path.resolve(import.meta.dirname, "./src/engine"),
"@store": path.resolve(import.meta.dirname, "./src/store"),
"@hooks": path.resolve(import.meta.dirname, "./src/hooks"),
"@components": path.resolve(import.meta.dirname, "./src/components"),
"@pages": path.resolve(import.meta.dirname, "./src/pages"),
"@utils": path.resolve(import.meta.dirname, "./src/utils"),
"@i18n": path.resolve(import.meta.dirname, "./src/i18n"),
},
},
server: { server: {
// `tauri dev` loads this server while cargo rewrites files under // `tauri dev` loads this server while cargo rewrites files under
// src-tauri/target, and watching those crashed Vite on Windows (EBUSY on // src-tauri/target, and watching those crashed Vite on Windows (EBUSY on
+3 -17
View File
@@ -1,23 +1,9 @@
import { defineConfig } from "vitest/config"; import { defineConfig } from "vitest/config";
// `import.meta.dirname` rather than `__dirname`: Vite 8's native config // The app's import aliases, defined once in vite.config.ts.
// loader (planned to become the default) does not provide the CJS global, import { alias } from "./vite.config.ts";
// and warns on every run until this changes.
import path from "path";
export default defineConfig({ export default defineConfig({
resolve: { resolve: { alias },
alias: {
"@": path.resolve(import.meta.dirname, "./src"),
"@config": path.resolve(import.meta.dirname, "./src/config"),
"@engine": path.resolve(import.meta.dirname, "./src/engine"),
"@store": path.resolve(import.meta.dirname, "./src/store"),
"@hooks": path.resolve(import.meta.dirname, "./src/hooks"),
"@components": path.resolve(import.meta.dirname, "./src/components"),
"@pages": path.resolve(import.meta.dirname, "./src/pages"),
"@utils": path.resolve(import.meta.dirname, "./src/utils"),
"@i18n": path.resolve(import.meta.dirname, "./src/i18n"),
},
},
test: { test: {
globals: true, globals: true,
// Node 25+ defines a global `localStorage` that is `undefined` unless // Node 25+ defines a global `localStorage` that is `undefined` unless