Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): Stop scripts from trying to read user input during install (
#5632) **Summary** Fixes #976. This is a bug fix to the problem where lifecycle scripts that try to go interactive hang yarn installs with no indication as to why. This sets stdin to /dev/null and, on unix-like systems, detaches the process from the terminal making it unable to read /dev/tty. Previously with the spinner enabled was impossible to give input to an interactive script on stdin, because a pipe was kept open from the main yarn process to the child process but it was never written to. Interactive scripts could previously use /dev/tty on unix-likes to bypass this, however the fact that scripts are run in parallel means that if two scripts go interactive in this manner that they'll step on each other. This does not change the behavior if the spinner is disabled. Also added a simple integration test with a blocking install script that times out without the patch. **Test plan** Try running `yarn add semantic-ui`. Hangs without the patch, fails with the patch.
- Loading branch information
Showing
12 changed files
with
239 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
__tests__/fixtures/install/install-blocking-script/blocking/install.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const readline = require('readline'); | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
prompt: 'OHAI> ', | ||
}); | ||
|
||
rl.prompt(); | ||
|
||
rl | ||
.on('line', line => { | ||
switch (line.trim()) { | ||
case 'hello': | ||
console.log('world!'); | ||
break; | ||
default: | ||
console.log(`Say what? I might have heard '${line.trim()}'`); | ||
break; | ||
} | ||
rl.prompt(); | ||
}) | ||
.on('close', () => { | ||
console.log('Have a great day!'); | ||
process.exit(0); | ||
}); |
7 changes: 7 additions & 0 deletions
7
__tests__/fixtures/install/install-blocking-script/blocking/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "blocking", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"install": "node install.js" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
__tests__/fixtures/install/install-blocking-script/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"blocking": "file:blocking" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.