Skip to content

Commit

Permalink
chore: extract package validation to an extra script (#5039)
Browse files Browse the repository at this point in the history
* 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
TkDodo authored Feb 26, 2023
1 parent c807d91 commit 1ec2c14
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 61 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ jobs:
- run: pnpm run test:react:17
env:
REACTJS_VERSION: 17
test-size:
name: 'Size'
test-build:
name: 'Test Build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -94,6 +94,6 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:size
- run: pnpm run test:build
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
"test:format": "pnpm run prettier --check",
"test:lib": "pnpm --filter \"./packages/**\" run test:lib",
"test:lib:dev": "pnpm --filter \"./packages/**\" run test:lib:dev",
"test:size": "pnpm run build && bundlewatch",
"test:build": "pnpm run build && bundlewatch && pnpm run validatePackages",
"test:types": "pnpm --filter \"./packages/**\" run test:types",
"build": "rollup --config rollup.config.js && pnpm --filter \"./packages/**\" run build && pnpm run build:types",
"build:types": "pnpm --filter \"./packages/**\" run build:types",
"watch": "concurrently --kill-others \"rollup --config rollup.config.js -w\" \"pnpm run build:types --watch\"",
"dev": "pnpm run watch",
"prettier": "prettier --plugin-search-dir . \"{packages,examples}/**/src/**/*.{md,js,jsx,ts,tsx,json,vue,svelte}\"",
"prettier:write": "pnpm run prettier --write",
"cipublish": "ts-node scripts/publish.ts"
"cipublish": "ts-node scripts/publish.ts",
"validatePackages": "ts-node scripts/validate-packages.ts"
},
"namespace": "@tanstack",
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/solid-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"test:eslint": "eslint --ext .ts,.tsx ./src",
"test:types": "tsc",
"test:lib": "jest --config ./jest.config.ts",
"test:lib:dev": "pnpm run test:lib --watch"
"test:lib:dev": "pnpm run test:lib --watch",
"build:types": "tsc --build"
},
"files": [
"build/lib/*",
Expand Down
58 changes: 3 additions & 55 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import {
branchConfigs,
examplesDirs,
latestBranch,
packages,
rootDir,
} from './config'
import { branchConfigs, latestBranch, packages, rootDir } from './config'
import type { BranchConfig, Commit, Package } from './types'

// Originally ported to TS from https://github.com/remix-run/react-router/tree/main/scripts/{version,publish}.js
import path from 'path'
import { exec, execSync } from 'child_process'
import { execSync } from 'child_process'
import fsp from 'fs/promises'
import chalk from 'chalk'
import jsonfile from 'jsonfile'
Expand Down Expand Up @@ -373,53 +367,7 @@ async function run() {
console.info('')

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'),
)
}
execSync(`pnpm run validatePackages`, { encoding: 'utf8', stdio: 'inherit' })

console.info(`Updating all changed packages to version ${version}...`)
// Update each package to the new version
Expand Down
66 changes: 66 additions & 0 deletions scripts/validate-packages.ts
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
}

0 comments on commit 1ec2c14

Please sign in to comment.