Add --on-return-key flag to conditionally enable Return key listener #639
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
:> node 1.js 1 2 (program ends)
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.