Skip to content

Commit

Permalink
Made node-notifier dependency optional
Browse files Browse the repository at this point in the history
  • Loading branch information
geowarin committed Aug 8, 2016
1 parent 8930083 commit 1b22671
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
24 changes: 12 additions & 12 deletions lib/utils/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ class Debugger {
this.enabled = true;
}

capture () {
this.enabled = true;
this.capturing = true;
}

endCapture () {
this.enabled = false;
this.capturing = false;
this.capturedMessages = [];
}

log (...args) {
if (this.enabled) {
this.captureConsole(args, console.log);
Expand All @@ -36,13 +47,8 @@ class Debugger {
}
}

capture () {
this.enabled = true;
this.capturing = true;
}

clearConsole () {
if (!this.capturing) {
if (!this.capturing && this.enabled) {
process.stdout.write('\x1bc');
}
}
Expand All @@ -66,12 +72,6 @@ class Debugger {
return e;
})
}

endCapture () {
this.enabled = false;
this.capturing = false;
this.capturedMessages = [];
}
}

module.exports = new Debugger();
17 changes: 9 additions & 8 deletions lib/webpack/plugins/notifier.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
const path = require('path');
const chalk = require('chalk');
const os = require('os');
const notifier = require('node-notifier');
const formatMessage = require('./formatMessage');
const debug = require('../../utils/debug');

function safeRequire (moduleName) {
try {
return require(moduleName);
} catch (ignored) {}
}

const LOGO = path.join(__dirname, 'tarec_logo_ico.png');

class NotifierPlugin {

constructor ({notificationTitle, compilationSuccessMessage, showNotifications}) {
this.notificationTitle = notificationTitle;
this.compilationSuccessMessage = compilationSuccessMessage;
this.showNotifications = showNotifications;
this.notifier = showNotifications && safeRequire('node-notifier');
}

notify (serverity, error) {
notifier.notify({
this.notifier.notify({
title: this.notificationTitle,
message: serverity + ': ' + error.name,
subtitle: error.file || '',
icon: LOGO
// wait: true
});
// .on('click', () => {
// console.log(error.file);
// });
}

apply (compiler) {
Expand All @@ -49,7 +50,7 @@ class NotifierPlugin {
const nbErrors = formattedErrors.length;
displayCompilationMessage(`Failed to compile with ${nbErrors} errors`, 'red');

if (this.showNotifications) {
if (this.notifier) {
this.notify('Error', formattedErrors[0]);
}
formattedErrors.forEach((error, index) => displayError(index, 'Error', error));
Expand Down
2 changes: 1 addition & 1 deletion test/Command.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const addBuiltInCommands = require('../lib/commands/addBuiltInCommands');
const test = require('ava');
const debug = require('../lib/utils/debug');

test('should add built-in commands', t => {
test('commands: should add built-in commands', t => {
const commands = new Commands();
addBuiltInCommands(commands);

Expand Down
6 changes: 2 additions & 4 deletions test/loadUserConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const os = require('os');

test('config : should parse config', () => {
process.env['ENV_VAR'] = 'http://localhost:8181';
const projectDir = path.resolve('fixtures/config/fullConfig.yml');
const userConfig = loadUserConfig(projectDir);
const userConfig = loadUserConfig(path.resolve('fixtures/config/fullConfig.yml'));

expect(userConfig.happypack).toEqual({
enabled: true,
Expand All @@ -32,8 +31,7 @@ test('config : should parse config', () => {
});

test('config : should parse empty config', () => {
const projectDir = path.resolve('fixtures/config/emptyConfig.yml');
const userConfig = loadUserConfig(projectDir);
const userConfig = loadUserConfig(path.resolve('fixtures/config/emptyConfig.yml'));

expect(userConfig.happypack).toEqual({
enabled: false,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/webpackConfigs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('webpack : dev config should handle dlls', t => {
expect(devConfig).toHavePlugin('AddAssetHtmlPlugin', expectedAssetPluginOptions);
});

test('webpack : happyPack', () => {
test('webpack : dev config should configure happyPack', () => {

const context = createMinimalContext();
context.dlls = [];
Expand Down

0 comments on commit 1b22671

Please sign in to comment.