Open History to see the last commit
1import { packages, rootDir } from './config'
2import path from 'path'
3import fsp from 'fs/promises'
4import jsonfile from 'jsonfile'
5β
6import type { PackageJson } from 'type-fest'
7β
8async function run() {
9 console.info('Validating packages...')
10 const failedValidations: string[] = []
11β
12 await Promise.all(
13 packages.map(async (pkg) => {
14 const pkgJson = await readPackageJson(
15 path.resolve(rootDir, 'packages', pkg.packageDir, 'package.json'),
16 )
17β
18 const entries =
19 pkg.name === '@tanstack/eslint-plugin-query'
20 ? (['main'] as const)
21 : pkg.name === '@tanstack/svelte-query'
22 ? (['types', 'module'] as const)
23 : (['main', 'types', 'module'] as const)
24β
25 await Promise.all(
26 entries.map(async (entryKey) => {
27 const entry = pkgJson[entryKey] as string
28β
29 if (!entry) {
30 throw new Error(
31 `Missing entry for "${entryKey}" in ${pkg.packageDir}/package.json!`,
32 )
33 }
34β
35 const filePath = path.resolve(
36 rootDir,
37 'packages',
38 pkg.packageDir,
39 entry,
40 )
41β
42 try {
43 await fsp.access(filePath)
44 } catch (err) {
45 failedValidations.push(`Missing build file: ${filePath}`)
46 }
47 }),
48 )
49 }),
50 )
51 console.info('')
52 if (failedValidations.length > 0) {
53 throw new Error(
54 'Some packages failed validation:\n\n' + failedValidations.join('\n'),
55 )
56 }
57}
58β
59run().catch((err) => {
60 console.info(err)
61 process.exit(1)
62})
63β
64async function readPackageJson(pathName: string) {
65 return (await jsonfile.readFile(pathName)) as PackageJson
66}