
























@@ -2,29 +2,52 @@ import { spawnSync } from "node:child_process";
22import fs from "node:fs";
33import os from "node:os";
44import path from "node:path";
5+import { resolvePnpmRunner } from "../pnpm-runner.mjs";
6+7+export function resolveGeneratedModuleFormatter(params) {
8+const platform = params.platform ?? process.platform;
9+const existsSync = params.existsSync ?? fs.existsSync;
10+const directFormatterPath = path.join(params.repoRoot, "node_modules", ".bin", "oxfmt");
11+const useDirectFormatter = platform !== "win32" && existsSync(directFormatterPath);
12+if (useDirectFormatter) {
13+return {
14+command: directFormatterPath,
15+args: ["--write", params.outputPath],
16+shell: false,
17+};
18+}
19+20+return resolvePnpmRunner({
21+comSpec: params.comSpec,
22+npmExecPath: params.npmExecPath,
23+nodeExecPath: params.nodeExecPath,
24+ platform,
25+pnpmArgs: ["exec", "oxfmt", "--write", params.outputPath],
26+});
27+}
528629export function formatGeneratedModule(source, { repoRoot, outputPath, errorLabel }) {
730const resolvedRepoRoot = path.resolve(repoRoot);
831const resolvedOutputPath = path.resolve(
932resolvedRepoRoot,
1033path.isAbsolute(outputPath) ? path.relative(resolvedRepoRoot, outputPath) : outputPath,
1134);
12-const directFormatterPath = path.join(resolvedRepoRoot, "node_modules", ".bin", "oxfmt");
13-const useDirectFormatter = process.platform !== "win32" && fs.existsSync(directFormatterPath);
14-const command = useDirectFormatter ? directFormatterPath : "pnpm";
1535const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-generated-format-"));
1636const tempOutputPath = path.join(tempDir, path.basename(resolvedOutputPath));
17371838try {
1939fs.writeFileSync(tempOutputPath, source, "utf8");
20-const args = useDirectFormatter
21- ? ["--write", tempOutputPath]
22- : ["exec", "oxfmt", "--write", tempOutputPath];
23-const formatter = spawnSync(command, args, {
40+const command = resolveGeneratedModuleFormatter({
41+existsSync: fs.existsSync,
42+outputPath: tempOutputPath,
43+repoRoot: resolvedRepoRoot,
44+});
45+const formatter = spawnSync(command.command, command.args, {
2446cwd: resolvedRepoRoot,
2547encoding: "utf8",
26-// Windows requires a shell to launch package-manager shim scripts reliably.
27- ...(process.platform === "win32" ? { shell: true } : {}),
48+env: command.env ?? process.env,
49+shell: command.shell,
50+windowsVerbatimArguments: command.windowsVerbatimArguments,
2851});
2952if (formatter.status !== 0) {
3053const details =
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。