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

Prevent optional dependency Chokidar from loading when not watching #1250

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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