From 15c298995ff81e010c144d200f111a218d7e11b5 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Thu, 3 Sep 2026 15:22:02 -0400 Subject: [PATCH] Handle multiple config files in watch mode Also optimized recompile list computation --- index.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index f45e29d..6319325 100755 --- a/index.js +++ b/index.js @@ -37,7 +37,8 @@ const { dir, output, replace } = argv if (argv.map) argv.map = { inline: false } -let configFile +// will be just one config file in the vast majority of cases +const configFiles = new Set() let argvConfigSet = false if (argv.env) process.env.NODE_ENV = argv.env @@ -127,20 +128,23 @@ try { }, }) - if (configFile) watcher.add(configFile) + if (configFiles.size) watcher.add([...configFiles]) watcher.on('ready', printMessage).on('change', (file) => { let recompile = [] - if (input.includes(file)) recompile.push(file) + // if it's a config file, skip to recompiling everything + if (!configFiles.has(file)) { + if (input.includes(file)) recompile.push(file) - const dependants = depGraph - .dependantsOf(file) - .concat(getAncestorDirs(file).flatMap(depGraph.dependantsOf)) + const dependants = depGraph + .dependantsOf(file) + .concat(getAncestorDirs(file).flatMap(depGraph.dependantsOf)) - recompile = recompile.concat( - dependants.filter((file) => input.includes(file)), - ) + recompile = recompile.concat( + dependants.filter((file) => input.includes(file)), + ) + } if (!recompile.length) recompile = input @@ -168,7 +172,7 @@ function rc(ctx, path) { 'Config Error: Can not set from or to options in config file, use CLI arguments instead', ) } - configFile = rc.file + configFiles.add(rc.file) return rc }) .catch((err) => {