@@ -6,7 +6,14 @@ import babelPresetEnv from '@babel/preset-env';
66import babelPresetTypescript from '@babel/preset-typescript' ;
77import builtinModules from 'builtin-modules' ;
88import { outputFile , readFile } from 'fs-extra' ;
9- import { rollup , watch , OutputOptions , InputOptions } from 'rollup' ;
9+ import {
10+ rollup ,
11+ watch ,
12+ OutputOptions ,
13+ InputOptions ,
14+ RollupWarning ,
15+ RollupWatchOptions ,
16+ } from 'rollup' ;
1017import babel from 'rollup-plugin-babel' ;
1118import commonjs from 'rollup-plugin-commonjs' ;
1219import dts from 'rollup-plugin-dts' ;
@@ -126,7 +133,7 @@ async function createRollupConfig({
126133 return { inputOptions, outputOptions } ;
127134}
128135
129- function dtsOnWarn ( warning : { code : string ; message : string } ) {
136+ function dtsOnWarn ( warning : RollupWarning ) {
130137 if ( warning . code === 'EMPTY_BUNDLE' ) return ;
131138
132139 console . error ( warning . message ) ;
@@ -140,7 +147,7 @@ async function createTypes({
140147 outputDir : string ;
141148} ) {
142149 // build our Rollup input options for rollup-plugin-dts
143- const inputOptions = {
150+ const inputOptions : InputOptions = {
144151 input,
145152 plugins : [ dts ( ) ] ,
146153 onwarn : dtsOnWarn ,
@@ -153,7 +160,7 @@ async function createTypes({
153160 const { name } = parse ( input ) ;
154161
155162 // build our Rollup output options
156- const outputOptions = {
163+ const outputOptions : OutputOptions = {
157164 file : resolve ( outputDir , format ( { name, ext : '.d.ts' } ) ) ,
158165 format : 'esm' ,
159166 } ;
@@ -234,7 +241,7 @@ export async function bundler({
234241
235242 for ( const { inputOptions, outputOptions } of runs ) {
236243 if ( watchBuild ) {
237- const watcher = watch (
244+ const watchOptions : RollupWatchOptions [ ] = [
238245 Object . assign (
239246 {
240247 output : outputOptions ,
@@ -243,16 +250,15 @@ export async function bundler({
243250 } ,
244251 } ,
245252 inputOptions
246- )
247- ) ;
253+ ) ,
254+ ] ;
255+
256+ const watcher = watch ( watchOptions ) ;
248257
249- watcher . on ( 'event' , ( { code, error } ) => {
250- switch ( code ) {
251- case 'FATAL' :
252- throw new Error ( error ) ;
258+ watcher . on ( 'event' , event => {
259+ switch ( event . code ) {
253260 case 'ERROR' :
254- console . error ( error ) ;
255- break ;
261+ throw event . error ;
256262 case 'END' :
257263 console . log ( `Successful build. (${ inputOptions . input } )` ) ;
258264 break ;
0 commit comments