From 0c3e743a3e9c340b786df76a07908893742d464a Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Fri, 19 Dec 2025 04:32:28 +0000 Subject: [PATCH] refactor(oxfmt): Restore accidentally removed TS types (#17098) If we pass the wrong argument, the test will just fail, but well, type safety is a good. --- apps/oxfmt/src-js/cli/worker-proxy.ts | 9 ++++++-- apps/oxfmt/src-js/libs/prettier.ts | 30 +++++++++++++++++---------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/oxfmt/src-js/cli/worker-proxy.ts b/apps/oxfmt/src-js/cli/worker-proxy.ts index ce7d0d4935026..4f84ad3aaa09d 100644 --- a/apps/oxfmt/src-js/cli/worker-proxy.ts +++ b/apps/oxfmt/src-js/cli/worker-proxy.ts @@ -1,5 +1,6 @@ import Tinypool from "tinypool"; import { resolvePlugins } from "../libs/prettier"; +import type { FormatEmbeddedCodeParam, FormatFileParam } from "../libs/prettier"; import type { Options } from "prettier"; // Worker pool for parallel Prettier formatting @@ -20,7 +21,9 @@ export async function formatEmbeddedCode( tagName: string, code: string, ): Promise { - return pool!.run({ options, code, tagName }, { name: "formatEmbeddedCode" }); + return pool!.run({ options, code, tagName } satisfies FormatEmbeddedCodeParam, { + name: "formatEmbeddedCode", + }); } export async function formatFile( @@ -29,5 +32,7 @@ export async function formatFile( fileName: string, code: string, ): Promise { - return pool!.run({ options, code, fileName, parserName }, { name: "formatFile" }); + return pool!.run({ options, code, fileName, parserName } satisfies FormatFileParam, { + name: "formatFile", + }); } diff --git a/apps/oxfmt/src-js/libs/prettier.ts b/apps/oxfmt/src-js/libs/prettier.ts index 40f7747565140..0312d725fa2cd 100644 --- a/apps/oxfmt/src-js/libs/prettier.ts +++ b/apps/oxfmt/src-js/libs/prettier.ts @@ -19,6 +19,8 @@ export async function resolvePlugins(): Promise { return []; } +// --- + const TAG_TO_PARSER: Record = { // CSS css: "css", @@ -33,6 +35,12 @@ const TAG_TO_PARSER: Record = { markdown: "markdown", }; +export type FormatEmbeddedCodeParam = { + code: string; + tagName: string; + options: Options; +}; + /** * Format xxx-in-js code snippets * @@ -44,11 +52,7 @@ export async function formatEmbeddedCode({ code, tagName, options, -}: { - code: string; - tagName: string; - options: Options; -}): Promise { +}: FormatEmbeddedCodeParam): Promise { // TODO: This should be resolved in Rust side const parserName = TAG_TO_PARSER[tagName]; @@ -67,6 +71,15 @@ export async function formatEmbeddedCode({ .catch(() => code); } +// --- + +export type FormatFileParam = { + code: string; + parserName: string; + fileName: string; + options: Options; +}; + /** * Format non-js file * @@ -77,12 +90,7 @@ export async function formatFile({ parserName, fileName, options, -}: { - code: string; - parserName: string; - fileName: string; - options: Options; -}): Promise { +}: FormatFileParam): Promise { if (!prettierCache) { prettierCache = await import("prettier"); }