spawncommand
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -1,3 +0,14 @@ | ||
## 1.1.0 (19 April 2017) | ||
## 15 May 2018 | ||
### 2.0.0 | ||
- [feature] fork Node modules | ||
- [ecma] update to modules system | ||
- [dep] update dependencies, install babel | ||
- [github] move to [Art Deco Code](https://artdeco.bz) | ||
## 19 April 2017 | ||
### 1.1.0 | ||
- [bugfix] do not trim output | ||
@@ -4,0 +15,0 @@ - [code] use `catchment` package |
{ | ||
"name": "spawncommand", | ||
"version": "1.1.0", | ||
"description": "spawn which returns a process with a promise property, fulfilled with { code, stdout, stderr }", | ||
"main": "src/index", | ||
"version": "2.0.0", | ||
"description": "Spawn a child process with a promise property resolved on exit with stdout, stderr and code", | ||
"main": "build", | ||
"files": [ | ||
"src/" | ||
"build" | ||
], | ||
"scripts": { | ||
"test": "zoroaster test/spec" | ||
"t": "zoroaster --babel", | ||
"build": "babel src --out-dir build", | ||
"test": "zoroaster test/spec --babel", | ||
"test-build": "BABEL_ENV=test-build zoroaster test/spec --babel", | ||
"test-all": "yarn-s test test-build", | ||
"example/spawncommand.js": "node example example/spawncommand", | ||
"example/fork.js": "node example example/fork", | ||
"example/pipe.js": "node example example/pipe" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Sobesednik/spawncommand.git" | ||
"url": "git+https://github.com/artdecocode/spawncommand.git" | ||
}, | ||
@@ -21,16 +28,25 @@ "keywords": [ | ||
"stdout", | ||
"stderr" | ||
"stderr", | ||
"ChildProcess", | ||
"stdio" | ||
], | ||
"author": "anton <anton@sobes.io>", | ||
"author": "anton <anton@adc.sh>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Sobesednik/spawncommand/issues" | ||
"url": "https://github.com/artdecocode/spawncommand/issues" | ||
}, | ||
"homepage": "https://github.com/Sobesednik/spawncommand#readme", | ||
"homepage": "https://github.com/artdecocode/spawncommand#readme", | ||
"devDependencies": { | ||
"zoroaster": "^0.3.0" | ||
"@babel/cli": "7.0.0-beta.46", | ||
"@babel/core": "7.0.0-beta.46", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.46", | ||
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.46", | ||
"@babel/register": "7.0.0-beta.46", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "1.1.0" | ||
}, | ||
"dependencies": { | ||
"catchment": "^1.0.0" | ||
"babel-plugin-transform-rename-import": "2.2.0", | ||
"catchment": "2.0.1" | ||
} | ||
} |
@@ -1,53 +0,72 @@ | ||
# spawncommand | ||
# spawnCommand | ||
extend `require('child_process').spawn` to set `.promise` property | ||
on the returned object. The promise will be fulfilled on process | ||
exit with a hash of `code`, `stdout` and `stderr`, where `code` | ||
is the exit code, `stdout` is all data the process wrote to | ||
_stdout_, and `stderr` is all data the process wrote to _stderr_. | ||
The promise will be rejected if `process.on('error')` fired. | ||
[](https://badge.fury.io/js/spawncommand) | ||
``` | ||
npm i --save spawncommand | ||
yarn add -E spawncommand | ||
``` | ||
``` | ||
const spawnCommand = require('spawncommand') | ||
This package is a wrapper around `child_process.spawn` methods to set `.promise` property on the returned `ChildProcess` instances. The promise will be fulfilled on process exit with an object consisting of `code`, `stdout` and `stderr` properties, where: | ||
const echo = spawnCommand('echo', ['hello world']) | ||
echo | ||
.promise | ||
.then((res) => { | ||
console.error(res) | ||
}) | ||
// { code: 0, stdout: 'hello world', stderr: '' } | ||
// echo is instance of ChildProcess) | ||
- `code` is the exit code | ||
- `stdout` is all data the process wrote to _stdout_ | ||
- `stderr` is all data the process wrote to _stderr_ | ||
The promise will be rejected if an error was encountered when trying to spawn the process. | ||
```js | ||
/* yarn example/spawncommand.js */ | ||
import spawnCommand from 'spawncommand' | ||
(async () => { | ||
const { promise } = spawnCommand('echo', ['hello world']) | ||
const { stderr, stdout, code } = await promise | ||
console.log(stderr) // undefined | ||
console.log(stdout) // hello world\n | ||
console.log(code) // 0 | ||
})() | ||
``` | ||
## Testing | ||
Because the returned object is a `ChildProcess`, all its properties can be accessed. | ||
[zoroaster](https://www.npmjs.com/package/zoroaster) | ||
```js | ||
/* yarn example/pipe.js */ | ||
import spawnCommand from 'spawncommand' | ||
(async () => { | ||
const { stdout, promise } = spawnCommand('echo', ['hello world']) | ||
stdout.pipe(process.stdout) | ||
await promise | ||
})() | ||
``` | ||
npm t | ||
> spawncommand@1.0.0 test /Users/zavr/Work/spawnCommand | ||
> zoroaster test/spec | ||
## fork | ||
test/spec | ||
index.js | ||
✓ spawnCommand | ||
✓ spawnExit0Command | ||
✓ spawnExit1Command | ||
✓ spanwWithNoChannels | ||
✓ spawnError | ||
message | ||
✓ stdout | ||
✓ stderr | ||
✓ exit0 | ||
✓ exit1 | ||
It is also possible to fork a Node.js process and execute a module in it. | ||
Executed 9 tests. | ||
```js | ||
/* yarn example/fork.js */ | ||
import { resolve } from 'path' | ||
import { fork } from 'spawncommand' | ||
const MODULE_PATH = resolve(__dirname, 'example/spawn.js') | ||
;(async () => { | ||
const { promise } = fork('example/spawn.js', [], { | ||
stdio: 'pipe', | ||
}) | ||
const { stdout } = await promise | ||
console.log(stdout) // same output as example/spawn.js | ||
})() | ||
``` | ||
Make sure to pass `pipe` option to be able to gather stderr and stdout streams (or an array for versions of Node.js when [this does not work][2]). | ||
--- | ||
(c) [Art Deco Code][1] 2018 | ||
[1]: https://artdeco.bz | ||
[2]: https://github.com/nodejs/node/pull/10866 |
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
7276
67
73
1
2
7
+ Addedbabel-plugin-transform-rename-import@2.2.0(transitive)
+ Addedcatchment@2.0.1(transitive)
- Removedcatchment@1.0.0(transitive)
Updatedcatchment@2.0.1