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