|
| 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