Gathering detailed insights and metrics for ez-spawn
Gathering detailed insights and metrics for ez-spawn
Gathering detailed insights and metrics for ez-spawn
Gathering detailed insights and metrics for ez-spawn
@jsdevtools/ez-spawn
Simple, consistent sync or async process spawning
cross-spawn
Cross platform child_process#spawn and child_process#spawnSync
@types/cross-spawn
TypeScript definitions for cross-spawn
spawn-command
Spawn commands like `child_process.exec` does but return a `ChildProcess`
npm install ez-spawn
61
Supply Chain
94.2
Quality
75.7
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
13 Stars
157 Commits
1 Forks
3 Watching
1 Branches
3 Contributors
Updated on 30 Sept 2024
JavaScript (86.19%)
TypeScript (13.81%)
Cumulative downloads
Total Downloads
Last day
163.4%
324
Compared to previous day
Last week
74.7%
2,646
Compared to previous week
Last month
253.1%
7,804
Compared to previous month
Last year
-49.5%
32,923
Compared to previous year
1
Flexible input parameters
Pass the program and arguments as a single string, an array of strings, or as separate parameters.
Pick your async syntax
Supports Promises, async
/await
, or callbacks.
Simple, consistent error handling
Non-zero exit codes are treated just like any other error. See Error Handling for more details.
String output by default
stdout and stderr output is automatically decoded as UTF-8 text by default. You can set the encoding
option for a different encoding, or even raw binary buffers.
Windows Support
Excellent Windows support, thanks to cross-spawn.
1const ezSpawn = require('@jsdevtools/ez-spawn'); 2 3// These are all identical 4ezSpawn.sync(`git commit -am "Fixed a bug"`); // Pass program and args as a string 5ezSpawn.sync("git", "commit", "-am", "Fixed a bug"); // Pass program and args as separate params 6ezSpawn.sync(["git", "commit", "-am", "Fixed a bug"]); // Pass program and args as an array 7ezSpawn.sync("git", ["commit", "-am", "Fixed a bug"]); // Pass program as a string and args as an array 8 9// Make a synchronous call 10let process = ezSpawn.sync(`git commit -am "Fixed a bug"`); 11console.log(process.stdout); 12 13//Make an asynchronous call, using async/await syntax 14let process = await ezSpawn.async(`git commit -am "Fixed a bug"`); 15console.log(process.stdout); 16 17//Make an asynchronous call, using callback syntax 18ezSpawn.async(`git commit -am "Fixed a bug"`, (err, process) => { 19 console.log(process.stdout); 20}); 21 22//Make an asynchronous call, using Promise syntax 23ezSpawn.async(`git commit -am "Fixed a bug"`) 24 .then((process) => { 25 console.log(process.stdout); 26 });
Install using npm:
1npm install @jsdevtools/ez-spawn
Then require it in your code:
1// Require the whole package 2const ezSpawn = require("@jsdevtools/ez-spawn"); 3 4// Or require "sync" or "async" directly 5const ezSpawnSync = require("@jsdevtools/ez-spawn").sync; 6const ezSpawnAsync = require("@jsdevtools/ez-spawn").async;
ezSpawn.sync(command, [...arguments], [options])
Synchronously spawns a process. This function returns when the proecess exits.
The command
and arguments
parameters can be passed as a single space-separated string, or as an array of strings, or as separate parameters.
The options
object is optional.
Returns a Process
object
ezSpawn.async(command, [...arguments], [options], [callback])
Asynchronously spawns a process. The Promise resolves (or the callback is called) when the process exits.
The command
and arguments
parameters can be passed as a single space-separated string, or as an array of strings, or as separate parameters.
The options
object is optional.
If a callback
is provided, then it will be called when the process exits. The first is either an Error
or null
. The second parameter is a Process
object.
If no callback
is provided, then a Promise is returned. It will resolve with a Process
object when the process exits.
Options
objectezSpawn.async()
and ezSpawn.sync()
both accept an optional options
object that closely mirrors the options
parameter of Node's spawn
, exec
, spawnSync
, and execSync
functions.
cwd
(string)
The current working directory of the child process.
env
(Object)
Environment variable key-value pairs.
argv0
(string)
Explicitly set the value of argv[0]
sent to the child process. This will be set to command
if not specified.
stdio
(Array or string)
The child process's stdio configuration (see options.stdio).
input
(string, Buffer, TypedArray, or DataView)
The value which will be passed as stdin to the spawned process. Supplying this value will override stdio[0]
.
uid
(number)
Sets the user identity of the process.
gid
(number)
Sets the group identity of the process.
timeout
(number)
The maximum amount of time (in milliseconds) the process is allowed to run.
killSignal
(string or integer)
The signal value to be used when the spawned process will be killed. Defaults to "SIGTERM"
.
maxBuffer
(number)
The largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated.
encoding
(string)
The encoding used for all stdio inputs and outputs. Defaults to "utf8"
. Set to "buffer"
for raw binary output.
shell
(boolean or string)
If true
, then command
will be run inside of a shell. Uses "/bin/sh" on UNIX, and process.env.ComSpec
on Windows. A different shell can be specified as a string.
windowsVerbatimArguments
(boolean)
No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to true automatically when shell
is "CMD"
.
windowsHide
(boolean)
Hide the subprocess console window that would normally be created on Windows systems.
Process
objectezSpawn.async()
and ezSpawn.sync()
both return a Process
object that closely mirrors the object returned by Node's spawnSync
function.
command
(string)
The command that was used to spawn the process.
args
(array of strings)
The command-line arguments that were passed to the process.
pid
(number)
The numeric process ID assigned by the operating system.
stdout
(string or Buffer)
The process's standard output. This is the same value as output[1]
.
stderr
(string or Buffer)
The process's error output. This is the same value as output[2]
.
output
(array of strings or Buffers)
The process's stdio [stdin, stdout, stderr].
status
(number)
The process's status code (a.k.a. "exit code").
signal
(string or null)
The signal used to kill the process, if the process was killed by a signal.
toString()
Returns the command
and args
as a single string. Useful for console logging.
All sorts of errors can occur when spawning processes. Node's built-in spawn
and spawnSync
functions handle different types of errors in different ways. Sometimes they throw the error, somtimes they emit an "error" event, and sometimes they return an object with an error
property. They also don't treat non-zero exit codes as errors. So it's up to you to handle all these different types of errors, and check the exit code too.
EZ Spawn simplifies things by treating all errors the same. If any error occurs, or if the process exits with a non-zero exit code, then an error is thrown. The error will have all the same properties as the Process
object, such as status
, stderr
, signal
, etc.
1try { 2 let process = ezSpawn.sync(`git commit -am "Fixed a bug"`, { throwOnError: true }); 3 console.log("Everything worked great!", process.stdout); 4} 5catch (error) { 6 console.error("Something went wrong!", error.status, error.stderr); 7}
Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.
To build/test the project locally on your computer:
Clone this repo
git clone hhttps://github.com/JS-DevTools/ez-spawn.git
Install dependencies
npm install
Run the tests
npm test
EZ Spawn is 100% free and open-source, under the MIT license. Use it however you want.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
Thanks to these awesome companies for their support of Open Source developers ❤
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More