Open lorefnon opened 1 year ago
Does tsx watch --clear-screen=false
work for you? (from https://github.com/esbuild-kit/tsx/pull/23)
This is not quite what I wanted though - it prevents the screen from clearing up which is good, but it still restarts the server which I don't want to happen.
I am proposing a similar flag which prevents the restart as well.
I also find this behavior non intuitive. I have attempted to address this in https://github.com/esbuild-kit/tsx/pull/220.
Instead of disabling it completely, I prefer to change it so there's a better way to trigger a reload manually. Do you know what nodemon does?
nodemon supports rs<enter>
for restarting the server.
Typing in multiple characters as a command seems confusing to me and would interfere with stdin (https://github.com/esbuild-kit/tsx/issues/163).
Ctrl+R
is generally used for reverse search outside of a process, but I wonder if we can leverage it to trigger a reload inside of tsx.
@nirajsavaika Would you mind experimenting in your PR?
While I'm sure a better solution will be available at some point, for others who reach here looking for a solution to disable restart-on-enter conveniently, here is a simple alternative:
echo "" | npx tsx watch some-script.ts
What about little restarting delay with signals counter? Like two or more 'enter' signals per 500ms shouln't cause restart.
Manually reload watch via Ctrl+r
Listening to Ctrl+r
seems to require putting stdin in "raw mode" (process.stdin.setRawMode(true)
), which disables all native shortcuts like Ctrl+c
. Without raw mode, detecting any input requires the user "send" the input by pressing Enter. Perhaps this is why Nodemon's manual reload also requires Enter at the end (rs<Enter>
).
When also tackling https://github.com/esbuild-kit/tsx/issues/163, seems like listening to stdin at all (process.stdin.on()
) could block or interfere with the child process correctly receiving stdin. And there's no way to passively listen to the stdin (even with a sibling process).
This may explain why Node.js hasn't implemented a manual way to reload watch (https://github.com/nodejs/node/issues/50212). Perhaps it's also worth considering to remove the manual reload feature or watch feature completely as Node.js already has it and it's not really related to TypeScript.
Any help & input would be appreciated!
I found another workaround to disable restart-on-enter, just by pressing Ctrl + d, which will close the stdin. It's an alternative to @lorefnon solution
It's way too easy to accidentally reload dev servers right now.
Feature request
Thanks for developing and maintaining this library. Would you be open to adding a flag to disable the restart on return behavior when running in watch mode ?
Why?
When server generates a lot of logs, I often use returns to create a visual gap between past output and next output before performing some action so that it is easier to see eg. what all db queries were executed as part of a specific request handling.
I don't mind manually restarting through
Ctrl+c ctrl+p enter
but every now and then I find myself accidentally restarting server when trying to add some vertical space in console output out of muscle memory.