-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract package validation to an extra script (#5039)
* chore: extract package validation to an extra script and run it during CI * chore: add missing `build:types` script to solid-query
- Loading branch information
Showing
5 changed files
with
77 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { packages, rootDir } from './config' | ||
import path from 'path' | ||
import fsp from 'fs/promises' | ||
import jsonfile from 'jsonfile' | ||
|
||
import type { PackageJson } from 'type-fest' | ||
|
||
async function run() { | ||
console.info('Validating packages...') | ||
const failedValidations: string[] = [] | ||
|
||
await Promise.all( | ||
packages.map(async (pkg) => { | ||
const pkgJson = await readPackageJson( | ||
path.resolve(rootDir, 'packages', pkg.packageDir, 'package.json'), | ||
) | ||
|
||
const entries = | ||
pkg.name === '@tanstack/eslint-plugin-query' | ||
? (['main'] as const) | ||
: pkg.name === '@tanstack/svelte-query' | ||
? (['types', 'module'] as const) | ||
: (['main', 'types', 'module'] as const) | ||
|
||
await Promise.all( | ||
entries.map(async (entryKey) => { | ||
const entry = pkgJson[entryKey] as string | ||
|
||
if (!entry) { | ||
throw new Error( | ||
`Missing entry for "${entryKey}" in ${pkg.packageDir}/package.json!`, | ||
) | ||
} | ||
|
||
const filePath = path.resolve( | ||
rootDir, | ||
'packages', | ||
pkg.packageDir, | ||
entry, | ||
) | ||
|
||
try { | ||
await fsp.access(filePath) | ||
} catch (err) { | ||
failedValidations.push(`Missing build file: ${filePath}`) | ||
} | ||
}), | ||
) | ||
}), | ||
) | ||
console.info('') | ||
if (failedValidations.length > 0) { | ||
throw new Error( | ||
'Some packages failed validation:\n\n' + failedValidations.join('\n'), | ||
) | ||
} | ||
} | ||
|
||
run().catch((err) => { | ||
console.info(err) | ||
process.exit(1) | ||
}) | ||
|
||
async function readPackageJson(pathName: string) { | ||
return (await jsonfile.readFile(pathName)) as PackageJson | ||
} |