Skip to content

Commit

Permalink
实现 set-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
keenwon committed Jun 12, 2018
1 parent e1c1a97 commit bedcb78
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"md5": "^2.2.1",
"minimatch": "^3.0.4",
"semver-utils": "^1.1.2",
"set-blocking": "^2.0.0",
"staged-git-files": "^1.1.1",
"stylelint": "^9.2.0",
"supports-color": "^4",
Expand Down
18 changes: 18 additions & 0 deletions src/utils/set-blocking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

/**
* 强制 stdio 同步输出
* https://github.com/nodejs/node/issues/6456
*
* @param {boolean} blocking 是否同步
* @returns {void}
*/
function setBlocking(blocking) {
[process.stdout, process.stderr].forEach(stream => {
if (stream._handle && typeof stream._handle.setBlocking === 'function') {
stream._handle.setBlocking(blocking);
}
});
}

module.exports = setBlocking;
4 changes: 2 additions & 2 deletions src/works/eslint/eslint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const setBlocking = require('set-blocking');

const result = {
name: 'eslint',
output: '',
Expand All @@ -17,6 +15,8 @@ process.on('uncaughtException', error => {
});

const eslint = require('eslint');
const setBlocking = require('../../utils/set-blocking');

const CLIEngine = eslint.CLIEngine;
const files = process.argv.slice(2);

Expand Down
2 changes: 1 addition & 1 deletion src/works/stylelint/stylelint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const stylelint = require('stylelint');
const setBlocking = require('set-blocking');
const setBlocking = require('../../utils/set-blocking');
const files = process.argv.slice(2);

const result = {
Expand Down

0 comments on commit bedcb78

Please sign in to comment.