3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export default class TaskRunner {
41
41
}
42
42
43
43
async run ( tasks ) {
44
- if ( this . numberWorkers > 1 && tasks . length > 1 ) {
44
+ if ( this . numberWorkers > 1 ) {
45
45
this . worker = new Worker ( workerPath , { numWorkers : this . numberWorkers } ) ;
46
46
}
47
47
Original file line number Diff line number Diff line change @@ -262,18 +262,18 @@ class TerserPlugin {
262
262
}
263
263
} ) ;
264
264
265
- let completedTasks = [ ] ;
265
+ if ( tasks . length === 0 ) {
266
+ return Promise . resolve ( ) ;
267
+ }
266
268
267
- if ( tasks . length > 0 ) {
268
- const taskRunner = new TaskRunner ( {
269
- cache : this . options . cache ,
270
- parallel : this . options . parallel ,
271
- } ) ;
269
+ const taskRunner = new TaskRunner ( {
270
+ cache : this . options . cache ,
271
+ parallel : this . options . parallel ,
272
+ } ) ;
272
273
273
- completedTasks = await taskRunner . run ( tasks ) ;
274
+ const completedTasks = await taskRunner . run ( tasks ) ;
274
275
275
- await taskRunner . exit ( ) ;
276
- }
276
+ await taskRunner . exit ( ) ;
277
277
278
278
completedTasks . forEach ( ( completedTask , index ) => {
279
279
const { file, input, inputSourceMap, commentsFile } = tasks [ index ] ;
Original file line number Diff line number Diff line change @@ -154,7 +154,14 @@ describe('parallel option', () => {
154
154
const errors = stats . compilation . errors . map ( cleanErrorStack ) ;
155
155
const warnings = stats . compilation . warnings . map ( cleanErrorStack ) ;
156
156
157
- expect ( Worker ) . toHaveBeenCalledTimes ( 0 ) ;
157
+ expect ( Worker ) . toHaveBeenCalledTimes ( 1 ) ;
158
+ expect ( Worker ) . toHaveBeenLastCalledWith ( workerPath , {
159
+ numWorkers : os . cpus ( ) . length - 1 ,
160
+ } ) ;
161
+ expect ( workerTransform ) . toHaveBeenCalledTimes (
162
+ Object . keys ( stats . compilation . assets ) . length
163
+ ) ;
164
+ expect ( workerEnd ) . toHaveBeenCalledTimes ( 1 ) ;
158
165
159
166
expect ( errors ) . toMatchSnapshot ( 'errors' ) ;
160
167
expect ( warnings ) . toMatchSnapshot ( 'warnings' ) ;
0 commit comments