The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import * as NodeModule from "node:module"; |
| 2 | |
| 3 | // Vite forwards explicit modes to tasks; clear our inherited default even on older Node. |
| 4 | if ( |
| 5 | process.env.VP_T3_TASK_CACHE_MODE && |
| 6 | process.env.VP_REMOTE_CACHE === process.env.VP_T3_TASK_CACHE_MODE |
| 7 | ) |
| 8 | delete process.env.VP_REMOTE_CACHE; |
| 9 | |
| 10 | // Older Node processes in unrelated projects must remain unaffected by machine setup. |
| 11 | if ( |
| 12 | typeof NodeModule.registerHooks === "function" && |
| 13 | Number(process.versions.node.split(".")[0]) >= 24 |
| 14 | ) { |
| 15 | try { |
| 16 | const { patchNativeCli } = await import("./nativeHook.js"); |
| 17 | const hookUrl = new URL("./nativeRunHook.js", import.meta.url).href; |
| 18 | NodeModule.registerHooks({ |
| 19 | load(url, context, nextLoad) { |
| 20 | const loaded = nextLoad(url, context); |
| 21 | if (!url.endsWith("/vite-plus/dist/bin.js")) return loaded; |
| 22 | try { |
| 23 | const source = |
| 24 | typeof loaded.source === "string" |
| 25 | ? loaded.source |
| 26 | : Buffer.from(loaded.source).toString(); |
| 27 | return { |
| 28 | ...loaded, |
| 29 | source: patchNativeCli(source).replace( |
| 30 | 'from "./run-hook.js"', |
| 31 | `from ${JSON.stringify(hookUrl)}`, |
| 32 | ), |
| 33 | }; |
| 34 | } catch { |
| 35 | return loaded; |
| 36 | } |
| 37 | }, |
| 38 | }); |
| 39 | } catch { |
| 40 | // Restricted Node processes must still run when the optional hook cannot load. |
| 41 | } |
| 42 | } |