@@ -5,6 +5,7 @@ import type { PluginDriver } from '../utils/PluginDriver';
55import { ensureArray } from '../utils/ensureArray' ;
66import { errAlreadyClosed , errCannotEmitFromOptionsHook , error } from '../utils/error' ;
77import { promises as fs } from '../utils/fs' ;
8+ import { catchUnfinishedHookActions } from '../utils/hookActions' ;
89import { normalizeInputOptions } from '../utils/options/normalizeInputOptions' ;
910import { normalizeOutputOptions } from '../utils/options/normalizeOutputOptions' ;
1011import type { GenericConfigObject } from '../utils/options/options' ;
@@ -48,20 +49,21 @@ export async function rollupInternal(
4849
4950 timeStart ( 'BUILD' , 1 ) ;
5051
51- try {
52- await graph . pluginDriver . hookParallel ( 'buildStart' , [ inputOptions ] ) ;
53- await graph . build ( ) ;
54- } catch ( err : any ) {
55- const watchFiles = Object . keys ( graph . watchFiles ) ;
56- if ( watchFiles . length > 0 ) {
57- err . watchFiles = watchFiles ;
52+ await catchUnfinishedHookActions ( graph . pluginDriver , async ( ) => {
53+ try {
54+ await graph . pluginDriver . hookParallel ( 'buildStart' , [ inputOptions ] ) ;
55+ await graph . build ( ) ;
56+ } catch ( err : any ) {
57+ const watchFiles = Object . keys ( graph . watchFiles ) ;
58+ if ( watchFiles . length > 0 ) {
59+ err . watchFiles = watchFiles ;
60+ }
61+ await graph . pluginDriver . hookParallel ( 'buildEnd' , [ err ] ) ;
62+ await graph . pluginDriver . hookParallel ( 'closeBundle' , [ ] ) ;
63+ throw err ;
5864 }
59- await graph . pluginDriver . hookParallel ( 'buildEnd' , [ err ] ) ;
60- await graph . pluginDriver . hookParallel ( 'closeBundle' , [ ] ) ;
61- throw err ;
62- }
63-
64- await graph . pluginDriver . hookParallel ( 'buildEnd' , [ ] ) ;
65+ await graph . pluginDriver . hookParallel ( 'buildEnd' , [ ] ) ;
66+ } ) ;
6567
6668 timeEnd ( 'BUILD' , 1 ) ;
6769
@@ -144,7 +146,7 @@ function normalizePlugins(plugins: readonly Plugin[], anonymousPrefix: string):
144146 } ) ;
145147}
146148
147- async function handleGenerateWrite (
149+ function handleGenerateWrite (
148150 isWrite : boolean ,
149151 inputOptions : NormalizedInputOptions ,
150152 unsetInputOptions : ReadonlySet < string > ,
@@ -161,19 +163,23 @@ async function handleGenerateWrite(
161163 inputOptions ,
162164 unsetInputOptions
163165 ) ;
164- const bundle = new Bundle ( outputOptions , unsetOptions , inputOptions , outputPluginDriver , graph ) ;
165- const generated = await bundle . generate ( isWrite ) ;
166- if ( isWrite ) {
167- if ( ! outputOptions . dir && ! outputOptions . file ) {
168- return error ( {
169- code : 'MISSING_OPTION' ,
170- message : 'You must specify "output.file" or "output.dir" for the build.'
171- } ) ;
166+ return catchUnfinishedHookActions ( outputPluginDriver , async ( ) => {
167+ const bundle = new Bundle ( outputOptions , unsetOptions , inputOptions , outputPluginDriver , graph ) ;
168+ const generated = await bundle . generate ( isWrite ) ;
169+ if ( isWrite ) {
170+ if ( ! outputOptions . dir && ! outputOptions . file ) {
171+ return error ( {
172+ code : 'MISSING_OPTION' ,
173+ message : 'You must specify "output.file" or "output.dir" for the build.'
174+ } ) ;
175+ }
176+ await Promise . all (
177+ Object . values ( generated ) . map ( chunk => writeOutputFile ( chunk , outputOptions ) )
178+ ) ;
179+ await outputPluginDriver . hookParallel ( 'writeBundle' , [ outputOptions , generated ] ) ;
172180 }
173- await Promise . all ( Object . values ( generated ) . map ( chunk => writeOutputFile ( chunk , outputOptions ) ) ) ;
174- await outputPluginDriver . hookParallel ( 'writeBundle' , [ outputOptions , generated ] ) ;
175- }
176- return createOutput ( generated ) ;
181+ return createOutput ( generated ) ;
182+ } ) ;
177183}
178184
179185function getOutputOptionsAndPluginDriver (
0 commit comments