Skip to content

Commit

Permalink
workflow: support building types in build script
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 18, 2023
1 parent 57f0fbe commit 7f1b546
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
8 changes: 7 additions & 1 deletion rollup.dts.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ if (!existsSync('temp/packages')) {
process.exit(1)
}

export default readdirSync('temp/packages').map(pkg => {
const packages = readdirSync('temp/packages')
const targets = process.env.TARGETS ? process.env.TARGETS.split(',') : null
const targetPackages = targets
? packages.filter(pkg => targets.includes(pkg))
: packages

export default targetPackages.map(pkg => {
return {
input: `./temp/packages/${pkg}/src/index.d.ts`,
output: {
Expand Down
26 changes: 20 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const targets = args._
const formats = args.formats || args.f
const devOnly = args.devOnly || args.d
const prodOnly = !devOnly && (args.prodOnly || args.p)
const buildTypes = args.withTypes || args.t
const sourceMap = args.sourcemap || args.s
const isRelease = args.release
const buildAllMatching = args.all || args.a
Expand All @@ -44,12 +45,25 @@ run()
async function run() {
const removeCache = scanEnums()
try {
if (!targets.length) {
await buildAll(allTargets)
checkAllSizes(allTargets)
} else {
await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
const resolvedTargets = targets.length
? fuzzyMatchTarget(targets, buildAllMatching)
: allTargets
await buildAll(resolvedTargets)
checkAllSizes(resolvedTargets)
if (buildTypes) {
await execa(
'pnpm',
[
'run',
'build-dts',
...(targets.length
? ['--environment', `TARGETS:${resolvedTargets.join(',')}`]
: [])
],
{
stdio: 'inherit'
}
)
}
} finally {
removeCache()
Expand Down
6 changes: 3 additions & 3 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ async function main() {
// build all packages with types
step('\nBuilding all packages...')
if (!skipBuild && !isDryRun) {
await run('pnpm', ['run', 'build'])
step('\nBuilding and testing types...')
await run('pnpm', ['test-dts'])
await run('pnpm', ['run', 'build', '--withTypes'])
step('\nTesting built types...')
await run('pnpm', ['test-dts-only'])
} else {
console.log(`(skipped)`)
}
Expand Down

0 comments on commit 7f1b546

Please sign in to comment.