Skip to content

Commit a078545

Browse files
committed
Use a flag to watch stdin
The kitchensink e2e tests were failing because in those tests the `npm start` command is sent to the background. The shell will then halt any background job that tries to read from the standard input, and since we are watching standard input to determine if we should exit or not the dev server would immediately exit. The workaround is to provide run the dev-server as `npm start </dev/zero &` instead, which provides a different standard input that will not close immediately. This, alas, doesn't work on Windows and might change the expected behaviour for some people that are used to start the dev-server as a background job. For this reason a --watch-stdin flag has been added to only enable this behaviour on request for the few applicable use cases. A note has also been added in the Troubleshooting section to help any final user that might start the dev-server as a background job.
1 parent a01f754 commit a078545

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

packages/react-dev-utils/addProcessExitHandlers.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77

88
'use strict';
99

10-
function addProcessExitHandlers() {
10+
function addProcessExitHandlers(argv) {
1111
// Issue: https://github.com/facebookincubator/create-react-app/issues/1753
1212
// The below lines are added to make sure that this process is
1313
// exited when stdin is ended. The consequence of not doing this means
1414
// that all watch processes will stay running despite the process that spawned
1515
// them being closed.
16-
process.stdin.on('end', function() {
17-
process.exit(0);
18-
});
19-
process.stdin.resume();
16+
argv = argv || process.argv;
17+
const watchStdinIndex = argv.indexOf('--watch-stdin');
18+
const shouldWatchStdin = watchStdinIndex > -1;
19+
if (shouldWatchStdin) {
20+
argv.splice(watchStdinIndex, 1);
21+
process.stdin.on('end', function() {
22+
process.exit(0);
23+
});
24+
process.stdin.resume();
25+
}
2026
}
2127

2228
module.exports = addProcessExitHandlers;

packages/react-scripts/config/webpack.config.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ module.exports = {
301301
},
302302
mangle: {
303303
safari10: true,
304-
},
304+
},
305305
output: {
306306
comments: false,
307307
// Turned on because emoji and regex is not minified properly using default

packages/react-scripts/scripts/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const argv = process.argv.slice(2);
3232
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
3333
argv.push('--watch');
3434

35-
addProcessExitHandlers();
35+
addProcessExitHandlers(argv);
3636
}
3737

3838
// @remove-on-eject-begin

packages/react-scripts/template/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -2218,12 +2218,22 @@ To resolve this:
22182218
1. Open an issue on the dependency's issue tracker and ask that the package be published pre-compiled.
22192219
* Note: Create React App can consume both CommonJS and ES modules. For Node.js compatibility, it is recommended that the main entry point is CommonJS. However, they can optionally provide an ES module entry point with the `module` field in `package.json`. Note that **even if a library provides an ES Modules version, it should still precompile other ES6 features to ES5 if it intends to support older browsers**.
22202220

2221-
2. Fork the package and publish a corrected version yourself.
2221+
2. Fork the package and publish a corrected version yourself.
22222222

22232223
3. If the dependency is small enough, copy it to your `src/` folder and treat it as application code.
22242224

22252225
In the future, we might start automatically compiling incompatible third-party modules, but it is not currently supported. This approach would also slow down the production builds.
22262226

2227+
### Phoenix doesn't kill the webpack-dev-server
2228+
2229+
When using create-react-app in a Phoenix application, the webpack-dev-server is not closed automatically if it's configured as a watcher. This is because Phoenix expects the watchers to close when the standart input is closed.
2230+
2231+
To watch for standart input you can pass the `--watch-stdin` option:
2232+
2233+
```
2234+
npm start -- --watch-stdin
2235+
```
2236+
22272237
## Something Missing?
22282238

22292239
If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebookincubator/create-react-app/issues) or [contribute some!](https://github.com/facebookincubator/create-react-app/edit/master/packages/react-scripts/template/README.md)

0 commit comments

Comments
 (0)