From 6ee0d6bfbc7611335adf87920b7d9d4a0ad9872a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 21 Feb 2024 22:25:15 +0100 Subject: [PATCH] feat(automd): expose `unwatch` --- src/automd.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/automd.ts b/src/automd.ts index 9f686b3..1aa1dc4 100644 --- a/src/automd.ts +++ b/src/automd.ts @@ -10,9 +10,12 @@ export interface AutomdResult extends TransformResult { output: string; } -export async function automd( - _config: Config = {}, -): Promise<{ results: AutomdResult[]; _config: ResolvedConfig; time: number }> { +export async function automd(_config: Config = {}): Promise<{ + results: AutomdResult[]; + time: number; + config: ResolvedConfig; + unwatch?: () => void | Promise; +}> { const start = performance.now(); const config = await loadConfig(_config.dir, _config); @@ -39,16 +42,18 @@ export async function automd( inputFiles.map((i) => _automd(i, config, multiFiles, cache)), ); + let unwatch; if (config.watch) { - await _watch(inputFiles, config, multiFiles, cache); + unwatch = await _watch(inputFiles, config, multiFiles, cache); } const time = performance.now() - start; return { - _config: config, time, results, + config, + unwatch, }; } @@ -119,4 +124,6 @@ async function _watch( process.on("SIGINT", () => { subscription.unsubscribe(); }); + + return subscription.unsubscribe; }