@@ -4,8 +4,10 @@ const rollup = require('rollup');
4
4
const babel = require ( '@rollup/plugin-babel' ) . babel ;
5
5
const closure = require ( './plugins/closure-plugin' ) ;
6
6
const flowRemoveTypes = require ( 'flow-remove-types' ) ;
7
+ const { dts} = require ( 'rollup-plugin-dts' ) ;
7
8
const prettier = require ( 'rollup-plugin-prettier' ) ;
8
9
const replace = require ( '@rollup/plugin-replace' ) ;
10
+ const typescript = require ( '@rollup/plugin-typescript' ) ;
9
11
const stripBanner = require ( 'rollup-plugin-strip-banner' ) ;
10
12
const chalk = require ( 'chalk' ) ;
11
13
const resolve = require ( '@rollup/plugin-node-resolve' ) . nodeResolve ;
@@ -61,6 +63,8 @@ const {
61
63
RN_FB_PROD ,
62
64
RN_FB_PROFILING ,
63
65
BROWSER_SCRIPT ,
66
+ CJS_DTS ,
67
+ ESM_DTS ,
64
68
} = Bundles . bundleTypes ;
65
69
66
70
const { getFilename} = Bundles ;
@@ -250,9 +254,11 @@ function getFormat(bundleType) {
250
254
case RN_FB_DEV :
251
255
case RN_FB_PROD :
252
256
case RN_FB_PROFILING :
257
+ case CJS_DTS :
253
258
return `cjs` ;
254
259
case ESM_DEV :
255
260
case ESM_PROD :
261
+ case ESM_DTS :
256
262
return `es` ;
257
263
case BROWSER_SCRIPT :
258
264
return `iife` ;
@@ -281,6 +287,8 @@ function isProductionBundleType(bundleType) {
281
287
case RN_FB_PROD :
282
288
case RN_FB_PROFILING :
283
289
case BROWSER_SCRIPT :
290
+ case CJS_DTS :
291
+ case ESM_DTS :
284
292
return true ;
285
293
default :
286
294
throw new Error ( `Unknown type: ${ bundleType } ` ) ;
@@ -303,6 +311,8 @@ function isProfilingBundleType(bundleType) {
303
311
case ESM_DEV :
304
312
case ESM_PROD :
305
313
case BROWSER_SCRIPT :
314
+ case CJS_DTS :
315
+ case ESM_DTS :
306
316
return false ;
307
317
case FB_WWW_PROFILING :
308
318
case NODE_PROFILING :
@@ -368,27 +378,36 @@ function getPlugins(
368
378
pureExternalModules ,
369
379
bundle
370
380
) {
381
+ // Short-circuit if we're only building a .d.ts bundle
382
+ if ( bundleType === CJS_DTS || bundleType === ESM_DTS ) {
383
+ return [ dts ( { tsconfig : bundle . tsconfig } ) ] ;
384
+ }
371
385
try {
372
386
const forks = Modules . getForks ( bundleType , entry , moduleType , bundle ) ;
373
387
const isProduction = isProductionBundleType ( bundleType ) ;
374
388
const isProfiling = isProfilingBundleType ( bundleType ) ;
375
389
376
390
const needsMinifiedByClosure =
377
- bundleType !== ESM_PROD && bundleType !== ESM_DEV ;
391
+ bundleType !== ESM_PROD &&
392
+ bundleType !== ESM_DEV &&
393
+ // TODO(@poteto) figure out ICE in closure compiler for eslint-plugin-react-hooks (ts)
394
+ bundle . tsconfig == null ;
378
395
379
396
return [
380
397
// Keep dynamic imports as externals
381
398
dynamicImports ( ) ,
382
- {
383
- name : 'rollup-plugin-flow-remove-types' ,
384
- transform ( code ) {
385
- const transformed = flowRemoveTypes ( code ) ;
386
- return {
387
- code : transformed . toString ( ) ,
388
- map : null ,
389
- } ;
390
- } ,
391
- } ,
399
+ bundle . tsconfig != null
400
+ ? typescript ( { tsconfig : bundle . tsconfig } )
401
+ : {
402
+ name : 'rollup-plugin-flow-remove-types' ,
403
+ transform ( code ) {
404
+ const transformed = flowRemoveTypes ( code ) ;
405
+ return {
406
+ code : transformed . toString ( ) ,
407
+ map : null ,
408
+ } ;
409
+ } ,
410
+ } ,
392
411
// Shim any modules that need forking in this environment.
393
412
useForks ( forks ) ,
394
413
// Ensure we don't try to bundle any fbjs modules.
@@ -839,7 +858,9 @@ async function buildEverything() {
839
858
[ bundle , RN_FB_DEV ] ,
840
859
[ bundle , RN_FB_PROD ] ,
841
860
[ bundle , RN_FB_PROFILING ] ,
842
- [ bundle , BROWSER_SCRIPT ]
861
+ [ bundle , BROWSER_SCRIPT ] ,
862
+ [ bundle , CJS_DTS ] ,
863
+ [ bundle , ESM_DTS ]
843
864
) ;
844
865
}
845
866
0 commit comments