From cc9ad10d049f1053bba8004df557358481ff6608 Mon Sep 17 00:00:00 2001 From: Julian Lloyd Date: Wed, 6 Feb 2019 15:47:53 -0800 Subject: [PATCH] Validate Karma config before starting watcher Fixes #45 --- lib/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 11de89c..b1a9846 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,7 +7,11 @@ const Watcher = require("./Watcher"); function createPreprocessor(preconfig, config, emitter, logger) { const cache = new Map(); const log = logger.create("preprocessor.rollup"); - const watcher = new Watcher(emitter); + + let watcher; + if (!config.singleRun && config.autoWatch) { + watcher = new Watcher(emitter); + } return async function preprocess(original, file, done) { const location = path.relative(config.basePath, file.path); @@ -25,8 +29,10 @@ function createPreprocessor(preconfig, config, emitter, logger) { const bundle = await rollup.rollup(options); cache.set(file.path, bundle.cache); - const [entry, ...dependencies] = bundle.watchFiles; - watcher.add(entry, dependencies); + if (watcher) { + const [entry, ...dependencies] = bundle.watchFiles; + watcher.add(entry, dependencies); + } log.info("Generating bundle for ./%s", location); const { output } = await bundle.generate(options);