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

main
ts 32 lines 1.54 KB
Raw
1 import { describe, expect, it } from "@alchemy.run/test";
2 import * as Effect from "effect/Effect";
3 import * as FileSystem from "effect/FileSystem";
4 import * as Path from "effect/Path";
5 import { transformSync } from "rolldown/utils";
6 import { PlatformServices } from "@/Util/PlatformServices.ts";
7
8 // React is only a devDependency (#1636), so a CLI module that compiles to a
9 // runtime `react` import crashes in consumer projects. A JSX pragma counts
10 // only in the file's leading comments; anywhere else the package's
11 // `jsx: react-jsx` falls back to `react/jsx-runtime`.
12 describe("CLI JSX runtime", { tags: ["unit", "local"] }, () => {
13 it.effect("no CLI module imports react at runtime", () =>
14 Effect.gen(function* () {
15 const fs = yield* FileSystem.FileSystem;
16 const path = yield* Path.Path;
17 const cli = yield* path.fromFileUrl(new URL("../../src/Cli/", import.meta.url));
18 const files = (yield* fs.readDirectory(cli, { recursive: true })).filter((file) =>
19 file.endsWith(".tsx"),
20 );
21 const offenders: string[] = [];
22 for (const file of files) {
23 const source = yield* fs.readFileString(path.join(cli, file));
24 // The package compiles with `jsx: react-jsx`: automatic runtime, react source.
25 const { code } = transformSync(file, source, { jsx: { runtime: "automatic" } });
26 if (/from\s+["']react(\/[^"']*)?["']/.test(code)) offenders.push(file);
27 }
28 expect(files.length).toBeGreaterThan(0);
29 expect(offenders).toEqual([]);
30 }).pipe(Effect.provide(PlatformServices)),
31 );
32 });