sync local pi changes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { FormatterConfig } from "../schema.ts";
|
||||
|
||||
export function createCommandFormatterRunner(deps: {
|
||||
execCommand: (
|
||||
command: string,
|
||||
args: string[],
|
||||
options: { cwd: string; timeout?: number },
|
||||
) => Promise<{ code: number; stdout: string; stderr: string }>;
|
||||
}) {
|
||||
return {
|
||||
async formatFile(input: {
|
||||
absolutePath: string;
|
||||
workspaceRoot: string;
|
||||
formatter: FormatterConfig;
|
||||
timeoutMs?: number;
|
||||
}) {
|
||||
const [command, ...args] = input.formatter.command.map((part) => part.replaceAll("{file}", input.absolutePath));
|
||||
const result = await deps.execCommand(command, args, {
|
||||
cwd: input.workspaceRoot,
|
||||
timeout: input.timeoutMs,
|
||||
});
|
||||
|
||||
if (result.code !== 0) {
|
||||
return {
|
||||
status: "failed" as const,
|
||||
message: (result.stderr || result.stdout || `formatter exited with ${result.code}`).trim(),
|
||||
};
|
||||
}
|
||||
|
||||
return { status: "formatted" as const };
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user