Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readline simply doesnt work with babel-watch #35

Closed
azarus opened this issue Dec 8, 2016 · 7 comments
Closed

Readline simply doesnt work with babel-watch #35

azarus opened this issue Dec 8, 2016 · 7 comments

Comments

@azarus
Copy link

azarus commented Dec 8, 2016

Since the watched app runs in a seperate process readline doesn't work, also no stdin is available for the process.

Would it be possible to forward the stdin to the sub process?

Thanks.

@azarus
Copy link
Author

azarus commented Dec 8, 2016

Given the following example


const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('What do you think of Node.js? ', (answer) => {
  // TODO: Log the answer in a database
  console.log(`Thank you for your valuable feedback: ${answer}`);

  rl.close();
});

the output result would be:

babel-node test.js
What do you think of Node.js? test
Thank you for your valuable feedback: test

But the result is:

babel-watch test.js
What do you think of Node.js? test

Note that the readline funciton doesn't call the callback. So the Thank you for your valuable feedback: test is not printed on the screeen..

@azarus
Copy link
Author

azarus commented Dec 8, 2016

I did some research i think this is related to this issue:
nodejs/node-v0.x-archive#1742

@azarus
Copy link
Author

azarus commented Dec 8, 2016

Looks like this code part causes the issue, since its switching the stdin input to the fork and then back to the main process.
const stdin = process.stdin; stdin.setEncoding('utf8'); stdin.on('data', (data) => { if (String(data).trim() === RESTART_COMMAND) { restartApp(); } });

Also applications should not use babel-watch in production, so this should be removed from the code or the all stdin events should be passed to the fork.

@kmagiera
Copy link
Owner

@azarus I think it would be the best to add a new flag that would disable stdin capturing. I know that the most frequent use case for babel watch is to use it with web-based application which does not require to read anything from STDIN, and then it's pretty handy to be able to restart the app from the command line (by typing rs) as it is also something that people using nodemod are familiar with

@aymericbeaumet
Copy link

aymericbeaumet commented Jan 1, 2017

I'm also developing a CLI app with a shell-like prompt, and this is currently not usable. The overhead of listening on process.stdin makes it too laggy for real typing.

Offering a --no-stdin flag sounds reasonable to me 👍

As a temporary solution I have removed those lines from my local node_modules, and everything works fine.

@hmmhmmhm
Copy link

It still same problem exist :(

@itsezc
Copy link

itsezc commented Mar 18, 2019

+1 Still exists

@STRML STRML closed this as completed in 34ab71c Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants