Show specific error message when chokidar can't be loaded

This commit is contained in:
Joshua Peek 2016-02-01 19:24:08 -08:00
parent f81d9e1274
commit 005c4cb7a8
3 changed files with 11 additions and 2 deletions

View File

@ -64,7 +64,7 @@ module.exports = function (commander, filenames) {
_.each(filenames, handle);
if (commander.watch) {
let chokidar = require("chokidar");
let chokidar = util.requireChokidar();
_.each(filenames, function (dirname) {
let watcher = chokidar.watch(dirname, {

View File

@ -132,7 +132,7 @@ module.exports = function (commander, filenames, opts) {
walk();
if (commander.watch) {
let chokidar = require("chokidar");
let chokidar = util.requireChokidar();
chokidar.watch(filenames, {
persistent: true,
ignoreInitial: true

View File

@ -71,3 +71,12 @@ process.on("uncaughtException", function (err) {
console.error(toErrorStack(err));
process.exit(1);
});
export function requireChokidar() {
try {
return require("chokidar");
} catch (err) {
console.error("The optional dependency chokidar failed to install and is required for --watch. Chokidar is likely not supported on your platform.")
throw err;
}
}