Skip to content

Commit

Permalink
fix: revert do not run parallel mode when you have only one file (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Sep 6, 2019
1 parent 815e533 commit 6613a97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/TaskRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class TaskRunner {
}

async run(tasks) {
if (this.numberWorkers > 1 && tasks.length > 1) {
if (this.numberWorkers > 1) {
this.worker = new Worker(workerPath, { numWorkers: this.numberWorkers });
}

Expand Down
18 changes: 9 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ class TerserPlugin {
}
});

let completedTasks = [];
if (tasks.length === 0) {
return Promise.resolve();
}

if (tasks.length > 0) {
const taskRunner = new TaskRunner({
cache: this.options.cache,
parallel: this.options.parallel,
});
const taskRunner = new TaskRunner({
cache: this.options.cache,
parallel: this.options.parallel,
});

completedTasks = await taskRunner.run(tasks);
const completedTasks = await taskRunner.run(tasks);

await taskRunner.exit();
}
await taskRunner.exit();

completedTasks.forEach((completedTask, index) => {
const { file, input, inputSourceMap, commentsFile } = tasks[index];
Expand Down
9 changes: 8 additions & 1 deletion test/parallel-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ describe('parallel option', () => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);

expect(Worker).toHaveBeenCalledTimes(0);
expect(Worker).toHaveBeenCalledTimes(1);
expect(Worker).toHaveBeenLastCalledWith(workerPath, {
numWorkers: os.cpus().length - 1,
});
expect(workerTransform).toHaveBeenCalledTimes(
Object.keys(stats.compilation.assets).length
);
expect(workerEnd).toHaveBeenCalledTimes(1);

expect(errors).toMatchSnapshot('errors');
expect(warnings).toMatchSnapshot('warnings');
Expand Down

0 comments on commit 6613a97

Please sign in to comment.