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
| 1 | import * as NodeServices from "@effect/platform-node/NodeServices" |
| 2 | import * as Codegen from "@effect/utils/Codegen" |
| 3 | import * as Glob from "@effect/utils/Glob" |
| 4 | import { assert, describe, it } from "@effect/vitest" |
| 5 | import * as Effect from "effect/Effect" |
| 6 | import * as FileSystem from "effect/FileSystem" |
| 7 | import * as Layer from "effect/Layer" |
| 8 | import * as path from "node:path" |
| 9 | |
| 10 | const MainLayer = Codegen.layer.pipe(Layer.provide(Glob.layer), Layer.provideMerge(NodeServices.layer)) |
| 11 | |
| 12 | describe("BarrelGenerator", () => { |
| 13 | it.effect("discovers a barrel from an absolute pattern", () => |
| 14 | Effect.gen(function*() { |
| 15 | const fs = yield* FileSystem.FileSystem |
| 16 | const directory = yield* fs.makeTempDirectoryScoped({ prefix: "codegen-" }) |
| 17 | const barrel = path.join(directory, "index.ts") |
| 18 | yield* fs.writeFileString(barrel, "// @barrel\n") |
| 19 | |
| 20 | const generator = yield* Codegen.BarrelGenerator |
| 21 | const files = yield* generator.discoverFiles(barrel, directory) |
| 22 | |
| 23 | assert.deepStrictEqual(files, [{ path: barrel, pattern: "*.ts", offset: 1 }]) |
| 24 | }).pipe(Effect.provide(MainLayer))) |
| 25 | |
| 26 | it.effect("excludes modules with a parenthesized barrel glob", () => |
| 27 | Effect.gen(function*() { |
| 28 | const fs = yield* FileSystem.FileSystem |
| 29 | const directory = yield* fs.makeTempDirectoryScoped({ prefix: "codegen-" }) |
| 30 | const barrel = path.join(directory, "index.ts") |
| 31 | yield* fs.writeFileString(barrel, "// @barrel(!(MigratorFileSystem).ts)\n") |
| 32 | for (const module of ["Migrator", "MigratorFileSystem"]) { |
| 33 | yield* fs.writeFileString(path.join(directory, `${module}.ts`), "/**\n * @since 4.0.0\n */\n") |
| 34 | } |
| 35 | |
| 36 | const generator = yield* Codegen.BarrelGenerator |
| 37 | const files = yield* generator.discoverFiles(barrel, directory) |
| 38 | yield* Effect.forEach(files, generator.processFile) |
| 39 | |
| 40 | assert.strictEqual( |
| 41 | yield* fs.readFileString(barrel), |
| 42 | `// @barrel(!(MigratorFileSystem).ts) |
| 43 | |
| 44 | /** |
| 45 | * @since 4.0.0 |
| 46 | */ |
| 47 | export * as Migrator from "./Migrator.ts" |
| 48 | ` |
| 49 | ) |
| 50 | }).pipe(Effect.provide(MainLayer))) |
| 51 | |
| 52 | it.effect("copies module stability tags into barrel exports", () => |
| 53 | Effect.gen(function*() { |
| 54 | const fs = yield* FileSystem.FileSystem |
| 55 | const directory = yield* fs.makeTempDirectoryScoped({ prefix: "codegen-" }) |
| 56 | const barrel = path.join(directory, "index.ts") |
| 57 | yield* fs.writeFileString(barrel, "// @barrel\n") |
| 58 | yield* fs.writeFileString( |
| 59 | path.join(directory, "Experimental.ts"), |
| 60 | `/** |
| 61 | * Experimental module. |
| 62 | * |
| 63 | * @stability experimental |
| 64 | * @since 3.0.0 |
| 65 | */ |
| 66 | export const experimental = 1 |
| 67 | ` |
| 68 | ) |
| 69 | yield* fs.writeFileString( |
| 70 | path.join(directory, "ExplicitStable.ts"), |
| 71 | `/** |
| 72 | * Explicitly stable module. |
| 73 | * |
| 74 | * @stability stable |
| 75 | * @since 1.0.0 |
| 76 | */ |
| 77 | export const explicitStable = 1 |
| 78 | ` |
| 79 | ) |
| 80 | yield* fs.writeFileString( |
| 81 | path.join(directory, "Stable.ts"), |
| 82 | `/** |
| 83 | * Stable module. |
| 84 | * |
| 85 | * @since 1.0.0 |
| 86 | */ |
| 87 | export const stable = 1 |
| 88 | ` |
| 89 | ) |
| 90 | yield* fs.writeFileString( |
| 91 | path.join(directory, "Unstable.ts"), |
| 92 | `/** |
| 93 | * Unstable module. |
| 94 | * |
| 95 | * @stability unstable |
| 96 | * @since 2.0.0 |
| 97 | */ |
| 98 | export const unstable = 1 |
| 99 | ` |
| 100 | ) |
| 101 | |
| 102 | const generator = yield* Codegen.BarrelGenerator |
| 103 | yield* generator.processFile({ path: barrel, pattern: "*.ts", offset: 1 }) |
| 104 | |
| 105 | assert.strictEqual( |
| 106 | yield* fs.readFileString(barrel), |
| 107 | `// @barrel |
| 108 | |
| 109 | /** |
| 110 | * @stability experimental |
| 111 | * @since 3.0.0 |
| 112 | */ |
| 113 | export * as Experimental from "./Experimental.ts" |
| 114 | |
| 115 | /** |
| 116 | * @stability stable |
| 117 | * @since 1.0.0 |
| 118 | */ |
| 119 | export * as ExplicitStable from "./ExplicitStable.ts" |
| 120 | |
| 121 | /** |
| 122 | * @since 1.0.0 |
| 123 | */ |
| 124 | export * as Stable from "./Stable.ts" |
| 125 | |
| 126 | /** |
| 127 | * @stability unstable |
| 128 | * @since 2.0.0 |
| 129 | */ |
| 130 | export * as Unstable from "./Unstable.ts" |
| 131 | ` |
| 132 | ) |
| 133 | }).pipe(Effect.provide(MainLayer))) |
| 134 | |
| 135 | it.effect("reads the module JSDoc after triple-slash directives", () => |
| 136 | Effect.gen(function*() { |
| 137 | const fs = yield* FileSystem.FileSystem |
| 138 | const directory = yield* fs.makeTempDirectoryScoped({ prefix: "codegen-" }) |
| 139 | const barrel = path.join(directory, "index.ts") |
| 140 | yield* fs.writeFileString(barrel, "// @barrel\n") |
| 141 | yield* fs.writeFileString( |
| 142 | path.join(directory, "Disposable.ts"), |
| 143 | `/// <reference lib="esnext.disposable" preserve="true" /> |
| 144 | /** |
| 145 | * @since 2.0.0 |
| 146 | */ |
| 147 | export const disposable = 1 |
| 148 | ` |
| 149 | ) |
| 150 | |
| 151 | const generator = yield* Codegen.BarrelGenerator |
| 152 | yield* generator.processFile({ path: barrel, pattern: "*.ts", offset: 1 }) |
| 153 | |
| 154 | assert.strictEqual( |
| 155 | yield* fs.readFileString(barrel), |
| 156 | `// @barrel |
| 157 | |
| 158 | /** |
| 159 | * @since 2.0.0 |
| 160 | */ |
| 161 | export * as Disposable from "./Disposable.ts" |
| 162 | ` |
| 163 | ) |
| 164 | }).pipe(Effect.provide(MainLayer))) |
| 165 | }) |