Skip to content

Commit 32f1c52

Browse files
committed
test: guard zod export parity
1 parent 06c0a82 commit 32f1c52

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

docs/todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
- [x] Add runtime parity fixtures by copying proven Assembly Instructions from `~/code/content` (stepParsing fixtures)
6767
- [x] Add a sync-v4 regression fixture to verify `.passthrough()``.catchall(z.unknown())` and `z.record(...)` key injection
6868
- [ ] Add runtime parity coverage for `assemblyStatus` (ok/error/busy) once stable samples are selected
69-
- [ ] Add a CI guard that `@transloadit/zod` exports list stays in sync with `packages/node/src/alphalib/types`
69+
- [x] Add a CI guard that `@transloadit/zod` exports list stays in sync with `packages/node/src/alphalib/types`

packages/zod/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"sync:v4": "node scripts/sync-v4.ts",
3535
"sync": "yarn sync:v3 && yarn sync:v4",
3636
"build": "yarn sync && tsc --build tsconfig.build.json",
37-
"check": "yarn sync && tsc --build tsconfig.build.json && tsc --noEmit --project tsconfig.test.json && node test/runtime-parity.test.ts"
37+
"check": "yarn sync && tsc --build tsconfig.build.json && tsc --noEmit --project tsconfig.test.json && node test/exports-sync.test.ts && node test/runtime-parity.test.ts"
3838
},
3939
"dependencies": {
4040
"zod": "^4.0.0"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from 'node:assert/strict'
2+
import { readdir, readFile } from 'node:fs/promises'
3+
import { dirname, resolve } from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
6+
const filePath = fileURLToPath(import.meta.url)
7+
const zodRoot = resolve(dirname(filePath), '..')
8+
const typesRoot = resolve(zodRoot, '../node/src/alphalib/types')
9+
10+
const normalize = (items: string[]): string[] => [...new Set(items)].sort()
11+
12+
const listTypeModules = async (): Promise<string[]> => {
13+
const entries = await readdir(typesRoot, { withFileTypes: true })
14+
const modules = entries
15+
.filter((entry) => entry.isFile() && entry.name.endsWith('.ts'))
16+
.map((entry) => entry.name.replace(/\.ts$/, ''))
17+
modules.push('robots/_index')
18+
return normalize(modules)
19+
}
20+
21+
const readIndexModules = async (indexPath: string): Promise<string[]> => {
22+
const contents = await readFile(indexPath, 'utf8')
23+
const modules = contents
24+
.split('\n')
25+
.map((line) => line.match(/export \* from ['"]\.\/(.+?)\.(?:ts|js)['"]/))
26+
.filter((match): match is RegExpMatchArray => Boolean(match))
27+
.map((match) => match[1])
28+
return normalize(modules)
29+
}
30+
31+
const expected = await listTypeModules()
32+
const v3Index = await readIndexModules(resolve(zodRoot, 'src/v3/index.ts'))
33+
const v4Index = await readIndexModules(resolve(zodRoot, 'src/v4/index.ts'))
34+
35+
assert.deepEqual(
36+
v3Index,
37+
expected,
38+
'zod v3 index exports must match packages/node/src/alphalib/types',
39+
)
40+
assert.deepEqual(
41+
v4Index,
42+
expected,
43+
'zod v4 index exports must match packages/node/src/alphalib/types',
44+
)
45+
46+
console.log('zod exports: ok')

0 commit comments

Comments
 (0)