@@ -4,8 +4,10 @@ const rollup = require('rollup');
44const babel = require ( '@rollup/plugin-babel' ) . babel ;
55const closure = require ( './plugins/closure-plugin' ) ;
66const flowRemoveTypes = require ( 'flow-remove-types' ) ;
7+ const { dts} = require ( 'rollup-plugin-dts' ) ;
78const prettier = require ( 'rollup-plugin-prettier' ) ;
89const replace = require ( '@rollup/plugin-replace' ) ;
10+ const typescript = require ( '@rollup/plugin-typescript' ) ;
911const stripBanner = require ( 'rollup-plugin-strip-banner' ) ;
1012const chalk = require ( 'chalk' ) ;
1113const resolve = require ( '@rollup/plugin-node-resolve' ) . nodeResolve ;
@@ -61,6 +63,8 @@ const {
6163 RN_FB_PROD ,
6264 RN_FB_PROFILING ,
6365 BROWSER_SCRIPT ,
66+ CJS_DTS ,
67+ ESM_DTS ,
6468} = Bundles . bundleTypes ;
6569
6670const { getFilename} = Bundles ;
@@ -250,9 +254,11 @@ function getFormat(bundleType) {
250254 case RN_FB_DEV :
251255 case RN_FB_PROD :
252256 case RN_FB_PROFILING :
257+ case CJS_DTS :
253258 return `cjs` ;
254259 case ESM_DEV :
255260 case ESM_PROD :
261+ case ESM_DTS :
256262 return `es` ;
257263 case BROWSER_SCRIPT :
258264 return `iife` ;
@@ -281,6 +287,8 @@ function isProductionBundleType(bundleType) {
281287 case RN_FB_PROD :
282288 case RN_FB_PROFILING :
283289 case BROWSER_SCRIPT :
290+ case CJS_DTS :
291+ case ESM_DTS :
284292 return true ;
285293 default :
286294 throw new Error ( `Unknown type: ${ bundleType } ` ) ;
@@ -303,6 +311,8 @@ function isProfilingBundleType(bundleType) {
303311 case ESM_DEV :
304312 case ESM_PROD :
305313 case BROWSER_SCRIPT :
314+ case CJS_DTS :
315+ case ESM_DTS :
306316 return false ;
307317 case FB_WWW_PROFILING :
308318 case NODE_PROFILING :
@@ -368,27 +378,36 @@ function getPlugins(
368378 pureExternalModules ,
369379 bundle
370380) {
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+ }
371385 try {
372386 const forks = Modules . getForks ( bundleType , entry , moduleType , bundle ) ;
373387 const isProduction = isProductionBundleType ( bundleType ) ;
374388 const isProfiling = isProfilingBundleType ( bundleType ) ;
375389
376390 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 ;
378395
379396 return [
380397 // Keep dynamic imports as externals
381398 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+ } ,
392411 // Shim any modules that need forking in this environment.
393412 useForks ( forks ) ,
394413 // Ensure we don't try to bundle any fbjs modules.
@@ -839,7 +858,9 @@ async function buildEverything() {
839858 [ bundle , RN_FB_DEV ] ,
840859 [ bundle , RN_FB_PROD ] ,
841860 [ bundle , RN_FB_PROFILING ] ,
842- [ bundle , BROWSER_SCRIPT ]
861+ [ bundle , BROWSER_SCRIPT ] ,
862+ [ bundle , CJS_DTS ] ,
863+ [ bundle , ESM_DTS ]
843864 ) ;
844865 }
845866
0 commit comments