+10
-0
@@ -0,1 +1,11 @@ | ||
| ## v1.0.5 / January 22, 2015 | ||
| - fix version ranges | ||
| - fix api docs/docblocks | ||
| - fix api docs | ||
| - edit description | ||
| - edit `scripts` | ||
| - add `async-exec-cmd` | ||
| - just move async logic to `async-exec-cmd` | ||
| ## v1.0.4 / January 21, 2015 | ||
@@ -2,0 +12,0 @@ - make it **hybrid** (with hybrid api) using `hybridify` |
+34
-76
| /** | ||
| * exec-cmd <https://github.com/tunnckoCore/exec-cmd> | ||
| * | ||
| * Copyright (c) 2014 Charlike Mike Reagent, contributors. | ||
| * Copyright (c) 2015 Charlike Mike Reagent, contributors. | ||
| * Licensed under the MIT license. | ||
@@ -10,77 +10,35 @@ */ | ||
| var assert = require('assert'); | ||
| var spawn = require('cross-spawn'); | ||
| var Deferred = require('native-or-another'); | ||
| var handleCallback = require('handle-callback'); | ||
| var handleArguments = require('handle-arguments'); | ||
| var asyncExecCmd = require('async-exec-cmd'); | ||
| var hybridify = require('hybridify'); | ||
| module.exports = function hybridExecCmd() { | ||
| var argz = handleArguments(arguments); | ||
| var promise = execCmd.apply(this, argz.args); | ||
| if (argz.callback) { | ||
| promise = handleCallback(promise, argz.callback); | ||
| } | ||
| return promise; | ||
| } | ||
| function execCmd(cmd, args, opts) { | ||
| var stdout = new Buffer(''); | ||
| var stderr = new Buffer(''); | ||
| opts = opts || {}; | ||
| args = args || []; | ||
| assert(typeof cmd === 'string', 'exec-cmd: `cmd` must be string'); | ||
| assert(Array.isArray(args), 'exec-cmd: `args` must be array'); | ||
| assert(typeof opts === 'object', 'exec-cmd: `opts` must be object'); | ||
| var defer = new Deferred(); | ||
| var cp = spawn(cmd, args, opts); | ||
| cp.stdout.on('data', function indexOnSTDOUT(data) { | ||
| stdout = Buffer.concat([stdout, data]); | ||
| }); | ||
| cp.stderr.on('data', function indexOnSTDERR(data) { | ||
| stderr = Buffer.concat([stderr, data]); | ||
| }); | ||
| /* istanbul ignore next */ | ||
| cp.on('error', function indexOnError(err) { | ||
| return defer.reject(err); | ||
| }); | ||
| cp.on('close', function indexOnClose(code) { | ||
| stdout = stdout.toString(); | ||
| stderr = stderr.toString(); | ||
| if (!code) { | ||
| return defer.resolve(stdout); | ||
| } | ||
| return defer.reject(new CommandError({ | ||
| status: code, | ||
| stdout: stdout, | ||
| stderr: stderr, | ||
| message: stderr.replace('\n' + code + '\n', ''), | ||
| command: cmd + ' ' + args.join(' ') | ||
| })); | ||
| }); | ||
| defer.promise.cp = cp; | ||
| return defer.promise; | ||
| } | ||
| function CommandError(opts) { | ||
| this.name = 'CommandError'; | ||
| this.command = opts.command; | ||
| this.message = opts.message; | ||
| this.status = opts.status; | ||
| this.stdout = opts.stdout; | ||
| this.stderr = opts.stderr; | ||
| } | ||
| CommandError.prototype = new Error(); | ||
| CommandError.prototype.constructor = CommandError; | ||
| /** | ||
| * Hybrid execute command via spawn | ||
| * | ||
| * **Example:** | ||
| * | ||
| * ```js | ||
| * var exec = require('exec-cmd'); | ||
| * var promise = exec('echo', [ | ||
| * 'hello world' | ||
| * ], function __cb(err, res) { | ||
| * // as usual | ||
| * }) | ||
| * .then(function(res) { | ||
| * //=> res[0] is code | ||
| * //=> res[1] is stdout | ||
| * //=> res[1] === 'hello world' | ||
| * }) | ||
| * .catch(function(err) { | ||
| * //=> null || undefined? | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @name execCmd | ||
| * @param {String} `<cmd>` | ||
| * @param {Array|Function} `<args>` | ||
| * @param {Object|Function} `[opts]` | ||
| * @param {Function} `[callback]` | ||
| * @return {Promise} | ||
| * @api public | ||
| */ | ||
| module.exports = hybridify(asyncExecCmd); |
+1
-1
@@ -1,2 +0,2 @@ | ||
| Copyright (c) 2014 [Charlike Make Reagent](http://j.mp/1stW47C), contributors | ||
| Copyright (c) 2015 [Charlike Make Reagent](http://j.mp/1stW47C), contributors | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person |
+11
-9
| { | ||
| "name": "exec-cmd", | ||
| "version": "1.0.4", | ||
| "description": "Simple, fast and cross-platform executing commands (with child_process spawn) using Bluebird or Native Promise", | ||
| "version": "1.0.5", | ||
| "description": "Flexible and cross-platform executing commands. Hybrid. Async and Promise API.", | ||
| "scripts": { | ||
| "lint": "jshint . && jscs . --reporter inline", | ||
| "lint": "jshint index.js && jscs index.js --reporter inline", | ||
| "test": "mocha", | ||
@@ -24,3 +24,7 @@ "test-cov": "istanbul cover _mocha", | ||
| "aplus", | ||
| "async", | ||
| "bluebird", | ||
| "callback", | ||
| "callbacks", | ||
| "cb", | ||
| "cmd", | ||
@@ -53,6 +57,4 @@ "cmds", | ||
| "dependencies": { | ||
| "cross-spawn": "^0.2.3", | ||
| "handle-arguments": "^1.0.2", | ||
| "handle-callback": "^1.0.1", | ||
| "native-or-another": "^2.0.0" | ||
| "async-exec-cmd": "^0.0.x", | ||
| "hybridify": "^1.0.x" | ||
| }, | ||
@@ -62,5 +64,5 @@ "devDependencies": { | ||
| "istanbul-harmony": "^0.3.1", | ||
| "mocha": "^2.0.1", | ||
| "mocha": "*", | ||
| "mocha-lcov-reporter": "0.0.1" | ||
| } | ||
| } | ||
| } |
+35
-3
| ## [![npm versi][npmjs-img]][npmjs-url] [![mit license][license-img]][license-url] [![build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![deps status][daviddm-img]][daviddm-url] | ||
| > Simple, fast and cross-platform executing commands (with child_process spawn) using Bluebird or Native Promise. **The package is [hybrid][hybridify] - with [hybridify][hybridify] api!** | ||
| > Flexible and cross-platform executing commands. **[Hybrid][hybridify], Async and Promise API.** | ||
@@ -14,2 +14,4 @@ | ||
| ## Usage | ||
| > For more use-cases see the [tests](./test.js) | ||
| ```js | ||
@@ -48,2 +50,32 @@ var exec = require('exec-cmd'); | ||
| ## API | ||
| ### [.execCmd](./index.js#L43) | ||
| > Hybrid execute command via spawn | ||
| * `<cmd>` **{String}** | ||
| * `<args>` **{Array|Function}** | ||
| * `[opts]` **{Object|Function}** | ||
| * `[callback]` **{Function}** | ||
| * `returns` **{Promise}** | ||
| **Example:** | ||
| ```js | ||
| var exec = require('exec-cmd'); | ||
| var promise = exec('echo', [ | ||
| 'hello world' | ||
| ], function __cb(err, res) { | ||
| // as usual | ||
| }) | ||
| .then(function(res) { | ||
| //=> res[0] is code | ||
| //=> res[1] is stdout | ||
| //=> res[1] === 'hello world' | ||
| }) | ||
| .catch(function(err) { | ||
| //=> null || undefined? | ||
| }) | ||
| ``` | ||
| ## Author | ||
@@ -88,5 +120,5 @@ **Charlike Mike Reagent** | ||
| _Powered and automated by [kdf](https://github.com/tunnckoCore), January 21, 2015_ | ||
| _Powered and automated by [kdf](https://github.com/tunnckoCore), January 22, 2015_ | ||
| [hybridify]: https://github.com/tunnckoCore/hybridify | ||
| [hybridify]: https://github.com/tunnckoCore/hybridify |
+65
-59
| /** | ||
| * exec-cmd <https://github.com/tunnckoCore/exec-cmd> | ||
| * | ||
| * Copyright (c) 2014 Charlike Mike Reagent, contributors. | ||
| * Copyright (c) 2015 Charlike Mike Reagent, contributors. | ||
| * Licensed under the MIT license. | ||
@@ -11,3 +11,3 @@ */ | ||
| var path = require('path'); | ||
| var exec = require('./index'); | ||
| var execCmd = require('./index'); | ||
| var assert = require('assert'); | ||
@@ -22,3 +22,4 @@ | ||
| it('should handle optional `args` and `options`', function(done) { | ||
| var promise = exec('echo'); | ||
| var promise = execCmd('echo'); | ||
| strictEqual(typeof promise.then, 'function'); | ||
@@ -29,60 +30,49 @@ done(); | ||
| it('should handle optional `options`', function(done) { | ||
| var promise = exec('echo', [ | ||
| var promise = execCmd('echo', [ | ||
| 'hello world' | ||
| ]) | ||
| .then(function(stdout) { | ||
| .then(function(res) { | ||
| var stdout = res[1]; | ||
| var code = res[0]; | ||
| strictEqual(code, 0); | ||
| strictEqual(stdout.trim(), 'hello world'); | ||
| done(); | ||
| }) | ||
| .catch(function(stderr) { | ||
| /* istanbul ignore next */ | ||
| notStrictEqual(stderr.trim(), 'hello world'); | ||
| /* istanbul ignore next */ | ||
| done(); | ||
| }) | ||
| }); | ||
| it('should be with hybrid api', function(done) { | ||
| var promise = exec('echo', [ | ||
| it('should be hybrid', function(done) { | ||
| var promise = execCmd('echo', [ | ||
| 'hello world' | ||
| ], function(err, res) { | ||
| var stdout = res[1]; | ||
| var code = res[0]; | ||
| strictEqual(code, 0); | ||
| assert(!err) | ||
| strictEqual(res.trim(), 'hello world'); | ||
| strictEqual(stdout.trim(), 'hello world'); | ||
| }) | ||
| .then(function(stdout) { | ||
| .then(function(res) { | ||
| var stdout = res[1]; | ||
| var code = res[0]; | ||
| strictEqual(code, 0); | ||
| strictEqual(stdout.trim(), 'hello world'); | ||
| done(); | ||
| }) | ||
| .catch(function(stderr) { | ||
| /* istanbul ignore next */ | ||
| notStrictEqual(stderr.trim(), 'hello world'); | ||
| /* istanbul ignore next */ | ||
| done(); | ||
| }) | ||
| }); | ||
| it('should pass args to node fixtures/hellow-world.js', function(done) { | ||
| var promise = exec('node', [ | ||
| it('should pass args to `node fixtures/hello-world.js`', function(done) { | ||
| var promise = execCmd('node', [ | ||
| './fixtures/hello-world.js', 'hello world' | ||
| ]) | ||
| .then(function(stdout) { | ||
| strictEqual(stdout, 'hello world'); | ||
| .then(function(res) { | ||
| var stdout = res[1]; | ||
| var code = res[0]; | ||
| strictEqual(code, 0); | ||
| strictEqual(stdout.trim(), 'hello world'); | ||
| done(); | ||
| }) | ||
| .catch(function(stderr) { | ||
| /* istanbul ignore next */ | ||
| notStrictEqual(stderr, 'hello world'); | ||
| /* istanbul ignore next */ | ||
| notStrictEqual(stderr, ''); | ||
| /* istanbul ignore next */ | ||
| done(stderr); | ||
| }) | ||
| }); | ||
| it('should give access to the underlying child process', function(done) { | ||
| var promise = exec('echo'); | ||
| strictEqual(typeof promise.cp.kill, 'function'); | ||
| done(); | ||
| }); | ||
| it('should expand using PATH_EXT properly', function(done) { | ||
@@ -94,11 +84,15 @@ if (!isWin) { | ||
| /* istanbul ignore next */ | ||
| var promise = exec(path.join(__dirname, 'fixtures/foo.bat')) // Should expand to foo.bat | ||
| .then(function(stdout) { | ||
| strictEqual(stdout, 'foo'); | ||
| var promise = execCmd(path.join(__dirname, 'fixtures/foo.bat')) // Should expand to foo.bat | ||
| .then(function(res) { | ||
| var stdout = res[1]; | ||
| var code = res[0]; | ||
| strictEqual(code, 0); | ||
| strictEqual(stdout.trim(), 'foo'); | ||
| done(); | ||
| }) | ||
| .catch(function(stderr) { | ||
| notStrictEqual(stderr, 'foo'); | ||
| notStrictEqual(stderr, ''); | ||
| done(stderr); | ||
| .catch(function(err) { | ||
| notStrictEqual(err, 'foo'); | ||
| notStrictEqual(err, ''); | ||
| done(err); | ||
| }); | ||
@@ -108,16 +102,20 @@ }); | ||
| it('should handle multibyte properly', function(done) { | ||
| var promise = exec('node', [ | ||
| var promise = execCmd('node', [ | ||
| path.join(__dirname, 'fixtures/multibyte') | ||
| ]) | ||
| .then(function(stdout) { | ||
| .then(function(res) { | ||
| var stdout = res[1]; | ||
| var code = res[0]; | ||
| strictEqual(code, 0); | ||
| strictEqual(stdout, 'こんにちは'); | ||
| done(); | ||
| }) | ||
| .catch(function(stderr) { | ||
| .catch(function(err) { | ||
| /* istanbul ignore next */ | ||
| notStrictEqual(stderr, 'こんにちは'); | ||
| notStrictEqual(err, 'こんにちは'); | ||
| /* istanbul ignore next */ | ||
| notStrictEqual(stderr, ''); | ||
| notStrictEqual(err, ''); | ||
| /* istanbul ignore next */ | ||
| done(stderr); | ||
| done(err); | ||
| }); | ||
@@ -127,15 +125,23 @@ }); | ||
| it('should fail on error code != 0', function(done) { | ||
| var promise = exec('node', [ | ||
| var promise = execCmd('node', [ | ||
| path.join(__dirname, 'fixtures/fail') | ||
| ]) | ||
| .then(function(stdout) { | ||
| .then(function(res) { | ||
| /* istanbul ignore next */ | ||
| strictEqual(stdout, ''); | ||
| var stdout = res[1]; | ||
| /* istanbul ignore next */ | ||
| var code = res[0]; | ||
| /* istanbul ignore next */ | ||
| strictEqual(code, 0); | ||
| /* istanbul ignore next */ | ||
| strictEqual(res[1], ''); | ||
| /* istanbul ignore next */ | ||
| assert(!code); | ||
| /* istanbul ignore next */ | ||
| done(); | ||
| }) | ||
| .catch(function(stderr) { | ||
| strictEqual(stderr instanceof Error, true); | ||
| strictEqual(stderr.name, 'CommandError'); | ||
| notStrictEqual(stderr, ''); | ||
| .catch(function(err) { | ||
| strictEqual(err instanceof Error, true); | ||
| strictEqual(err.name, 'CommandError'); | ||
| notStrictEqual(err, ''); | ||
| done(); | ||
@@ -142,0 +148,0 @@ }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
-50%122
37.08%17951
-3.17%186
-12.26%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed