├── .gitignore
├── .travis.yml
├── index.js
├── appveyor.yml
├── test
├── fixtures
│ ├── yargs-497-stderr.js
│ └── yargs-497-stdout.js
└── test.js
├── LICENSE.txt
├── CHANGELOG.md
├── package.json
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | .nyc_output
4 | coverage
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | os:
4 | - linux
5 | - osx
6 |
7 | after_success: npm run coverage
8 |
9 | node_js:
10 | - "4"
11 | - "6"
12 | - "stable"
13 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = function (blocking) {
2 | [process.stdout, process.stderr].forEach(function (stream) {
3 | if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') {
4 | stream._handle.setBlocking(blocking)
5 | }
6 | })
7 | }
8 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | environment:
2 | matrix:
3 | - nodejs_version: "4"
4 | - nodejs_version: "6"
5 |
6 | install:
7 | - ps: Install-Product node $env:nodejs_version
8 | - npm install
9 |
10 | test_script:
11 | - node --version
12 | - npm --version
13 | - npm test
14 |
15 | os:
16 | - Windows Server 2012 R2
17 |
18 | build: off
19 |
20 | version: "{build}"
21 |
--------------------------------------------------------------------------------
/test/fixtures/yargs-497-stderr.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | // pretend we are a TTY
4 | process.stdout.isTTY = true
5 | process.stderr.isTTY = true
6 |
7 | // see: https://github.com/yargs/yargs/issues/497
8 | var buffer = ''
9 | for (var i = 0; i < 3000; i++) {
10 | buffer += 'line ' + i + '\n'
11 | }
12 |
13 | var setBlocking = require('../../')
14 | setBlocking(true)
15 |
16 | console.error(buffer)
17 | process.exit(1)
18 |
19 | console.log('should not execute')
20 |
--------------------------------------------------------------------------------
/test/fixtures/yargs-497-stdout.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | // pretend we are a TTY
4 | process.stdout.isTTY = true
5 | process.stderr.isTTY = true
6 |
7 | // see: https://github.com/yargs/yargs/issues/497
8 | var buffer = ''
9 | for (var i = 0; i < 3000; i++) {
10 | buffer += 'line ' + i + '\n'
11 | }
12 |
13 | var setBlocking = require('../../')
14 | setBlocking(true)
15 |
16 | console.log(buffer)
17 | process.exit(0)
18 |
19 | console.log('should not execute')
20 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016, Contributors
2 |
3 | Permission to use, copy, modify, and/or distribute this software
4 | for any purpose with or without fee is hereby granted, provided
5 | that the above copyright notice and this permission notice
6 | appear in all copies.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 | OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
11 | LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12 | OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 |
6 | # [2.0.0](https://github.com/yargs/set-blocking/compare/v1.0.0...v2.0.0) (2016-05-17)
7 |
8 |
9 | ### Features
10 |
11 | * add an isTTY check ([#3](https://github.com/yargs/set-blocking/issues/3)) ([66ce277](https://github.com/yargs/set-blocking/commit/66ce277))
12 |
13 |
14 | ### BREAKING CHANGES
15 |
16 | * stdio/stderr will not be set to blocking if isTTY === false
17 |
18 |
19 |
20 |
21 | # 1.0.0 (2016-05-14)
22 |
23 |
24 | ### Features
25 |
26 | * implemented shim for stream._handle.setBlocking ([6bde0c0](https://github.com/yargs/set-blocking/commit/6bde0c0))
27 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | /* global describe, it */
2 |
3 | var exec = require('child_process').exec
4 |
5 | require('chai').should()
6 |
7 | describe('setBlocking', function () {
8 | // see: https://github.com/yargs/yargs/issues/497
9 | it('does not truncate text printed to stdout when process.exit() is called', function (done) {
10 | exec('node ./test/fixtures/yargs-497-stdout.js', function (err, stdout, stderr) {
11 | if (err) return done(err)
12 | stdout.should.match(/line 2999/)
13 | return done()
14 | })
15 | })
16 |
17 | it('does not truncate text printed to stderr when process.exit() is called', function (done) {
18 | exec('node ./test/fixtures/yargs-497-stderr.js', function (err, stdout, stderr) {
19 | err.should.match(/Command failed/)
20 | stderr.should.match(/line 2999/)
21 | return done()
22 | })
23 | })
24 | })
25 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "set-blocking",
3 | "version": "2.0.0",
4 | "description": "set blocking stdio and stderr ensuring that terminal output does not truncate",
5 | "main": "index.js",
6 | "scripts": {
7 | "pretest": "standard",
8 | "test": "nyc mocha ./test/*.js",
9 | "coverage": "nyc report --reporter=text-lcov | coveralls",
10 | "version": "standard-version"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/yargs/set-blocking.git"
15 | },
16 | "keywords": [
17 | "flush",
18 | "terminal",
19 | "blocking",
20 | "shim",
21 | "stdio",
22 | "stderr"
23 | ],
24 | "author": "Ben Coe ",
25 | "license": "ISC",
26 | "bugs": {
27 | "url": "https://github.com/yargs/set-blocking/issues"
28 | },
29 | "homepage": "https://github.com/yargs/set-blocking#readme",
30 | "devDependencies": {
31 | "chai": "^3.5.0",
32 | "coveralls": "^2.11.9",
33 | "mocha": "^2.4.5",
34 | "nyc": "^6.4.4",
35 | "standard": "^7.0.1",
36 | "standard-version": "^2.2.1"
37 | },
38 | "files": [
39 | "index.js",
40 | "LICENSE.txt"
41 | ]
42 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # set-blocking
2 |
3 | [](https://travis-ci.org/yargs/set-blocking)
4 | [](https://www.npmjs.com/package/set-blocking)
5 | [](https://coveralls.io/r/yargs/set-blocking?branch=master)
6 | [](https://github.com/conventional-changelog/standard-version)
7 |
8 | Set blocking `stdio` and `stderr` ensuring that terminal output does not truncate.
9 |
10 | ```js
11 | const setBlocking = require('set-blocking')
12 | setBlocking(true)
13 | console.log(someLargeStringToOutput)
14 | ```
15 |
16 | ## Historical Context/Word of Warning
17 |
18 | This was created as a shim to address the bug discussed in [node #6456](https://github.com/nodejs/node/issues/6456). This bug crops up on
19 | newer versions of Node.js (`0.12+`), truncating terminal output.
20 |
21 | You should be mindful of the side-effects caused by using `set-blocking`:
22 |
23 | * If your module sets blocking to `true`, it will affect other modules
24 | consuming your library. In [yargs](https://github.com/yargs/yargs/blob/master/yargs.js#L653) we only call
25 | `setBlocking(true)` once we already know we are about to call `process.exit(code)`.
26 | * This patch will not apply to subprocesses spawned with `isTTY = true`, this is
27 | the [default `spawn()` behavior](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
28 |
29 | ## License
30 |
31 | ISC
32 |
--------------------------------------------------------------------------------