Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Optimize compilation events to prevent unneeded stats.toJson() call (#…
Browse files Browse the repository at this point in the history
…182)

* Optimize compilation events to prevent unneeded stats.toJson() call

* Switch fron nanobus to EventEmitter to fix tests

Per nanobus documentation:
> ### When shouldn't I use this package?
> If you're only writing code that runs inside Node and don't need a '*' listener, consider using the built-in event emitter API instead.

* Remove nanobus dependency

* Revert "Remove nanobus dependency"

This reverts commit 92fca9e.

* Revert "Switch fron nanobus to EventEmitter to fix tests"

This reverts commit 55fef9f.

* Address comments

Some tests are timing out locally, but I can't figure out why. Maybe it's just an issue on my box?

* chore: save result of hasErrors/Warnings, remove event name const

note: the event name object const(s) really weren't needed as the event
names only appear twice each.
  • Loading branch information
MLoughry authored and shellscape committed Jun 20, 2018
1 parent 012ab60 commit 416f414
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,23 @@ module.exports = (opts) => {
});

comp.hooks.done.tap('WebpackServe', (stats) => {
const json = stats.toJson();
if (stats.hasErrors()) {
bus.emit('compiler-error', { json, compiler: comp });
}

if (stats.hasWarnings()) {
bus.emit('compiler-warning', { json, compiler: comp });
const hasErrors = stats.hasErrors();
const hasWarnings = stats.hasWarnings();
// stats.toJson() has a high time-cost for large projects
// only run that if there are listeners AND there are
// problems with the build (#181)
if (
(bus.listeners('compiler-error').length && hasErrors) ||
(bus.listeners('compiler-warning').length && hasWarnings)
) {
const json = stats.toJson();
if (hasErrors) {
bus.emit('compiler-error', { json, compiler: comp });
}

if (hasWarnings) {
bus.emit('compiler-warning', { json, compiler: comp });
}
}

bus.emit('build-finished', { stats, compiler: comp });
Expand Down

0 comments on commit 416f414

Please sign in to comment.