Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/blocking notifications #47

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

#### 1.1.2
###### _September 12, 2019_

- Changed compilation done hook to async to fix #43.

#### 1.1.1
###### _August 29, 2019_

Expand Down
26 changes: 18 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* A Webpack plugin that generates OS notifications for build steps using node-notifier.
*/
var path = require('path');
var process = require('process');
var os = require('os');
var notifier = require('node-notifier');
var stripAnsi = require('strip-ansi');
var exec = require('child_process').exec;

const IS_WINDOWS = os.platform() === 'win32';

// ensure the SnoreToast appId is registered, which is needed for Windows Toast notifications
// this is necessary in Windows 8 and above, (Windows 10 post build 1709), where all notifications must be generated
// by a valid application.
// see: https://github.com/KDE/snoretoast, https://github.com/RoccoC/webpack-build-notifier/issues/20
var appName;
if (process.platform === 'win32') {
var os = require('os');
if (IS_WINDOWS) {
var versionParts = os.release().split('.');
var winVer = +(`${versionParts[0]}.${versionParts[1]}`)
if (winVer >= 6.2) {
Expand Down Expand Up @@ -231,7 +231,7 @@ WebpackBuildNotifierPlugin.prototype.onCompilationWatchRun = function (compilati
callback();
};

WebpackBuildNotifierPlugin.prototype.onCompilationDone = function (results) {
WebpackBuildNotifierPlugin.prototype.onCompilationDone = function (results, callback) {
var notify,
title = this.title + ' - ',
msg = 'Build successful!',
Expand Down Expand Up @@ -280,16 +280,26 @@ WebpackBuildNotifierPlugin.prototype.onCompilationDone = function (results) {
wait: !buildSuccessful
})
);
if (onComplete) {
onComplete(results.compilation, compilationStatus);
}
}

if (this.activateTerminalOnError && !buildSuccessful) {
this.activateTerminalWindow();
}

hasRun = true;

if (typeof callback === 'function') {
if (IS_WINDOWS) {
// workaround for #43 to ensure notifications are dispatched
setTimeout(() => callback(), 10);
} else {
callback();
}
}

if (onComplete) {
onComplete(results.compilation, compilationStatus);
}
};

WebpackBuildNotifierPlugin.prototype.apply = function (compiler) {
Expand All @@ -298,7 +308,7 @@ WebpackBuildNotifierPlugin.prototype.apply = function (compiler) {
if (!this.suppressCompileStart) {
compiler.hooks.watchRun.tapAsync('webpack-build-notifier', this.onCompilationWatchRun.bind(this));
}
compiler.hooks.done.tap('webpack-build-notifier', this.onCompilationDone.bind(this));
compiler.hooks.done.tapAsync('webpack-build-notifier', this.onCompilationDone.bind(this));
} else {
// for webpack < 4
if (!this.suppressCompileStart) {
Expand Down
Loading