Skip to content

Commit d0ea3fa

Browse files
committed
fix(watch): Wait for user command to close before restarting
1 parent f46a2bb commit d0ea3fa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/commands/watch.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ function watch(path: string, command: string, options: {
2323
terminate?: boolean
2424
}) {
2525
let childProcess: ChildProcess;
26+
const runCommand = (file: string) => {
27+
childProcess = exec(command.replace(/\[path\]/gi, file), (error, stdout) => {
28+
error?.killed || console.log(error ?? stdout);
29+
});
30+
}
2631
getFiles(path, {
2732
recursive: options.recursive,
2833
ignore: options.ignore,
2934
}).forEach((file) => {
3035
chokidar.watch(file)
3136
.on('change', () => {
3237
!options.terminate || childProcess?.kill();
33-
childProcess = exec(command.replace(/\[path\]/gi, file), (error, stdout) => {
34-
error?.killed || console.log(error ?? stdout);
35-
});
38+
childProcess?.on('close', () => {
39+
runCommand(file);
40+
}) ?? runCommand(file);
3641
});
3742
});
3843
}

0 commit comments

Comments
 (0)