Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim down dependency tree #11

Merged
merged 6 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
const {execFileSync} = require('child_process');
const path = require('path');
const execa = require('execa');

const exec = (cmd, args, shell) => execFileSync(cmd, args || [], {encoding: 'utf8', shell}).trim();

const create = (columns, rows) => ({
columns: parseInt(columns, 10),
Expand All @@ -26,7 +28,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 = exec(path.join(__dirname, 'vendor/windows/term-size.exe')).split(/\r?\n/);

if (size.length === 2) {
return create(size[0], size[1]);
Expand All @@ -36,7 +38,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 = exec(path.join(__dirname, 'vendor/macos/term-size'), [], true).split(/\r?\n/);

if (size.length === 2) {
return create(size[0], size[1]);
Expand All @@ -47,16 +49,16 @@ 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 = exec('resize', ['-u']).match(/\d+/g);

if (size.length === 2) {
return create(size[0], size[1]);
}
} catch (_) {}

try {
const columns = execa.sync('tput', ['cols']).stdout;
const rows = execa.sync('tput', ['lines']).stdout;
const columns = exec('tput', ['cols']);
const rows = exec('tput', ['lines']);

if (columns && rows) {
return create(columns, rows);
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
"tty",
"redirected"
],
"dependencies": {
"execa": "^1.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"execa": "^1.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
Expand Down