The best way to control Claude Code, Codex and more from any computer or phone

main
ts 71 lines 2.78 KB
Raw
1 import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import { nodeFileTrace } from "@vercel/nft";
4 import * as Data from "effect/Data";
5 import * as Effect from "effect/Effect";
6 import * as FileSystem from "effect/FileSystem";
7 import * as Path from "effect/Path";
8 import type { TraceInput } from "./Trace.ts";
9
10 export class TraceRunnerInvalidProps extends Data.TaggedError("TraceRunnerInvalidProps")<{
11 readonly message: string;
12 readonly cause?: unknown;
13 }> {}
14
15 NodeRuntime.runMain(
16 Effect.gen(function* () {
17 const fs = yield* FileSystem.FileSystem;
18 const path = yield* Path.Path;
19 const inputPath = process.argv[2];
20 const outputPath = process.argv[3];
21 if (!inputPath || !outputPath)
22 return yield* new TraceRunnerInvalidProps({ message: "Missing dependency trace paths" });
23 const source = yield* fs.readFileString(inputPath);
24 const input = yield* Effect.try(() => JSON.parse(source) as TraceInput);
25 const trace = (seeds: string[], emitGlobs: boolean) =>
26 Effect.tryPromise(() =>
27 nodeFileTrace(seeds, {
28 base: input.base,
29 processCwd: input.root,
30 conditions: ["node", "production"],
31 // Next's manifests already trace its runtime without dev bundlers.
32 ignore: input.next
33 ? (file) => file.replaceAll("\\", "/").includes("/node_modules/next/")
34 : undefined,
35 analysis: {
36 emitGlobs,
37 computeFileReferences: true,
38 evaluatePureExpressions: true,
39 },
40 }),
41 );
42 const result = yield* trace(input.seeds, true);
43 const stateFiles = [...result.fileList].filter((file) =>
44 file.split(/[\\/]/).includes(".alchemy"),
45 );
46 if (stateFiles.length > 0) {
47 // NFT's asset globs can sweep up unrelated build/state directories.
48 // Trace without globs to retain explicit state dependencies: packaging
49 // must still reject those, including references through symlinks.
50 // Include modules discovered by a wildcard import too: their explicit
51 // references to state must not disappear with the wildcard expansion.
52 const explicit = yield* trace(
53 [
54 ...new Set([
55 ...input.seeds,
56 ...[...result.fileList]
57 .filter(
58 (file) => /\.[cm]?[jt]sx?$/.test(file) && !file.split(/[\\/]/).includes(".alchemy"),
59 )
60 .map((file) => path.resolve(input.base, file)),
61 ]),
62 ],
63 false,
64 );
65 for (const file of stateFiles) {
66 if (!explicit.fileList.has(file)) result.fileList.delete(file);
67 }
68 }
69 yield* fs.writeFileString(outputPath, JSON.stringify([...result.fileList]));
70 }).pipe(Effect.provide(NodeServices.layer)),
71 );