From 1840611fe67ea0b3a41c8ed72006482727c48892 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 5 Apr 2026 13:02:10 +0100 Subject: [PATCH] fix(ui): make locale generation formatter-stable --- scripts/control-ui-i18n.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/control-ui-i18n.ts b/scripts/control-ui-i18n.ts index 31c962eccc9..01106b6f05c 100644 --- a/scripts/control-ui-i18n.ts +++ b/scripts/control-ui-i18n.ts @@ -513,6 +513,7 @@ async function resolvePiCommand(): Promise { type RunProcessOptions = { cwd?: string; + input?: string; rejectOnFailure?: boolean; }; @@ -525,7 +526,7 @@ async function runProcess( const child = spawn(executable, args, { cwd: options.cwd ?? ROOT, env: process.env, - stdio: ["ignore", "pipe", "pipe"], + stdio: ["pipe", "pipe", "pipe"], }); let stdout = ""; @@ -537,6 +538,11 @@ async function runProcess( stderr += String(chunk); }); child.once("error", reject); + if (options.input !== undefined) { + child.stdin.end(options.input); + } else { + child.stdin.end(); + } child.once("close", (code) => { if ((code ?? 1) !== 0 && options.rejectOnFailure) { reject( @@ -549,6 +555,18 @@ async function runProcess( }); } +async function formatGeneratedTypeScript(filePath: string, source: string): Promise { + const result = await runProcess( + "pnpm", + ["exec", "oxfmt", "--stdin-filepath", path.relative(ROOT, filePath)], + { + input: source, + rejectOnFailure: true, + }, + ); + return result.stdout; +} + type PendingPrompt = { id: string; reject: (reason?: unknown) => void; @@ -956,7 +974,10 @@ async function syncLocale( workflow: CONTROL_UI_I18N_WORKFLOW, }; - const expectedLocale = renderLocaleModule(entry, nextMap); + const expectedLocale = await formatGeneratedTypeScript( + existingPath, + renderLocaleModule(entry, nextMap), + ); const expectedMeta = renderMeta(nextMeta); const expectedGlossary = renderGlossary(glossary.length === 0 ? DEFAULT_GLOSSARY : glossary); const expectedTm = renderTranslationMemory(tm);