privatenumber / tsx

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

Add --on-return-key flag to conditionally enable Return key listener #639

Closed iuroc closed 2 months ago

iuroc commented 3 months ago

Add --on-return-key flag to conditionally enable Return key listener

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:

console.log(1)

require('process')

console.log(2)

Create 2.js:

const { spawn } = require('child_process')

spawn('node', ['1.js'], {
    stdio: ['inherit', 'inherit', 'inherit'],
    shell: true
})
process.stdin.on('data', () => {
    console.log('log in 2.js')
})

Create 3.js:

const { spawn } = require('child_process')

const child = spawn('node', ['2.js'], {
    stdio: ['pipe', 'pipe', 'pipe'],
    shell: true
})
child.stdout.on('data', chunk => {
    console.log(chunk.toString())
})

Here are the execution results:

Running 1.js:

> node 1.js
1
2
(program ends)

Running 2.js:

> 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

kermitsxb commented 2 months ago

How is this PR going ? I'm interested in using tsx in my CLI development process

privatenumber commented 2 months ago

This is a breaking change so it can't be released until the next major. But also, this work is already queued for v5. This PR was made without a heads up. The timeline for v5 is not known yet.

If you use tsx, the best way to get more development on it is to fund it. Currently, it barely gets funding so I struggle to justify investing more time into it.

iuroc commented 2 months ago

I understand your point, and this is indeed a breaking change that needs to wait for the next major release. However, this change is currently causing issues when used alongside concurrently, so I'll have to find an alternative workaround until v5 is released.

kermitsxb commented 2 months ago

@privatenumber thank you for your answer, I totally understand your point.