Skip to content

Commit

Permalink
Prevent optional dependency Chokidar from loading when not watching
Browse files Browse the repository at this point in the history
  • Loading branch information
eklingen committed Oct 15, 2019
1 parent 1485a44 commit cefb1cf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions nunjucks/src/node-loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const path = require('path');
const Loader = require('./loader');
const {PrecompiledLoader} = require('./precompiled-loader.js');
let chokidar;
try {
chokidar = require('chokidar'); // eslint-disable-line global-require
} catch (e) {} // eslint-disable-line no-empty

class FileSystemLoader extends Loader {
constructor(searchPaths, opts) {
Expand Down Expand Up @@ -37,7 +34,9 @@ class FileSystemLoader extends Loader {
if (opts.watch) {
// Watch all the templates in the paths and fire an event when
// they change
if (!chokidar) {
try {
chokidar = require('chokidar'); // eslint-disable-line global-require
} catch (e) {
throw new Error('watch requires chokidar to be installed');
}
const paths = this.searchPaths.filter(fs.existsSync);
Expand Down Expand Up @@ -94,7 +93,9 @@ class NodeResolveLoader extends Loader {
this.noCache = !!opts.noCache;

if (opts.watch) {
if (!chokidar) {
try {
chokidar = require('chokidar'); // eslint-disable-line global-require
} catch (e) {
throw new Error('watch requires chokidar to be installed');
}
this.watcher = chokidar.watch();
Expand Down

0 comments on commit cefb1cf

Please sign in to comment.