The best way to control Claude Code, Codex and more from any computer or phone
| 1 | // Loader hook for published installs under Node. |
| 2 | // |
| 3 | // Beyond transpiling, the hook resolves the way tsx does: tsconfig `paths`, |
| 4 | // `.js` imports that mean `.ts` source, extensionless and directory imports, |
| 5 | // JSON without import attributes, and `require()` of TypeScript from `.cts`. |
| 6 | // |
| 7 | // Every alchemy Node process runs this file first: the `alchemy` CLI |
| 8 | // imports it before its entry (bin/cli.js), and the dev exec child, the |
| 9 | // local-provider sidecar and dev-server runners are started with `--import` |
| 10 | // of it. Alchemy itself and all of its dependencies run their built |
| 11 | // JavaScript; the hook exists so the USER's `.ts`/`.tsx` (the stack |
| 12 | // entrypoint and everything it imports from the project) transpiles through |
| 13 | // Oxc. Alchemy never relies on Node's built-in TypeScript support: it is |
| 14 | // strip-only (no parameter properties, enums, or TSX), and the transform |
| 15 | // flag that covered some of that was removed in Node 26. |
| 16 | // |
| 17 | // Anything under `node_modules` is left to Node, matching Node's own refusal |
| 18 | // to type-strip installed packages: a dependency is expected to ship |
| 19 | // JavaScript. |
| 20 | // |
| 21 | // Checkout runs use `register-dev-mode.js` instead, which installs the same |
| 22 | // loader without the filter (alchemy's own source is TypeScript there) and |
| 23 | // additionally resolves workspace packages onto their `src/`. |
| 24 | import { enableCompileCache, registerHooks } from "node:module"; |
| 25 | |
| 26 | // Node's module compile cache: V8 code cache persisted across processes, |
| 27 | // keyed by compiled source, so the loader's transformed TypeScript benefits |
| 28 | // too. Enabled before the loader is imported so the loader's own dependency |
| 29 | // graph (rolldown) is covered. Honours `NODE_COMPILE_CACHE` (directory) and |
| 30 | // `NODE_DISABLE_COMPILE_CACHE`; defaults to Node's per-user temp directory. |
| 31 | // The loader flushes it after lazy imports settle (see node-utils loader/hooks.ts). |
| 32 | enableCompileCache(); |
| 33 | |
| 34 | // distilled's lazy service stubs: with the `distilled-lazy` export condition |
| 35 | // a service module resolves to a stub that loads each operation on first |
| 36 | // use, so importing whole providers (as a stack does) costs a fraction of |
| 37 | // the heap. Opt-in: `alchemy --fast-distilled` (bin/cli.js turns the flag |
| 38 | // into `ALCHEMY_FAST_DISTILLED=1`, which child processes inherit), or the |
| 39 | // env var directly. Bundles never see the condition: a stub `require`s its |
| 40 | // full module at runtime, which no bundle contains. Installed before |
| 41 | // anything imports a provider. |
| 42 | if (process.env.ALCHEMY_FAST_DISTILLED === "1") { |
| 43 | registerHooks({ |
| 44 | resolve(specifier, context, nextResolve) { |
| 45 | if (!specifier.startsWith("@distilled.cloud/")) return nextResolve(specifier, context); |
| 46 | return nextResolve(specifier, { |
| 47 | ...context, |
| 48 | conditions: [...context.conditions, "distilled-lazy"], |
| 49 | }); |
| 50 | }, |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | const { registerOxc } = await import("@alchemy.run/node-utils/register-oxc"); |
| 55 | |
| 56 | registerOxc({ |
| 57 | filter: (path) => !/[\\/]node_modules[\\/]/.test(path), |
| 58 | }); |