


























@@ -1,6 +1,7 @@
11import { spawnSync } from "node:child_process";
22import fs from "node:fs/promises";
33import path from "node:path";
4+import { resolvePnpmRunner } from "../pnpm-runner.mjs";
4556const PROTOCOL_SCHEMA_RELATIVE_PATH = "codex-rs/app-server-protocol/schema";
67@@ -23,6 +24,47 @@ export type GeneratedCodexAppServerProtocolSource = {
2324cleanup: () => Promise<void>;
2425};
252627+type PnpmCommand = {
28+args: string[];
29+command: string;
30+env?: NodeJS.ProcessEnv;
31+shell: boolean;
32+windowsVerbatimArguments?: boolean;
33+};
34+35+type ResolvePnpmCommandOptions = {
36+comSpec?: string;
37+env?: NodeJS.ProcessEnv;
38+execPath?: string;
39+npmExecPath?: string;
40+platform?: NodeJS.Platform;
41+};
42+43+function resolveEnvValue(env: NodeJS.ProcessEnv, name: string): string | undefined {
44+const key = Object.keys(env).find((candidate) => candidate.toLowerCase() === name.toLowerCase());
45+return key === undefined ? undefined : env[key];
46+}
47+48+export function resolveCodexProtocolPnpmCommand(
49+args: string[],
50+options: ResolvePnpmCommandOptions = {},
51+): PnpmCommand {
52+const env = options.env ?? process.env;
53+const command = resolvePnpmRunner({
54+comSpec: options.comSpec ?? resolveEnvValue(env, "ComSpec"),
55+npmExecPath: options.npmExecPath ?? env.npm_execpath,
56+nodeExecPath: options.execPath ?? process.execPath,
57+platform: options.platform,
58+pnpmArgs: args,
59+});
60+if (command.env === undefined) {
61+const invocation = { ...command };
62+delete invocation.env;
63+return invocation;
64+}
65+return command;
66+}
67+2668export async function resolveCodexAppServerProtocolSource(repoRoot: string): Promise<{
2769codexRepo: string;
2870sourceRoot: string;
@@ -159,9 +201,19 @@ function runCargoProtocolGenerator(codexRepo: string, args: string[]): void {
159201}
160202161203function formatGeneratedTypeScript(repoRoot: string, root: string): void {
162-const result = spawnSync("pnpm", ["exec", "oxfmt", "--write", "--threads=1", root], {
204+const command = resolveCodexProtocolPnpmCommand([
205+"exec",
206+"oxfmt",
207+"--write",
208+"--threads=1",
209+root,
210+]);
211+const result = spawnSync(command.command, command.args, {
163212cwd: repoRoot,
213+env: command.env ?? process.env,
214+shell: command.shell,
164215stdio: "inherit",
216+windowsVerbatimArguments: command.windowsVerbatimArguments,
165217});
166218if (result.status !== 0) {
167219throw new Error(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。