Skip to content

Commit

Permalink
Rename stripEof option to stripFinalNewline
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 28, 2018
1 parent 0e780f8 commit f8397ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions index.js
Expand Up @@ -2,7 +2,7 @@
const path = require('path');
const childProcess = require('child_process');
const crossSpawn = require('cross-spawn');
const stripEof = require('strip-eof');
const stripFinalNewline = require('strip-final-newline');
const npmRunPath = require('npm-run-path');
const isStream = require('is-stream');
const _getStream = require('get-stream');
Expand Down Expand Up @@ -44,14 +44,19 @@ function handleArgs(cmd, args, opts) {
opts = Object.assign({
maxBuffer: TEN_MEGABYTES,
buffer: true,
stripEof: true,
stripFinalNewline: true,
preferLocal: true,
localDir: parsed.options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
cleanup: true
}, parsed.options);

// TODO: Remove in the next major release
if (opts.stripEof === false) {
opts.stripFinalNewline = false;
}

opts.stdio = stdio(opts);

if (opts.preferLocal) {
Expand Down Expand Up @@ -89,8 +94,8 @@ function handleInput(spawned, input) {
}

function handleOutput(opts, val) {
if (val && opts.stripEof) {
val = stripEof(val);
if (val && opts.stripFinalNewline) {
val = stripFinalNewline(val);
}

return val;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -43,7 +43,7 @@
"npm-run-path": "^2.0.0",
"p-finally": "^1.0.0",
"signal-exit": "^3.0.0",
"strip-eof": "^1.0.0"
"strip-final-newline": "^2.0.0"
},
"devDependencies": {
"ava": "*",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -195,12 +195,12 @@ Default: `false`

If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.

#### stripEof
#### stripFinalNewline

Type: `boolean`<br>
Default: `true`

[Strip EOF](https://github.com/sindresorhus/strip-eof) (last newline) from the output.
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.

#### preferLocal

Expand Down
7 changes: 6 additions & 1 deletion test.js
Expand Up @@ -138,11 +138,16 @@ test('skip throwing when using reject option in execa.shellSync()', t => {
t.is(typeof err.stderr, 'string');
});

test('stripEof option', async t => {
test('stripEof option (legacy)', async t => {
const {stdout} = await m('noop', ['foo'], {stripEof: false});
t.is(stdout, 'foo\n');
});

test('stripFinalNewline option', async t => {
const {stdout} = await m('noop', ['foo'], {stripFinalNewline: false});
t.is(stdout, 'foo\n');
});

test.serial('preferLocal option', async t => {
t.true((await m('cat-names')).stdout.length > 2);

Expand Down

0 comments on commit f8397ba

Please sign in to comment.