Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/ispawn
Spawn a process to inspect it.
https://github.com/thlorenz/ispawn
Last synced: 2 months ago
JSON representation
Spawn a process to inspect it.
- Host: GitHub
- URL: https://github.com/thlorenz/ispawn
- Owner: thlorenz
- License: mit
- Created: 2018-07-31T17:32:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-03T17:26:52.000Z (over 6 years ago)
- Last Synced: 2024-10-18T00:31:35.599Z (3 months ago)
- Language: JavaScript
- Homepage: https://thlorenz.github.io/ispawn
- Size: 1.14 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ispawn [![build status](https://secure.travis-ci.org/thlorenz/ispawn.svg?branch=master)](http://travis-ci.org/thlorenz/ispawn)
Spawn a process to inspect it.
## Installation
npm install ispawn
## [API](https://thlorenz.github.io/ispawn)
### createSpawn
Configures a process to be spawned but doesn't spawn it yet
**Parameters**
- `$0` **Objects** options (same as @see `spawn`)
Returns **Spawner** that will spawn the configured process via `spawner.spawn`
### spawn
Spawns a process with the given options allowing to intercept `stdout`
and `stderr` output of the application itself or the underlying process,
i.e. V8 and Node.js messages.#### onStdout and onStderr interceptors
The functions, `onStdout`, `onStderr` called with each line written to the
respective file descriptor have the following signature:`onStdout(line:String, fromApp:Boolean)` where `fromApp` is `true` when the
line came from the app itself and `false` when it came from the underlying
runtime, i.e. Node.js or V8 when flags triggered diagnostics output.To mark a line as _handled_ return `true` from the function and it will not
be printed to the console.#### Example
```js
function onStdout(line, fromApp) {
// Don't intercept app output, just have it printed as usual
if (fromApp) return false
// Do something with diagnositics messages here ...return true
}
const { termination } = spawn({
execArgv: [ '--trace-turbo-inlining' ]
, argv: [ require.resolve('./bind.js') ]
, onStdout
})try {
const code = await termination
console.log('The app returned with code', code)
} catch (err) {
console.error(err)
}
```[full example](https://github.com/thlorenz/ispawn/blob/master/example/map-inlines)
**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options
- `$0.execArgv` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>?** arguments passed to Node.js/V8 directly (not to your app) (optional, default `[]`)
- `$0.argv` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** file to run followed by flags to pass to your app
- `$0.node` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** path to Node.js executable (optional, default `process.execPath`)
- `$0.spawnOpts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** options passed to `child_process.spawn` (optional, default `{}`)
- `$0.onStdout` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** function to call with each line written to stdout (optional, default `null`)
- `$0.onStderr` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** function to call with each line written to stderr (optional, default `null`)Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** with the following properties- termination: {Promise} that resolves when process exits
- proc: the spawned process## Kudos
Lots of the ideas and code were extracted from the [0x
tool](https://github.com/davidmarkclements/0x).## License
MIT