diff --git a/docs/watch-mode.md b/docs/watch-mode.md index d9901163e..a15bcba15 100644 --- a/docs/watch-mode.md +++ b/docs/watch-mode.md @@ -51,3 +51,4 @@ tsx watch --exclude "./data/**/*" ./file.ts - Press Return to manually rerun the script. - Use `--clear-screen=false` to prevent the screen from clearing on rerun. +- Use `--reload-on-keypress=false` to disable reloading on keypress. If your child process uses stdin raw mode, be sure to disable this. diff --git a/src/watch/index.ts b/src/watch/index.ts index 826bce1c3..0379e0554 100644 --- a/src/watch/index.ts +++ b/src/watch/index.ts @@ -45,6 +45,11 @@ const flags = { type: [String], description: 'Paths & globs to exclude from being watched', }, + reloadOnKeypress: { + type: Boolean, + description: 'Reload on keypress (press Return key to manually rerun). Disable if your process uses stdin raw mode.', + default: true, + }, } as const; export const watchCommand = command({ @@ -232,5 +237,7 @@ export const watchCommand = command({ ).on('all', reRun); // On "Return" key - process.stdin.on('data', () => reRun('Return key')); + if (argv.flags.reloadOnKeypress && process.stdin.isTTY) { + process.stdin.on('data', () => reRun('Return key')); + } });