| 1 | // Type-checks the built `effect` declarations the way a consumer with |
| 2 | // `skipLibCheck: false` does. Run after `pnpm build` with `stripInternal` |
| 3 | // enabled to catch public declarations that reference `@internal` symbols |
| 4 | // (see Effect-TS/effect#6431, #7187, #8161). |
| 5 | import { execFileSync } from "node:child_process" |
| 6 | import * as Fs from "node:fs" |
| 7 | import * as Os from "node:os" |
| 8 | import * as Path from "node:path" |
| 9 | import { fileURLToPath } from "node:url" |
| 10 | |
| 11 | const root = Path.resolve(Path.dirname(fileURLToPath(import.meta.url)), "..") |
| 12 | const pkgDir = Path.join(root, "packages", "effect") |
| 13 | const dist = Path.join(pkgDir, "dist") |
| 14 | |
| 15 | if (!Fs.existsSync(Path.join(dist, "index.d.ts"))) { |
| 16 | console.error("packages/effect/dist is missing; run `pnpm build` first") |
| 17 | process.exit(1) |
| 18 | } |
| 19 | |
| 20 | const pkg = JSON.parse(Fs.readFileSync(Path.join(pkgDir, "package.json"), "utf8")) |
| 21 | const entrypoints = Object.entries(pkg.publishConfig.exports) |
| 22 | .filter(([key, target]) => target !== null && key !== "./package.json" && !key.includes("*")) |
| 23 | .map(([key]) => Path.posix.join(pkg.name, key)) |
| 24 | |
| 25 | const dir = Fs.mkdtempSync(Path.join(Os.tmpdir(), "effect-dist-types-")) |
| 26 | try { |
| 27 | Fs.writeFileSync( |
| 28 | Path.join(dir, "index.ts"), |
| 29 | entrypoints.map((entry, i) => `import * as _${i} from "${entry}"\nexport { _${i} }\n`).join("") |
| 30 | ) |
| 31 | Fs.writeFileSync( |
| 32 | Path.join(dir, "tsconfig.json"), |
| 33 | JSON.stringify({ |
| 34 | compilerOptions: { |
| 35 | strict: true, |
| 36 | noEmit: true, |
| 37 | target: "ES2022", |
| 38 | module: "ESNext", |
| 39 | moduleResolution: "bundler", |
| 40 | skipLibCheck: false, |
| 41 | types: ["node"], |
| 42 | typeRoots: [Path.join(root, "node_modules", "@types")], |
| 43 | paths: { |
| 44 | [pkg.name]: [Path.join(dist, "index.d.ts")], |
| 45 | [`${pkg.name}/*`]: [Path.join(dist, "*")] |
| 46 | } |
| 47 | }, |
| 48 | files: ["index.ts"] |
| 49 | }) |
| 50 | ) |
| 51 | execFileSync("pnpm", ["exec", "tsc", "-p", Path.join(dir, "tsconfig.json")], { cwd: root, stdio: "inherit" }) |
| 52 | } catch (error) { |
| 53 | process.exitCode = typeof error.status === "number" ? error.status : 1 |
| 54 | } finally { |
| 55 | Fs.rmSync(dir, { recursive: true, force: true }) |
| 56 | } |