-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented shim for stream._handle.setBlocking
- Loading branch information
Benjamin Coe
committed
May 14, 2016
0 parents
commit 6bde0c0
Showing
8 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.DS_Store | ||
.nyc_output |
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,14 @@ | ||
Copyright (c) 2016, Contributors | ||
|
||
Permission to use, copy, modify, and/or distribute this software | ||
for any purpose with or without fee is hereby granted, provided | ||
that the above copyright notice and this permission notice | ||
appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE | ||
LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES | ||
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | ||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | ||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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,18 @@ | ||
# set-blocking | ||
|
||
[](https://travis-ci.org/yargs/set-blocking) | ||
[](https://www.npmjs.com/package/set-blocking) | ||
[](https://coveralls.io/r/yargs/set-blocking?branch=master) | ||
[](https://github.com/conventional-changelog/standard-version) | ||
|
||
set blocking `stdio` and `stderr` ensuring that terminal output does not truncate | ||
|
||
```js | ||
const setBlocking = require('set-blocking') | ||
setBlocking(true) | ||
console.log(someLargeStringToOutput) | ||
``` | ||
|
||
## License | ||
|
||
ISC |
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 @@ | ||
module.exports = function (blocking) { | ||
[process.stdout, process.stderr].forEach(function(stream){ | ||
if (stream._handle && typeof stream._handle.setBlocking === 'function') { | ||
stream._handle.setBlocking(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "set-blocking", | ||
"version": "1.0.0", | ||
"description": "set blocking stdio and stderr ensuring that terminal output does not truncate", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "nyc mocha ./test/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/yargs/set-blocking.git" | ||
}, | ||
"keywords": [ | ||
"flush", | ||
"terminal", | ||
"blocking", | ||
"stdio", | ||
"stderr" | ||
], | ||
"author": "Ben Coe <[email protected]>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/yargs/set-blocking/issues" | ||
}, | ||
"homepage": "https://github.com/yargs/set-blocking#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.4.5", | ||
"nyc": "^6.4.4", | ||
"standard": "^7.0.1", | ||
"standard-version": "^2.2.1" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"LICENSE.txt" | ||
] | ||
} |
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,15 @@ | ||
#!/usr/bin/env node | ||
|
||
// see: https://github.com/yargs/yargs/issues/497 | ||
var buffer = '' | ||
for (var i = 0; i < 3000; i++) { | ||
buffer += 'line ' + i + '\n' | ||
} | ||
|
||
var setBlocking = require('../../') | ||
setBlocking(true) | ||
|
||
console.error(buffer) | ||
process.exit(1) | ||
|
||
console.log('should not execute') |
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,15 @@ | ||
#!/usr/bin/env node | ||
|
||
// see: https://github.com/yargs/yargs/issues/497 | ||
var buffer = '' | ||
for (var i = 0; i < 3000; i++) { | ||
buffer += 'line ' + i + '\n' | ||
} | ||
|
||
var setBlocking = require('../../') | ||
setBlocking(true) | ||
|
||
console.log(buffer) | ||
process.exit(0) | ||
|
||
console.log('should not execute') |
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,24 @@ | ||
/* global describe, should */ | ||
|
||
var exec = require('child_process').exec | ||
var setBlocking = require('../') | ||
|
||
require('chai').should() | ||
|
||
describe('setBlocking', function () { | ||
// see: https://github.com/yargs/yargs/issues/497 | ||
it('does not truncate text printed to stdout when process.exit() is called', function (done) { | ||
exec('./test/fixtures/yargs-497-stdout.js', function (err, stdout, stderr) { | ||
if (err) return done(err) | ||
stdout.should.match(/line 2999/) | ||
return done() | ||
}) | ||
}) | ||
|
||
it('does not truncate text printed to stderr when process.exit() is called', function (done) { | ||
exec('./test/fixtures/yargs-497-stderr.js', function (err, stdout, stderr) { | ||
stderr.should.match(/line 2999/) | ||
return done() | ||
}) | ||
}) | ||
}) |