Skip to content

Stop watch process when process.stdin ends closes #1753 #1754

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

Closed
wants to merge 3 commits into from

Conversation

wmonk
Copy link

@wmonk wmonk commented Mar 7, 2017

What has been done

  • When process.stdin fires an end event, the process exits with a 0 exit code

How has this been tested

  • Started the app normally ✅
  • Started the app when another app was already running (chose a new port) ✅
  • Started the app via phoenix ✅

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@gaearon
Copy link
Contributor

gaearon commented Mar 7, 2017

Should this also happen for build and test?
Could you explain more about what resume() does?

@wmonk
Copy link
Author

wmonk commented Mar 7, 2017

I don't think this needs to happen for build and test, both of those scripts will exit once they've finished processing.

To be honest, i'm not 100% familiar with what resume(), but has been used by all other mentioned projects to enable this behaviour. From what I have read, it essentially starts reading from the stdin stream, which it doesn't do automatically unless you explicitly call process.stdin.on('data', callback). You can test it with:

$ echo "{ foo: 'bar' }" | node -e 'process.stdin.on("data", d => console.log(d.toString()))'
// { foo: 'bar' }

$ echo "{ foo: 'bar' }" | node -e 'process.stdin.on("end", () => console.log("hello world"))'
// 

$ echo "{ foo: 'bar' }" | node -e 'process.stdin.on("end", () => console.log("hello world")); process.stdin.resume()'
// hello world

@gaearon
Copy link
Contributor

gaearon commented Mar 7, 2017

I don't think this needs to happen for build and test, both of those scripts will exit once they've finished processing.

True for build, but test runs a watcher by default.

@wmonk
Copy link
Author

wmonk commented Mar 7, 2017

@gaearon have just tested this, and you are right, the test process hangs around.

@@ -42,6 +42,11 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1);
}

process.stdin.on('end', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment here (and in the other file) explaining what this does and linking to the issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth toggling this with an env var? Webpack uses --stdin to turn this behaviour on - although testing worked fine, I don't want to inadvertently break some other scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we break we'll learn from that. I think it's fine to start with on by default in the next major (technically minor since we're in 0.x), and see what breaks.

@@ -44,3 +44,8 @@ argv.push(
);
// @remove-on-eject-end
jest.run(argv);

process.stdin.on('end', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to only do this in non-CI mode. Move this into if statement below plz.

@wmonk wmonk force-pushed the handle-process-stdin branch from 13d6686 to 14784ae Compare March 8, 2017 08:24
@ianmcnally
Copy link
Contributor

ianmcnally commented Mar 8, 2017

Design/style Q: would it make sense to make a helper, since this code is duplicated across two files?

Like:

// in a new dev script

function addExitHandlersToProcess(process) {
  process.stdin.on('end', function() {
    process.exit(0);
  });
  process.stdin.resume();
  }
}

And call it in start.js and test.js. Along with cutting down duplication, it would add some self-documentation.

@gaearon
Copy link
Contributor

gaearon commented Mar 8, 2017

We could put it in react-dev-utils I guess, like we do with other helpers. Then this doesn't need to live in user projects after ejecting.

@gaearon
Copy link
Contributor

gaearon commented Mar 9, 2017

For some reason this breaks the CI.

@Kjir Kjir mentioned this pull request Oct 25, 2017
@gaearon
Copy link
Contributor

gaearon commented Jan 9, 2018

I’m open to getting this in, but the CI needs to pass.

@gaearon gaearon closed this Jan 9, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants