Skip to content

Commit 61e402b

Browse files
authored
Fix: avoid using process.exit() when possible (#3955)
**Summary** Refs #3524. We are using `process.exit()` pretty liberally although it is [strongly advised not to use it](https://nodejs.org/api/process.html#process_process_exit_code) since it may cause the `stdout` to get corrupted/terminated before a full flush. This patch changes all possible `process.exit(code)` calls with `process.exitCode = code` statements. We'd also ideally enable [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule in ESLint but it requires an upgrade to ESLint v4 which should be handled separately. **Test plan** Expect tests to pass and actually finish (not run indefinitely due to `yarn` not exiting at all). Also, the script referenced in #3524 to output something like the following: ``` DATA 18 DATA 8192 DATA 8192 DATA 5392 DATA 15 EXIT 0 ```
1 parent fa0fb69 commit 61e402b

File tree

5 files changed

+335
-308
lines changed

5 files changed

+335
-308
lines changed

bin/yarn-bundle-entry.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55

66
require('../lib/v8-compile-cache');
77
module.exports = require('../lib/yarn-cli');
8+
const main = module.exports.default;
9+
10+
// ignore all arguments after a --
11+
const doubleDashIndex = process.argv.findIndex(element => element === '--');
12+
const startArgs = process.argv.slice(0, 2);
13+
const args = process.argv.slice(2, doubleDashIndex === -1 ? process.argv.length : doubleDashIndex);
14+
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex + 1, process.argv.length);
15+
16+
main({startArgs, args, endArgs});

bin/yarn.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ var constants = require(dirPath + '/constants');
3131
mkdirp.sync(constants.MODULE_CACHE_DIRECTORY);
3232

3333
module.exports = require(dirPath + '/cli');
34+
const main = module.exports.default;
35+
36+
// ignore all arguments after a --
37+
const doubleDashIndex = process.argv.findIndex(element => element === '--');
38+
const startArgs = process.argv.slice(0, 2);
39+
const args = process.argv.slice(2, doubleDashIndex === -1 ? process.argv.length : doubleDashIndex);
40+
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex + 1, process.argv.length);
41+
42+
main({startArgs, args, endArgs});

scripts/build-webpack.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const compiler = webpack({
3535
output: {
3636
filename: `yarn-${version}.js`,
3737
path: path.join(basedir, 'artifacts'),
38+
library: 'yarn-cli',
39+
libraryTarget: 'commonjs2',
3840
},
3941
target: 'node',
4042
});
@@ -71,6 +73,8 @@ const compilerLegacy = webpack({
7173
output: {
7274
filename: `yarn-legacy-${version}.js`,
7375
path: path.join(basedir, 'artifacts'),
76+
library: 'yarn-cli',
77+
libraryTarget: 'commonjs2',
7478
},
7579
target: 'node',
7680
});

0 commit comments

Comments
 (0)