@@ -29,6 +29,7 @@ const devOnly = args.devOnly || args.d
29
29
const prodOnly = ! devOnly && ( args . prodOnly || args . p )
30
30
const sourceMap = args . sourcemap || args . s
31
31
const isRelease = args . release
32
+ const buildTypes = args . t || args . types || isRelease
32
33
const buildAllMatching = args . all || args . a
33
34
const commit = execa . sync ( 'git' , [ 'rev-parse' , 'HEAD' ] ) . stdout . slice ( 0 , 7 )
34
35
@@ -75,6 +76,7 @@ async function build(target) {
75
76
`NODE_ENV:${ env } ` ,
76
77
`TARGET:${ target } ` ,
77
78
formats ? `FORMATS:${ formats } ` : `` ,
79
+ buildTypes ? `TYPES:true` : `` ,
78
80
prodOnly ? `PROD_ONLY:true` : `` ,
79
81
sourceMap ? `SOURCE_MAP:true` : `` ,
80
82
]
@@ -83,6 +85,44 @@ async function build(target) {
83
85
] ,
84
86
{ stdio : 'inherit' }
85
87
)
88
+
89
+ if ( buildTypes && pkg . types ) {
90
+ console . log ( )
91
+ console . log ( chalk . bold ( chalk . yellow ( `Rolling up type definitions for ${ target } ...` ) ) )
92
+
93
+ // build types
94
+ const { Extractor, ExtractorConfig } = require ( '@microsoft/api-extractor' )
95
+
96
+ const extractorConfigPath = path . resolve ( pkgDir , `api-extractor.json` )
97
+ const extractorConfig = ExtractorConfig . loadFileAndPrepare ( extractorConfigPath )
98
+ const result = Extractor . invoke ( extractorConfig , {
99
+ localBuild : true ,
100
+ showVerboseMessages : true ,
101
+ } )
102
+
103
+ if ( result . succeeded ) {
104
+ // concat additional d.ts to rolled-up dts (mostly for JSX)
105
+ if ( pkg . buildOptions && pkg . buildOptions . dts ) {
106
+ const dtsPath = path . resolve ( pkgDir , pkg . types )
107
+ const existing = await fs . readFile ( dtsPath , 'utf-8' )
108
+ const toAdd = await Promise . all (
109
+ pkg . buildOptions . dts . map ( ( file ) => {
110
+ return fs . readFile ( path . resolve ( pkgDir , file ) , 'utf-8' )
111
+ } )
112
+ )
113
+ await fs . writeFile ( dtsPath , existing + '\n' + toAdd . join ( '\n' ) )
114
+ }
115
+ console . log ( chalk . bold ( chalk . green ( `API Extractor completed successfully.` ) ) )
116
+ } else {
117
+ console . error (
118
+ `API Extractor completed with ${ extractorResult . errorCount } errors` +
119
+ ` and ${ extractorResult . warningCount } warnings`
120
+ )
121
+ process . exitCode = 1
122
+ }
123
+
124
+ await fs . remove ( `${ pkgDir } /dist/packages` )
125
+ }
86
126
}
87
127
88
128
function checkAllSizes ( targets ) {
0 commit comments