tiny-cross-spawn
v1.0.1
Published
Zero-dependency, dual CJS/ESM, ReDoS-safe drop-in replacement for cross-spawn
Maintainers
Readme
Why?
For over a decade, cross-spawn has been the universal foundation for cross-platform process execution across Node.js.
However, it was originally designed in the Node 0.10 era, pulling in 5 transitive dependencies (which, isexe, path-key, shebang-command, shebang-regex) and relying on regular expressions for argument escaping that historically introduced ReDoS vulnerabilities (such as CVE-2024-21538).
tiny-cross-spawn is a modern, zero-dependency drop-in replacement engineered for current runtimes (Node.js 18+, Bun, and Deno):
- Zero runtime dependencies: Pure native
PATHEXTand shebang resolution using standard library built-ins. - Linear O(N) Quoting: Deterministic character scanning without regex backtracking (immune to ReDoS).
- Full Dual ESM and CJS support: Native
exportsmap for bothimportandrequire(). - Native TypeScript definitions: Strongly-typed
dist/index.d.tsincluded out of the box. - Exhaustive Parity: 100% pass rate against
node-cross-spawn's original test suite. - Tiny footprint: ~2.5 KB minified.
Installation
npm install tiny-cross-spawnUsage
Asynchronous (spawn)
import { spawn } from 'tiny-cross-spawn';
const child = spawn('npm', ['test'], { stdio: 'inherit' });
child.on('close', (code) => {
console.log(`Child process exited with code ${code}`);
});Synchronous (spawnSync / spawn.sync)
import { spawnSync } from 'tiny-cross-spawn';
const result = spawnSync('npm', ['--version']);
console.log(result.stdout.toString().trim());CommonJS
const spawn = require('tiny-cross-spawn');
const { spawnSync } = require('tiny-cross-spawn');
const res = spawnSync('node', ['-v']);
console.log(res.stdout.toString());API Parity with Node & cross-spawn
tiny-cross-spawn strictly matches the function signatures and return types of Node's native child_process.spawn and node-cross-spawn:
spawn(command, [args], [options]): ChildProcessspawnSync(command, [args], [options]): SpawnSyncReturns<Buffer | string>spawn.sync: Alias tospawnSync
License
MIT © nanasi
