From 7d63e25b11040249caaf2aa41c62927390ac18a3 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Thu, 23 May 2019 15:57:57 +0200 Subject: [PATCH 1/6] Slimmed down dependencies tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced “execa” with the native “child_process” module. - Imported “strip-eof” directly. --- index.js | 17 +++++++++++------ package.json | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 7f12066..21a831a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,11 @@ 'use strict'; +const {spawnSync} = require('child_process'); const path = require('path'); -const execa = require('execa'); +const stripEof = require('strip-eof'); + +const spawn = (cmd, args) => stripEof(spawnSync(cmd, args || [], {encoding: 'utf8'}).stdout); + +const spawnSh = cmd => spawn('/bin/sh', ['-c', `"${cmd}"`]); const create = (columns, rows) => ({ columns: parseInt(columns, 10), @@ -26,7 +31,7 @@ module.exports = () => { if (process.platform === 'win32') { try { // Binary: https://github.com/sindresorhus/win-term-size - const size = execa.sync(path.join(__dirname, 'vendor/windows/term-size.exe')).stdout.split(/\r?\n/); + const size = spawn(path.join(__dirname, 'vendor/windows/term-size.exe')).split(/\r?\n/); if (size.length === 2) { return create(size[0], size[1]); @@ -36,7 +41,7 @@ module.exports = () => { if (process.platform === 'darwin') { try { // Binary: https://github.com/sindresorhus/macos-term-size - const size = execa.shellSync(path.join(__dirname, 'vendor/macos/term-size')).stdout.split(/\r?\n/); + const size = spawnSh(path.join(__dirname, 'vendor/macos/term-size')).split(/\r?\n/); if (size.length === 2) { return create(size[0], size[1]); @@ -47,7 +52,7 @@ module.exports = () => { // `resize` is preferred as it works even when all file descriptors are redirected // https://linux.die.net/man/1/resize try { - const size = execa.sync('resize', ['-u']).stdout.match(/\d+/g); + const size = spawn('resize', ['-u']).match(/\d+/g); if (size.length === 2) { return create(size[0], size[1]); @@ -55,8 +60,8 @@ module.exports = () => { } catch (_) {} try { - const columns = execa.sync('tput', ['cols']).stdout; - const rows = execa.sync('tput', ['lines']).stdout; + const columns = spawn('tput', ['cols']); + const rows = spawn('tput', ['lines']); if (columns && rows) { return create(columns, rows); diff --git a/package.json b/package.json index 02faec4..90a6dee 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,11 @@ "redirected" ], "dependencies": { - "execa": "^1.0.0" + "strip-eof": "^2.0.0" }, "devDependencies": { "ava": "^1.4.1", + "execa": "^1.0.0", "tsd": "^0.7.2", "xo": "^0.24.0" } From 94e3a908ce46088ddccd2df38c37b147806bd7c1 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Fri, 24 May 2019 19:00:43 +0200 Subject: [PATCH 2/6] =?UTF-8?q?Using=20=E2=80=9CString#trim=E2=80=9D=20ins?= =?UTF-8?q?tead=20of=20=E2=80=9Cstrip-eof=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 +-- package.json | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 21a831a..8acdd38 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,8 @@ 'use strict'; const {spawnSync} = require('child_process'); const path = require('path'); -const stripEof = require('strip-eof'); -const spawn = (cmd, args) => stripEof(spawnSync(cmd, args || [], {encoding: 'utf8'}).stdout); +const spawn = (cmd, args) => spawnSync(cmd, args || [], {encoding: 'utf8'}).stdout.trim(); const spawnSh = cmd => spawn('/bin/sh', ['-c', `"${cmd}"`]); diff --git a/package.json b/package.json index 90a6dee..64bcf13 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,7 @@ "tty", "redirected" ], - "dependencies": { - "strip-eof": "^2.0.0" - }, + "dependencies": {}, "devDependencies": { "ava": "^1.4.1", "execa": "^1.0.0", From 664086b90bb0ccd0a8d76a3507aa3793276a8287 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Fri, 24 May 2019 19:05:16 +0200 Subject: [PATCH 3/6] =?UTF-8?q?Using=20=E2=80=9CexecFileSync=E2=80=9D=20in?= =?UTF-8?q?stead=20of=20=E2=80=9CspawnSync=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 8acdd38..6187210 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,10 @@ 'use strict'; -const {spawnSync} = require('child_process'); +const {execFileSync} = require('child_process'); const path = require('path'); -const spawn = (cmd, args) => spawnSync(cmd, args || [], {encoding: 'utf8'}).stdout.trim(); +const exec = (cmd, args) => execFileSync(cmd, args || [], {encoding: 'utf8'}).trim(); -const spawnSh = cmd => spawn('/bin/sh', ['-c', `"${cmd}"`]); +const execSh = cmd => exec('/bin/sh', ['-c', `"${cmd}"`]); const create = (columns, rows) => ({ columns: parseInt(columns, 10), @@ -30,7 +30,7 @@ module.exports = () => { if (process.platform === 'win32') { try { // Binary: https://github.com/sindresorhus/win-term-size - const size = spawn(path.join(__dirname, 'vendor/windows/term-size.exe')).split(/\r?\n/); + const size = exec(path.join(__dirname, 'vendor/windows/term-size.exe')).split(/\r?\n/); if (size.length === 2) { return create(size[0], size[1]); @@ -40,7 +40,7 @@ module.exports = () => { if (process.platform === 'darwin') { try { // Binary: https://github.com/sindresorhus/macos-term-size - const size = spawnSh(path.join(__dirname, 'vendor/macos/term-size')).split(/\r?\n/); + const size = execSh(path.join(__dirname, 'vendor/macos/term-size')).split(/\r?\n/); if (size.length === 2) { return create(size[0], size[1]); @@ -51,7 +51,7 @@ module.exports = () => { // `resize` is preferred as it works even when all file descriptors are redirected // https://linux.die.net/man/1/resize try { - const size = spawn('resize', ['-u']).match(/\d+/g); + const size = exec('resize', ['-u']).match(/\d+/g); if (size.length === 2) { return create(size[0], size[1]); @@ -59,8 +59,8 @@ module.exports = () => { } catch (_) {} try { - const columns = spawn('tput', ['cols']); - const rows = spawn('tput', ['lines']); + const columns = exec('tput', ['cols']); + const rows = exec('tput', ['lines']); if (columns && rows) { return create(columns, rows); From 775c8a369c1c68dfabd87003ee248f49c4cf1c7f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 25 May 2019 12:10:48 +0700 Subject: [PATCH 4/6] Update package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 64bcf13..1902bd4 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "tty", "redirected" ], - "dependencies": {}, "devDependencies": { "ava": "^1.4.1", "execa": "^1.0.0", From 13cf663035c1ad71dd1a31ec11beca433f1a6e65 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Sat, 25 May 2019 13:37:39 +0200 Subject: [PATCH 5/6] =?UTF-8?q?Letting=20=E2=80=9CexecFileSync=E2=80=9D=20?= =?UTF-8?q?handle=20how=20to=20execute=20commands=20inside=20a=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6187210..e26d71b 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,7 @@ const {execFileSync} = require('child_process'); const path = require('path'); -const exec = (cmd, args) => execFileSync(cmd, args || [], {encoding: 'utf8'}).trim(); - -const execSh = cmd => exec('/bin/sh', ['-c', `"${cmd}"`]); +const exec = (cmd, args, shell) => execFileSync(cmd, args || [], {encoding: 'utf8', shell: !!shell}).trim(); const create = (columns, rows) => ({ columns: parseInt(columns, 10), @@ -40,7 +38,7 @@ module.exports = () => { if (process.platform === 'darwin') { try { // Binary: https://github.com/sindresorhus/macos-term-size - const size = execSh(path.join(__dirname, 'vendor/macos/term-size')).split(/\r?\n/); + const size = exec(path.join(__dirname, 'vendor/macos/term-size'), [], true).split(/\r?\n/); if (size.length === 2) { return create(size[0], size[1]); From 97236aa8bcd54af337cb35cc837962c5326ac32d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 25 May 2019 18:55:48 +0700 Subject: [PATCH 6/6] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e26d71b..ec433ad 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const {execFileSync} = require('child_process'); const path = require('path'); -const exec = (cmd, args, shell) => execFileSync(cmd, args || [], {encoding: 'utf8', shell: !!shell}).trim(); +const exec = (cmd, args, shell) => execFileSync(cmd, args || [], {encoding: 'utf8', shell}).trim(); const create = (columns, rows) => ({ columns: parseInt(columns, 10),