diff --git a/index.js b/index.js index aad9ac887..502999ea5 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -44,7 +44,7 @@ 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', @@ -52,6 +52,11 @@ function handleArgs(cmd, args, opts) { 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) { @@ -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; diff --git a/package.json b/package.json index c0257b757..bbaffc133 100644 --- a/package.json +++ b/package.json @@ -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": "*", diff --git a/readme.md b/readme.md index f3f533d92..161da6bb5 100644 --- a/readme.md +++ b/readme.md @@ -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`
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 diff --git a/test.js b/test.js index c85e91c26..5757ed10a 100644 --- a/test.js +++ b/test.js @@ -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);