Skip to content

Commit 6613a97

Browse files
authoredSep 6, 2019
fix: revert do not run parallel mode when you have only one file (#146)
1 parent 815e533 commit 6613a97

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed
 

‎src/TaskRunner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class TaskRunner {
4141
}
4242

4343
async run(tasks) {
44-
if (this.numberWorkers > 1 && tasks.length > 1) {
44+
if (this.numberWorkers > 1) {
4545
this.worker = new Worker(workerPath, { numWorkers: this.numberWorkers });
4646
}
4747

‎src/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,18 @@ class TerserPlugin {
262262
}
263263
});
264264

265-
let completedTasks = [];
265+
if (tasks.length === 0) {
266+
return Promise.resolve();
267+
}
266268

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+
});
272273

273-
completedTasks = await taskRunner.run(tasks);
274+
const completedTasks = await taskRunner.run(tasks);
274275

275-
await taskRunner.exit();
276-
}
276+
await taskRunner.exit();
277277

278278
completedTasks.forEach((completedTask, index) => {
279279
const { file, input, inputSourceMap, commentsFile } = tasks[index];

‎test/parallel-option.test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ describe('parallel option', () => {
154154
const errors = stats.compilation.errors.map(cleanErrorStack);
155155
const warnings = stats.compilation.warnings.map(cleanErrorStack);
156156

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);
158165

159166
expect(errors).toMatchSnapshot('errors');
160167
expect(warnings).toMatchSnapshot('warnings');

0 commit comments

Comments
 (0)
Failed to load comments.