Skip to content

Commit

Permalink
Merge pull request #275 from benjarwar/feature/overlay-warnings
Browse files Browse the repository at this point in the history
Feature/overlay warnings
  • Loading branch information
glenjamin committed Mar 16, 2018
2 parents 8984fa2 + 2e8da50 commit b0af1f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -93,9 +93,10 @@ Configuration options can be passed to the client by adding querystring paramete
* **autoConnect** - Set to `false` to use to prevent a connection being automatically opened from the client to the webpack back-end - ideal if you need to modify the options using the `setOptionsAndConnect` function
* **ansiColors** - An object to customize the client overlay colors as mentioned in the [ansi-html](https://github.com/Tjatse/ansi-html/blob/99ec49e431c70af6275b3c4e00c7be34be51753c/README.md#set-colors) package.
* **overlayStyles** - An object to let you override or add new inline styles to the client overlay div.
* **overlayWarnings** - Set to `true` to enable client overlay on warnings in addition to errors.

> Note:
> Since the `ansiColors` and `overlaySyles` options are passed via query string, you'll need to uri encode your stringified options like below:
> Since the `ansiColors` and `overlayStyles` options are passed via query string, you'll need to uri encode your stringified options like below:
```js
var ansiColors = {
Expand Down
17 changes: 11 additions & 6 deletions client.js
Expand Up @@ -11,6 +11,7 @@ var options = {
name: '',
autoConnect: true,
overlayStyles: {},
overlayWarnings: false,
ansiColors: {}
};
if (__resourceQuery) {
Expand Down Expand Up @@ -62,6 +63,10 @@ function setOverrides(overrides) {

if (overrides.ansiColors) options.ansiColors = JSON.parse(overrides.ansiColors);
if (overrides.overlayStyles) options.overlayStyles = JSON.parse(overrides.overlayStyles);

if (overrides.overlayWarnings) {
options.overlayWarnings = overrides.overlayWarnings == 'true';
}
}

function EventSourceWrapper() {
Expand Down Expand Up @@ -200,7 +205,9 @@ function createReporter() {
if (options.warn) {
log(type, obj);
}
if (overlay && type !== 'warnings') overlay.showProblems(type, obj[type]);
if (overlay && (options.overlayWarnings || type !== 'warnings')) {
overlay.showProblems(type, obj[type]);
}
},
success: function() {
if (overlay) overlay.clear();
Expand Down Expand Up @@ -239,13 +246,11 @@ function processMessage(obj) {
}
if (obj.errors.length > 0) {
if (reporter) reporter.problems('errors', obj);
} else if (obj.warnings.length > 0) {
if (reporter) reporter.problems('warnings', obj);
} else {
if (reporter) {
if (obj.warnings.length > 0) {
reporter.problems('warnings', obj);
} else {
reporter.cleanProblemsCache();
}
reporter.cleanProblemsCache();
reporter.success();
}
processUpdate(obj.hash, obj.modules, options);
Expand Down

0 comments on commit b0af1f9

Please sign in to comment.