privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.72k stars 152 forks source link

Change watch reload command from Return key #215

Open lorefnon opened 1 year ago

lorefnon commented 1 year ago

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.

privatenumber commented 1 year ago

Does tsx watch --clear-screen=false work for you? (from https://github.com/esbuild-kit/tsx/pull/23)

lorefnon commented 1 year ago

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.

nirajsavaika commented 1 year ago

I also find this behavior non intuitive. I have attempted to address this in https://github.com/esbuild-kit/tsx/pull/220.

privatenumber commented 1 year ago

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?

lorefnon commented 1 year ago

nodemon supports rs<enter> for restarting the server.

privatenumber commented 1 year ago

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?

lorefnon commented 1 year ago

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
npdev453 commented 1 year ago

What about little restarting delay with signals counter? Like two or more 'enter' signals per 500ms shouln't cause restart.

privatenumber commented 1 year ago

Ideal solution

Manually reload watch via Ctrl+r

Problems

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!

np42 commented 9 months ago

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

net commented 5 months ago

It's way too easy to accidentally reload dev servers right now.