@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 06:00 UTC

main
ts 110 lines 3.72 KB
Raw
1 import * as Nextjs from "@alchemy.run/frontend-frameworks/nextjs/neon";
2 import * as Vocs from "@alchemy.run/frontend-frameworks/vocs/neon";
3 import { expect } from "@alchemy.run/test";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as Path from "effect/Path";
8 import * as Schedule from "effect/Schedule";
9 import { functionTextSamples } from "../FunctionRollout.ts";
10
11 const buildDirectories = new Set([
12 "node_modules",
13 "dist",
14 "build",
15 "serve-neon.mjs",
16 "neon-node-adapter.mjs",
17 ".alchemy",
18 ".next",
19 ".nuxt",
20 ".output",
21 ".svelte-kit",
22 ".astro",
23 ".vite",
24 ".vinxi",
25 ".nitro",
26 ".cache",
27 ".turbo",
28 ".vercel",
29 "tsconfig.tsbuildinfo",
30 ]);
31
32 /** Isolate mutable sources and build output while reusing installed dependencies. */
33 export const exampleRoot = Effect.fn(function* (slug: string) {
34 const fs = yield* FileSystem.FileSystem;
35 const path = yield* Path.Path;
36 const source = yield* path.fromFileUrl(
37 new URL(`../../../../../examples/neon-website-${slug}/`, import.meta.url),
38 );
39 // Keep relative tsconfig paths and avoid ignored roots that confuse Tailwind's scanner:
40 // a git-ignored copy makes Tailwind's source scan spin and the Vite build hang,
41 // so these copies must never be gitignored.
42 const directory = path.dirname(source);
43 yield* fs.makeDirectory(directory, { recursive: true });
44 const root = yield* fs.makeTempDirectoryScoped({
45 directory,
46 prefix: `neon-website-${slug}-`,
47 });
48 for (const name of yield* fs.readDirectory(source)) {
49 if (!buildDirectories.has(name) && !name.startsWith(".env") && name !== ".npmrc") {
50 yield* fs.copy(path.join(source, name), path.join(root, name));
51 }
52 }
53 const installed = path.join(source, "node_modules");
54 const dependencies = path.join(root, "node_modules");
55 yield* fs.makeDirectory(dependencies);
56 for (const name of yield* fs.readDirectory(installed)) {
57 if (name.startsWith(".") && name !== ".bin") continue;
58 if (name.startsWith("@")) {
59 yield* fs.makeDirectory(path.join(dependencies, name));
60 for (const pkg of yield* fs.readDirectory(path.join(installed, name))) {
61 yield* fs.symlink(
62 yield* fs.realPath(path.join(installed, name, pkg)),
63 path.join(dependencies, name, pkg),
64 );
65 }
66 } else {
67 yield* fs.symlink(
68 yield* fs.realPath(path.join(installed, name)),
69 path.join(dependencies, name),
70 );
71 }
72 }
73 return root;
74 });
75
76 export const buildPortableExample = Effect.fn(function* (
77 slug: "nextjs" | "vocs",
78 existingRoot?: string,
79 ) {
80 const path = yield* Path.Path;
81 const root = existingRoot ?? (yield* exampleRoot(slug));
82 const target = slug === "nextjs" ? Nextjs.target() : Vocs.target();
83 const output = yield* target.build({ root, framework: slug });
84 expect(output.distDirectory).toBeDefined();
85 expect(output.serverModules?.[0]).toBeDefined();
86 return {
87 root,
88 distDir: output.distDirectory!,
89 serverEntry: path.join(output.distDirectory!, output.serverModules![0]!.name),
90 layout: slug === "nextjs" ? ("next" as const) : ("output" as const),
91 };
92 });
93
94 export const bodyContaining = Effect.fn(function* (url: string, text: string) {
95 const body = yield* HttpClient.get(url).pipe(
96 Effect.flatMap((response) => response.text),
97 Effect.repeat({
98 schedule: Schedule.spaced("1 second"),
99 times: 8,
100 until: (body) => body.includes(text),
101 }),
102 );
103 expect(body).toContain(text);
104 return body;
105 });
106
107 export const updatedBodyContaining = Effect.fn(function* (url: string, text: string) {
108 const samples = yield* functionTextSamples(url, (body) => body.includes(text));
109 for (const body of samples) expect(body).toContain(text);
110 });