@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, 04:45 UTC

main
ts 68 lines 2.61 KB
Raw
1 import { expect, layer } from "@alchemy.run/test";
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import * as Bundle from "alchemy/Bundle/Bundle";
4 import * as Effect from "effect/Effect";
5 import {
6 isolatedProject,
7 materializeIsolatedProject,
8 removeIsolatedProject,
9 } from "../IsolatedProject.ts";
10
11 /** Bare (non-relative, non-builtin) `import` statements left in the chunks. */
12 const bareImports = (result: Bundle.BundleOutput) =>
13 result.files
14 .filter((file) => typeof file.content === "string")
15 .flatMap((file) => (file.content as string).split("\n"))
16 .filter((line) => /^import\b/.test(line))
17 .filter((line) => !/["'](\.\/|node:)/.test(line));
18
19 /** Each provider package's generated-entry bootstrap, and the package that ships it. */
20 const BOOTSTRAPS = [
21 ["@alchemy.run/fly", "@alchemy.run/fly/Bootstrap"],
22 ["@alchemy.run/hetzner", "@alchemy.run/hetzner/Bootstrap"],
23 ["@alchemy.run/prisma", "@alchemy.run/prisma/Bootstrap"],
24 ["@alchemy.run/railway", "@alchemy.run/railway/Bootstrap"],
25 ] as const;
26
27 layer(NodeServices.layer)("provider package bootstraps", (it) => {
28 // The contract the generated entries rely on, for bootstraps that ship in a
29 // provider package: a consumer project with only `alchemy` and that package
30 // installed (bun's isolated linker / pnpm) must be able to bundle it, with
31 // the package's own dependencies resolving from its location.
32 for (const [pkg, specifier] of BOOTSTRAPS) {
33 it.effect(
34 `${specifier} bundles from an isolated project`,
35 () =>
36 Effect.gen(function* () {
37 const name = pkg.replace("@alchemy.run/", "");
38 const project = isolatedProject(`bootstrap-${name}`, import.meta.filename, [pkg]);
39 yield* materializeIsolatedProject(project);
40 const virtualEntryPlugin = yield* Bundle.virtualEntryPlugin;
41 try {
42 const result = yield* Bundle.build(
43 {
44 cwd: project.dir,
45 input: project.main,
46 platform: "node",
47 external: ["bun", "bun:*"],
48 resolve: { conditionNames: [...Bundle.BUN_CONDITION_NAMES] },
49 plugins: [
50 virtualEntryPlugin(
51 () => `
52 import * as bootstrap from ${JSON.stringify(specifier)};
53 export default bootstrap;
54 `,
55 ),
56 ],
57 },
58 { format: "esm" },
59 );
60 expect(bareImports(result)).toEqual([]);
61 } finally {
62 yield* removeIsolatedProject(project);
63 }
64 }),
65 { tags: ["unit", "local"], timeout: 120_000 },
66 );
67 }
68 });