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/`.
24import { enableCompileCache } 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 register-oxc.ts).
32enableCompileCache();
33
34const { registerOxc } = await import("@alchemy.run/node-utils/register-oxc");
35
36registerOxc({
37 filter: (path) => !/[\\/]node_modules[\\/]/.test(path),
38});