Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shelljs.exec

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shelljs.exec - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

benchmark-results-raw.txt

4

index.js

@@ -6,3 +6,3 @@ 'use strict'

function shello(command, options) {
function shelljsExec(command, options) {

@@ -36,2 +36,2 @@ options = normaliseOptions(options)

module.exports = shello
module.exports = shelljsExec
{
"name": "shelljs.exec",
"version": "1.0.1",
"description": "Drop-in replacement for shelljs' slow exec method, 5x faster",
"version": "1.0.2",
"description": "Replacement for shelljs' slow exec method - 20x faster",
"author": "Daniel Lewis BSc (Hons)",

@@ -6,0 +6,0 @@ "license": "ISC",

@@ -10,27 +10,32 @@ # shelljs.exec

**Drop-in replacement for shelljs' slow exec method, 5x faster**
**Replacement for shelljs' slow exec method - 20x faster**
**shelljs.exec** is a wrapper for [child_process.execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options)
IGNORE THIS README, IT IS BEING UPDATED RIGHT NOW
IGNORE THIS README, IT IS BEING UPDATED RIGHT NOW
<br>
IGNORE THIS README, IT IS BEING UPDATED RIGHT NOW
## Introduction
shelljs.exec takes identical arguments ... `(command[, options])` ... but does not throw by default.
shelljs is FAST but its exec method is SLOW, use this module instead of shelljs' exec method for speeds [20x faster](#benchmarks)
shelljs.exec has been benchmarked at 10 times faster than shelljs!
shelljs.exec is a zero-dependency module
On success it returns a JSON object:
It takes 2 arguments, the command to execute and an [options object](#options-object)
<br>
## Usage
On success:
```javascript 1.5
var shello = require('shelljs.exec')
var cmd = 'echo hello'
var cmdObj = shello(cmd, {stdio: 'pipe', encoding:'utf-8'})
var exec = require('shelljs.exec')
var cmdObj = exec('echo hello', {silent: true})
expect(cmdObj).to.eql({
error: null, // same as child_process.exec
error: null,
stdout: 'hello\n',
stderr: '', // same as child_process.exec
stderr: '',
code: 0,

@@ -41,8 +46,7 @@ ok: true

On failure it returns a JSON object:
On failure:
```javascript 1.5
var shello = require('shelljs.exec')
var cmd = 'blip blop'
var cmdObj = shello(cmd, {stdio: 'pipe', encoding:'utf-8'})
var exec = require('shelljs.exec')
var cmdObj = exec('blip blop', {silent: true})

@@ -58,22 +62,55 @@ expect(cmdObj.error).to.be.an('error')

For the full list of available options see [child_process.execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options)
**benchmarks**
This output was generated by [benchmark.js](benchmark.js)
<br>
********** shelljs **********
shelljs is slow
shelljs: 198.773ms
*****************************
## Options object
********** shelljs.exec **********
shelljs.exec is fast
shelljs.exec: 17.926ms
*****************************
* silent: Do not echo any output to console. Defaults to false.
**Author says**
* and any option available to Node.js' [child_process.execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options)
<br>
## Benchmarks
Benchmark test result logs are [HERE](https://travis-ci.org/danday74/shelljs.exec)
Generally speaking, on Linux shelljs.exec is 20 times faster and on Windows 5 times faster.
These tables show average execution times based on 1000 test runs:
Linux (Travis CI) Node v6
| command | shelljs.exec (this module) | shelljs.exec (from shelljs) | | shelljs supported command | |
|-------------------------------------|----------------------------|-----------------------------|--------------|---------------------------|--------------|
| echo hello | 4.16ms | 103.45ms | 24.9x slower | 0.17ms (shelljs.echo) | 24.4x faster |
| which git | 75.43ms | 169.85ms | 2.3x slower | 0.90ms (shelljs.which) | 83.5x faster |
| cat file1 file2 | 3.97ms | 105.03ms | 26.5x slower | 0.59ms (shelljs.cat) | 6.7x faster |
| printf hello | 3.17ms | 97.84ms | 30.8x slower | N/A | |
| whoami | 4.42ms | 110.14ms | 24.9x slower | N/A | |
| git rev-parse --is-inside-work-tree | 4.88ms | 100.61ms | 20.6x slower | N/A | |
Windows (GIT bash) Node v6.10.0
| command | shelljs.exec (this module) | shelljs.exec (from shelljs) | | shelljs supported command | |
|-------------------------------------|----------------------------|-----------------------------|--------------|---------------------------|---------------|
| echo hello | 15.56ms | 188.52ms | 12.1x slower | 0.43ms (shelljs.echo) | 35.9x faster |
| which git | 164.37ms | 332.20ms | 2.0x slower | 1.19ms (shelljs.which) | 138.6x faster |
| cat file1 file2 | 40.97ms | 217.73ms | 5.3x slower | 0.77ms (shelljs.cat) | 53.3x faster |
| printf hello | 43.55ms | 235.87ms | 5.4x slower | N/A | |
| whoami | 45.26ms | 247.77ms | 5.5x slower | N/A | |
| git rev-parse --is-inside-work-tree | 43.41ms | 231.35ms | 5.3x slower | N/A | |
<br>
## Author says
But as the days of Noah were, so also will the coming of the Son of Man be. 38 For as in the days before the flood, they were eating and drinking, marrying and giving in marriage, until the day that Noah entered the ark, 39 and did not know until the flood came and took them all away, so also will the coming of the Son of Man be.
[Matthew 24:37-39](https://www.biblegateway.com/passage/?search=Matthew+24%3A37-39&version=NKJV)

@@ -7,29 +7,29 @@ 'use strict'

var imp = require('../_js/testImports')
var shello = require('../../index')
var shelljsExec = require('../../index')
var COUNT = 2
var COUNT = 5
var RANGE = imp.range(COUNT)
function report(cmd, shelljsExecTimeSum, shelloTimeSum, shelljsCmdTimeSum, shelljsCmd) {
function report(cmd, oldTimeSum, newTimeSum, cmdTimeSum, shelljsCmd) {
function getWord(percent) {
if (percent < 100)
return chalk.green((100 / percent).toFixed(1) + ' times faster than shell-o')
return chalk.green((100 / percent).toFixed(1) + ' times faster than shelljs.exec (this module)')
else
return chalk.red((percent / 100).toFixed(1) + ' times slower than shell-o')
return chalk.red((percent / 100).toFixed(1) + ' times slower than shelljs.exec (this module)')
}
var shelljsExecTimeAvg, shelloTimeAvg, shelljsCmdTimeAvg
var shelljsExecTimePct, shelljsCmdTimePct, shelljsExecTimeWord, shelljsCmdTimeWord
var oldTimeAvg, newTimeAvg, cmdTimeAvg
var oldTimePct, cmdTimePct, oldTimeWord, cmdTimeWord
shelloTimeAvg = shelloTimeSum / COUNT
newTimeAvg = newTimeSum / COUNT
shelljsExecTimeAvg = shelljsExecTimeSum / COUNT
shelljsExecTimePct = 100 / shelloTimeAvg * shelljsExecTimeAvg
shelljsExecTimeWord = getWord(shelljsExecTimePct)
oldTimeAvg = oldTimeSum / COUNT
oldTimePct = 100 / newTimeAvg * oldTimeAvg
oldTimeWord = getWord(oldTimePct)
if (shelljsCmdTimeSum) {
shelljsCmdTimeAvg = shelljsCmdTimeSum / COUNT
shelljsCmdTimePct = 100 / shelloTimeAvg * shelljsCmdTimeAvg
shelljsCmdTimeWord = getWord(shelljsCmdTimePct)
if (cmdTimeSum) {
cmdTimeAvg = cmdTimeSum / COUNT
cmdTimePct = 100 / newTimeAvg * cmdTimeAvg
cmdTimeWord = getWord(cmdTimePct)
}

@@ -39,13 +39,13 @@

console.log(chalk.grey('AVERAGE TIMES FOR ' + COUNT + ' RUNS'))
console.log(chalk.grey('shelljs.exec --------------------> ', shelljsExecTimeAvg.toFixed(2) + 'ms', ' (' + shelljsExecTimePct.toFixed(2) + '%)', ' ' + shelljsExecTimeWord))
console.log(chalk.grey('shello --------------------------> ', shelloTimeAvg.toFixed(2) + 'ms', ' (100%)'))
if (shelljsCmdTimeSum && shelljsCmd) {
console.log(chalk.grey('shelljs.' + shelljsCmd + '> ', shelljsCmdTimeAvg.toFixed(2) + 'ms', ' (' + shelljsCmdTimePct.toFixed(2) + '%)', ' ' + shelljsCmdTimeWord))
console.log(chalk.grey('shelljs.exec (from shelljs) -----> ', oldTimeAvg.toFixed(2) + 'ms', ' (' + oldTimePct.toFixed(2) + '%)', ' ' + oldTimeWord))
console.log(chalk.grey('shelljs.exec (this module) ------> ', newTimeAvg.toFixed(2) + 'ms', ' (100%)'))
if (cmdTimeSum && shelljsCmd) {
console.log(chalk.grey('shelljs.' + shelljsCmd + '> ', cmdTimeAvg.toFixed(2) + 'ms', ' (' + cmdTimePct.toFixed(2) + '%)', ' ' + cmdTimeWord))
}
}
describe('benchmarks: shell-o v shelljs', function() {
describe('benchmarks: shelljs v shelljs.exec', function() {
var cmdObj, start, end
var shelljsExecTime, shelloTime, shelljsCmdTime
var oldTime, newTime, cmdTime

@@ -58,3 +58,3 @@ describe('shelljs supported commands', function() {

var shelljsExecTimeSum = 0, shelloTimeSum = 0, shelljsCmdTimeSum = 0
var oldTimeSum = 0, newTimeSum = 0, cmdTimeSum = 0

@@ -67,9 +67,9 @@ RANGE.forEach(function() {

imp.expect(cmdObj.stdout).to.equal('hello' + imp.EOL)
shelljsExecTime = end - start
oldTime = end - start
start = now()
cmdObj = shello('echo hello', {silent: true})
cmdObj = shelljsExec('echo hello', {silent: true})
end = now()
imp.expect(cmdObj.stdout).to.equal('hello' + imp.EOL)
shelloTime = end - start
newTime = end - start

@@ -80,10 +80,10 @@ start = now()

imp.expect(cmdObj.stdout).to.equal('hello')
shelljsCmdTime = end - start
cmdTime = end - start
shelljsExecTimeSum += shelljsExecTime
shelloTimeSum += shelloTime
shelljsCmdTimeSum += shelljsCmdTime
oldTimeSum += oldTime
newTimeSum += newTime
cmdTimeSum += cmdTime
})
report('echo hello', shelljsExecTimeSum, shelloTimeSum, shelljsCmdTimeSum, 'echo --------------------')
report('echo hello', oldTimeSum, newTimeSum, cmdTimeSum, 'echo --------------------')
})

@@ -95,4 +95,4 @@ })

before(function() {
var which = shello('which which', {silent: true})
var git = shello('which git', {silent: true})
var which = shelljsExec('which which', {silent: true})
var git = shelljsExec('which git', {silent: true})
if (!which.ok || !git.ok) {

@@ -105,3 +105,3 @@ this.skip()

var shelljsExecTimeSum = 0, shelloTimeSum = 0, shelljsCmdTimeSum = 0
var oldTimeSum = 0, newTimeSum = 0, cmdTimeSum = 0

@@ -114,9 +114,9 @@ RANGE.forEach(function() {

imp.expect(cmdObj.code).to.equal(0)
shelljsExecTime = end - start
oldTime = end - start
start = now()
cmdObj = shello('which git', {silent: true})
cmdObj = shelljsExec('which git', {silent: true})
end = now()
imp.expect(cmdObj.code).to.equal(0)
shelloTime = end - start
newTime = end - start

@@ -128,10 +128,10 @@ start = now()

imp.expect(cmdObj.code).to.equal(0)
shelljsCmdTime = end - start
cmdTime = end - start
shelljsExecTimeSum += shelljsExecTime
shelloTimeSum += shelloTime
shelljsCmdTimeSum += shelljsCmdTime
oldTimeSum += oldTime
newTimeSum += newTime
cmdTimeSum += cmdTime
})
report('which git', shelljsExecTimeSum, shelloTimeSum, shelljsCmdTimeSum, 'which -------------------')
report('which git', oldTimeSum, newTimeSum, cmdTimeSum, 'which -------------------')
})

@@ -143,4 +143,4 @@ })

before(function() {
var cat1 = shello('where cat', {silent: true})
var cat2 = shello('which cat', {silent: true})
var cat1 = shelljsExec('where cat', {silent: true})
var cat2 = shelljsExec('which cat', {silent: true})
if (!cat1.ok && !cat2.ok) {

@@ -153,3 +153,3 @@ this.skip()

var shelljsExecTimeSum = 0, shelloTimeSum = 0, shelljsCmdTimeSum = 0
var oldTimeSum = 0, newTimeSum = 0, cmdTimeSum = 0

@@ -165,9 +165,9 @@ var file1 = __dirname + '/file1'

imp.expect(cmdObj.stdout).to.equal('hello\nworld\n')
shelljsExecTime = end - start
oldTime = end - start
start = now()
cmdObj = shello('cat ' + file1 + ' ' + file2, {silent: true})
cmdObj = shelljsExec('cat ' + file1 + ' ' + file2, {silent: true})
end = now()
imp.expect(cmdObj.stdout).to.equal('hello\nworld\n')
shelloTime = end - start
newTime = end - start

@@ -178,10 +178,10 @@ start = now()

imp.expect(cmdObj.stdout).to.equal('hello\nworld\n')
shelljsCmdTime = end - start
cmdTime = end - start
shelljsExecTimeSum += shelljsExecTime
shelloTimeSum += shelloTime
shelljsCmdTimeSum += shelljsCmdTime
oldTimeSum += oldTime
newTimeSum += newTime
cmdTimeSum += cmdTime
})
report('cat file1 file2', shelljsExecTimeSum, shelloTimeSum, shelljsCmdTimeSum, 'cat ---------------------')
report('cat file1 file2', oldTimeSum, newTimeSum, cmdTimeSum, 'cat ---------------------')
})

@@ -196,4 +196,4 @@ })

before(function() {
var printf1 = shello('where printf', {silent: true})
var printf2 = shello('which printf', {silent: true})
var printf1 = shelljsExec('where printf', {silent: true})
var printf2 = shelljsExec('which printf', {silent: true})
if (!printf1.ok && !printf2.ok) {

@@ -206,3 +206,3 @@ this.skip()

var shelljsExecTimeSum = 0, shelloTimeSum = 0
var oldTimeSum = 0, newTimeSum = 0

@@ -215,15 +215,15 @@ RANGE.forEach(function() {

imp.expect(cmdObj.stdout).to.equal('hello')
shelljsExecTime = end - start
oldTime = end - start
start = now()
cmdObj = shello('printf hello', {silent: true})
cmdObj = shelljsExec('printf hello', {silent: true})
end = now()
imp.expect(cmdObj.stdout).to.equal('hello')
shelloTime = end - start
newTime = end - start
shelljsExecTimeSum += shelljsExecTime
shelloTimeSum += shelloTime
oldTimeSum += oldTime
newTimeSum += newTime
})
report('printf hello', shelljsExecTimeSum, shelloTimeSum)
report('printf hello', oldTimeSum, newTimeSum)
})

@@ -235,4 +235,4 @@ })

before(function() {
var whoami1 = shello('where whoami', {silent: true})
var whoami2 = shello('which whoami', {silent: true})
var whoami1 = shelljsExec('where whoami', {silent: true})
var whoami2 = shelljsExec('which whoami', {silent: true})
if (!whoami1.ok && !whoami2.ok) {

@@ -245,3 +245,3 @@ this.skip()

var shelljsExecTimeSum = 0, shelloTimeSum = 0
var oldTimeSum = 0, newTimeSum = 0

@@ -254,15 +254,15 @@ RANGE.forEach(function() {

imp.expect(cmdObj.code).to.equal(0)
shelljsExecTime = end - start
oldTime = end - start
start = now()
cmdObj = shello('whoami', {silent: true})
cmdObj = shelljsExec('whoami', {silent: true})
end = now()
imp.expect(cmdObj.code).to.equal(0)
shelloTime = end - start
newTime = end - start
shelljsExecTimeSum += shelljsExecTime
shelloTimeSum += shelloTime
oldTimeSum += oldTime
newTimeSum += newTime
})
report('whoami', shelljsExecTimeSum, shelloTimeSum)
report('whoami', oldTimeSum, newTimeSum)
})

@@ -274,4 +274,4 @@ })

before(function() {
var git1 = shello('where git', {silent: true})
var git2 = shello('which git', {silent: true})
var git1 = shelljsExec('where git', {silent: true})
var git2 = shelljsExec('which git', {silent: true})
if (!git1.ok && !git2.ok) {

@@ -284,3 +284,3 @@ this.skip()

var shelljsExecTimeSum = 0, shelloTimeSum = 0
var oldTimeSum = 0, newTimeSum = 0

@@ -293,15 +293,15 @@ RANGE.forEach(function() {

imp.expect(cmdObj.stdout).to.equal('true\n')
shelljsExecTime = end - start
oldTime = end - start
start = now()
cmdObj = shello('git rev-parse --is-inside-work-tree', {silent: true})
cmdObj = shelljsExec('git rev-parse --is-inside-work-tree', {silent: true})
end = now()
imp.expect(cmdObj.stdout).to.equal('true\n')
shelloTime = end - start
newTime = end - start
shelljsExecTimeSum += shelljsExecTime
shelloTimeSum += shelloTime
oldTimeSum += oldTime
newTimeSum += newTime
})
report('git rev-parse --is-inside-work-tree', shelljsExecTimeSum, shelloTimeSum)
report('git rev-parse --is-inside-work-tree', oldTimeSum, newTimeSum)
})

@@ -308,0 +308,0 @@ })

@@ -1,8 +0,1 @@

* Rename and update package.json and tests - try both alternatives for searching
* Rename benchmark vars
* Ensure packages up to date
* Run benchmarks on Windows and Linux and OSX
* Update README
* Update README and delete TODO

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc