tsx
tsx copied to clipboard
Can't use stdin in watch mode
Bug description
What did you do? (Provide reproduction code in next section)
Run npx tsx watch
for console app
What did you expect to happen? I was expecting the ability to enter text into the console
What happened instead? Entering text into the console starts rerun
Do you have an error stack-trace or screenshots?
Reproduction
index.ts:
import { createInterface } from 'readline'
const rl = createInterface({
input: process.stdin,
output: process.stdout,
})
rl.on('line', async (line) => {
console.log(line)
rl.prompt()
})
command: npx tsx watch --clear-screen=false ./index.ts
Environment
System: OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish) CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz Shell: 5.1.16 - /bin/bash Binaries: Node: v18.12.1 npm: 9.2.0 npmPackages: tsx: ^3.12.1 => 3.12.1
Can you contribute a fix?
- [ ] I’m interested in opening a pull request for this issue.
We can fix this in a breaking change release by removing https://github.com/esbuild-kit/tsx/blob/be0478990305fc0052d9c6c982a20d3990658cc2/src/watch/index.ts#L166
but tsx would need another way to manually reload watch.
Will have to look into how other watchers handle this.
+1
Why did you do that 😢 ?
We can fix this in a breaking change release by removing
https://github.com/esbuild-kit/tsx/blob/be0478990305fc0052d9c6c982a20d3990658cc2/src/watch/index.ts#L166
but tsx would need another way to manually reload watch.
Will have to look into how other watchers handle this.
To avoid breaking change, a command line option to disable this feature could be added. --no-keyboard-rerun
for example ?
I’m having the same issue. Would the extra command line option be acceptable? If so, I can work on a PR
For now, I'm open to a breaking change PR so we can agree on an end-goal. Then, another PR to back-port that to the current major version behind a flag to avoid breaking change.
I actually think the --no-keyboard-rerun
is a good option in general, not just to avoid the breaking change.
If we did want an option for manual reloads, I know for example nodemon manual reloads on rs+enter, but technically even that keyboard combination could be problematic for CLI apps and full ctrl+c manual restart doesn't seem so bad to me. So opting out of keyboard rerun behavior with the extra CLI option seems flexible enough. What are your thoughts?
Ah I see this PR implements the flag and would work for the CLI app use case and is non-breaking. Can we start with that and add a manual reload option in a future PR?
- https://github.com/esbuild-kit/tsx/pull/220
I'm so frustrated to restart manually :(
Was there any solution for this, its very frustrating, I wanted to use tsx with inquirer but anytime i input anything in the terminal, it restarts
My health is safe, I have changed for the experimental node watch mode + ts-node:
node --trace-deprecation --abort-on-uncaught-exception --watch -r ts-node/register index.ts
Hacky solution:
cd my-project
sed -i.bak 's/process.stdin.on/void/' node_modules/tsx/dist/cli.mjs
sed -i.bak 's/process.stdin.on/void/' node_modules/tsx/dist/cli.cjs
Should work in both bash and cmd (assuming sed is there, e.g. through msys2).
Nodemon's rs<enter>
may seem half-baked, but in practice you can avoid typing it in console at watch/dev time. It boils down to this:
- You type
rs<enter>
as a test input and remember to type something else next time - You have
rs<enter>
as a sort of a manually-entered fixed/enum value and either:- Resort to another char combination for it
- Or go much more complex route of replacing/avoiding your dev tools
The issue is acknowledged, and the next steps are outlined above. PR contributions are welcome.
To maintain focus, I'm locking this thread but encourage constructive dialogue through PRs.