The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** @param {string} source */ |
| 2 | export function patchNativeCli(source) { |
| 3 | if (source.includes('import { startRunHook } from "./run-hook.js";')) return source; |
| 4 | const start = "\tconst exitCode = await run({"; |
| 5 | const end = "\t\targs: rustCliArgs\n\t});"; |
| 6 | if (source.split(start).length !== 2 || source.split(end).length !== 2) |
| 7 | throw new Error("Unsupported Vite+ entrypoint; no files were changed."); |
| 8 | return ( |
| 9 | 'import { startRunHook } from "./run-hook.js";\n' + |
| 10 | source |
| 11 | .replace( |
| 12 | start, |
| 13 | '\tconst finishRunHook = await startRunHook(command, process.cwd(), async () => (await (await import("../binding/index.js")).detectWorkspace(process.cwd())).root);\n\tif (finishRunHook?.remoteCache && !rustCliArgs.includes("--last-details") && !rustCliArgs.some((arg) => arg === "--remote-cache" || arg.startsWith("--remote-cache="))) { rustCliArgs.splice(1, 0, "--remote-cache", finishRunHook.remoteCache); process.env.VP_T3_TASK_CACHE_MODE = finishRunHook.remoteCache; }\n\tlet exitCode;\n\ttry {\n\texitCode = await run({', |
| 14 | ) |
| 15 | .replace(end, end + "\n\t} finally {\n\t\tawait finishRunHook?.();\n\t}") |
| 16 | ); |
| 17 | } |