Skip to content

Commit

Permalink
fix(watchConfig): handle custom config names
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 19, 2023
1 parent b89e50b commit eedd141
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ export async function watchConfig<
let config = await loadConfig<T, MT>(options);

const configName = options.name || "config";
const configFileName =
options.configFile ??
(options.name !== "config" ? `${options.name}.config` : "config");
const watchingFiles = [
...new Set(
(config.layers || [])
.filter((l) => l.cwd)
.flatMap((l) => [
...["ts", "js", "mjs", "cjs", "cts", "mts", "json"].map((ext) =>
resolve(l.cwd!, (options.name || "config") + "." + ext)
resolve(l.cwd!, configFileName + "." + ext)
),
l.source && resolve(l.cwd!, l.source),
// TODO: Support watching rc from home and workspace
Expand Down Expand Up @@ -115,7 +118,7 @@ export async function watchConfig<
};

if (options.debounce !== false) {
_fswatcher.on("all", debounce(onChange, options.debounce));
_fswatcher.on("all", debounce(onChange, options.debounce ?? 100));
} else {
_fswatcher.on("all", onChange);
}
Expand Down

0 comments on commit eedd141

Please sign in to comment.