Skip to content

Commit 9d800b7

Browse files
authored
fix(scripts): route i18n formatter through pnpm runner (#95534)
1 parent 5ccfc97 commit 9d800b7

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

scripts/control-ui-i18n.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import * as ts from "typescript";
1010
import { formatErrorMessage } from "../src/infra/errors.ts";
1111
import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs";
1212

13+
const { formatGeneratedModule } = (await import(
14+
new URL("./lib/format-generated-module.mjs", import.meta.url).href
15+
)) as {
16+
formatGeneratedModule: (
17+
source: string,
18+
options: {
19+
errorLabel: string;
20+
outputPath: string;
21+
repoRoot: string;
22+
},
23+
) => string;
24+
};
25+
1326
interface TranslationMap {
1427
[key: string]: string | TranslationMap;
1528
}
@@ -1228,18 +1241,12 @@ export async function runProcess(
12281241
}
12291242

12301243
async function formatGeneratedTypeScript(filePath: string, source: string): Promise<string> {
1231-
const directFormatterPath = path.join(ROOT, "node_modules", ".bin", "oxfmt");
1232-
const formatterCommand =
1233-
process.platform !== "win32" && existsSync(directFormatterPath) ? directFormatterPath : "pnpm";
1234-
const formatterArgs =
1235-
formatterCommand === directFormatterPath
1236-
? ["--stdin-filepath", path.relative(ROOT, filePath)]
1237-
: ["exec", "oxfmt", "--stdin-filepath", path.relative(ROOT, filePath)];
1238-
const result = await runProcess(formatterCommand, formatterArgs, {
1239-
input: source,
1240-
rejectOnFailure: true,
1244+
const formatted = formatGeneratedModule(source, {
1245+
errorLabel: "control ui locale",
1246+
outputPath: filePath,
1247+
repoRoot: ROOT,
12411248
});
1242-
return restoreReplacementCorruptedStringLiterals(source, result.stdout);
1249+
return restoreReplacementCorruptedStringLiterals(source, formatted);
12431250
}
12441251

12451252
function restoreReplacementCorruptedStringLiterals(source: string, formatted: string): string {

0 commit comments

Comments
 (0)