Add --on-return-key flag to conditionally enable Return key listener
Added --on-return-key flag to the watch command for optional Return key press handling.
Updated the command logic to conditionally register process.stdin.on('data') listener based on the flag.
Improved flag description and default behavior in the command configuration.
Note: Enabling --on-return-key may cause issues with concurrently "tsx watch some.ts" when some.ts imports/require process. Specifically, if some.ts includes import mysql from "mysql2" and console.log(mysql), it may block execution at the import statement and not correctly print the content.
You can temporarily resolve this issue by using concurrently -r.
This change allows users to control whether the script should trigger a re-run on Return key press, providing more flexibility in how the watch command operates.
Below is an example demonstrating why the onReturnKey parameter is needed.
> node 2.js
1
2
(waiting for input) aaaaa
log in 2.js
bbbbb
log in 2.js
ccccc
log in 2.js
ddddd
log in 2.js
(waiting for input)
Running 3.js:
node 3.js
1
(there is an extra blank line here)
(blocked, unable to input, Enter has no effect)
Analysis
Running 1.js and 2.js both output correctly.
The process.stdin.on('data',) event causes 2.js to enter a waiting input blocking state after printing.
When running node 3.js, the terminal only outputs 1 and not 2, indicating that execution is stuck at require('process') in 1.js, and the subsequent code does not execute.
Any of the following three actions allow all three files to execute normally:
Remove process.stdin.on('data',) from 2.js
Remove require("process") from 1.js
Change stdio in 3.js to ['inherit', 'inherit', 'inherit'] and remove process.stdin.on('data',)
tsx watch also uses process.stdin.on('data',) (src/watch/index.ts#L219), which is why concurrently "tsx watch xxx.ts" will cause xxx.ts and all its imported modules to be stuck at the require("process") line, with subsequent code not executing.
Add --on-return-key flag to conditionally enable Return key listener
--on-return-key
flag to thewatch
command for optional Return key press handling.process.stdin.on('data')
listener based on the flag.--on-return-key
may cause issues withconcurrently "tsx watch some.ts"
whensome.ts
imports/requireprocess
. Specifically, ifsome.ts
includesimport mysql from "mysql2"
andconsole.log(mysql)
, it may block execution at theimport
statement and not correctly print the content.concurrently -r
.This change allows users to control whether the script should trigger a re-run on Return key press, providing more flexibility in how the
watch
command operates.Below is an example demonstrating why the
onReturnKey
parameter is needed.Create
1.js
:Create
2.js
:Create
3.js
:Here are the execution results:
Running
1.js
:Running
2.js
:Running
3.js
:Analysis
1.js
and2.js
both output correctly.process.stdin.on('data',)
event causes2.js
to enter a waiting input blocking state after printing.node 3.js
, the terminal only outputs1
and not2
, indicating that execution is stuck atrequire('process')
in1.js
, and the subsequent code does not execute.process.stdin.on('data',)
from2.js
require("process")
from1.js
stdio
in3.js
to['inherit', 'inherit', 'inherit']
and removeprocess.stdin.on('data',)
tsx watch
also usesprocess.stdin.on('data',)
(src/watch/index.ts#L219), which is whyconcurrently "tsx watch xxx.ts"
will causexxx.ts
and all its imported modules to be stuck at therequire("process")
line, with subsequent code not executing.