types: (wip) improve dts output

This commit is contained in:
Evan You
2019-11-01 11:32:53 -04:00
parent 06c5b0a861
commit 5eee1152ca
9 changed files with 53 additions and 31 deletions

View File

@@ -27,6 +27,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.t || args.types
const buildAllMatching = args.all || args.a
const lean = args.lean || args.l
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
@@ -68,7 +69,7 @@ async function build(target) {
`NODE_ENV:${env}`,
`TARGET:${target}`,
formats ? `FORMATS:${formats}` : ``,
args.types ? `TYPES:true` : ``,
buildTypes ? `TYPES:true` : ``,
prodOnly ? `PROD_ONLY:true` : ``,
lean ? `LEAN:true` : ``
]
@@ -78,7 +79,7 @@ async function build(target) {
{ stdio: 'inherit' }
)
if (args.types && pkg.types) {
if (buildTypes && pkg.types) {
console.log()
console.log(
chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`))
@@ -97,6 +98,17 @@ async function build(target) {
})
if (result.succeeded) {
// concat additional d.ts to rolled-up dts (mostly for JSX)
if (pkg.buildOptions.dts) {
const dtsPath = path.resolve(pkgDir, pkg.types)
const existing = await fs.readFile(dtsPath, 'utf-8')
const toAdd = await Promise.all(
pkg.buildOptions.dts.map(file => {
return fs.readFile(path.resolve(pkgDir, file), 'utf-8')
})
)
await fs.writeFile(dtsPath, existing + '\n' + toAdd.join('\n'))
}
console.log(
chalk.bold(chalk.green(`API Extractor completed successfully.`))
)