shx is a command-line wrapper for ShellJS, designed specifically for providing cross-platform Unix-like commands within npm package scripts. It enables developers to use common shell commands such as `rm`, `cp`, `ls`, `mkdir`, `echo`, and `sed` consistently across different operating systems (Unix, Windows) without encountering shell-specific syntax issues. The current stable version, 0.4.0, is based on ShellJS v0.9, and mandates Node.js v18 or newer. Its primary differentiator from ShellJS (which is suitable for longer, programmatic JavaScript scripts) is its focus on simple, one-off command executions in `package.json` scripts, offering portability and ease of integration into build tooling and development workflows. shx's release cadence is tied to its upstream ShellJS dependency. It ensures a consistent CLI experience for basic file system operations.
npm install shxVerified import paths — ran on the pinned version, not inferred.
This `package.json` example demonstrates how to use `shx` for common build script tasks like cleaning directories, copying files, and creating directories, ensuring cross-platform compatibility.
Upgrade your Node.js environment to version 18 or higher.
Adjust scripts relying on stdout from `shx sed -i` to capture or process the modified file directly, rather than its output.
Always quote glob patterns within `shx` commands in `package.json` scripts, preferably with escaped double quotes like `\"pattern\"`.
Use escaped double quotes for all arguments passed to `shx` commands, e.g., `shx echo \"Hello World!\"`.
Escape forward slashes within `sed` patterns or replacement strings (e.g., `shx sed -i "s/original\/path/replacement\/path/g" file.txt`).
Install `shx` as a development dependency (`npm install shx --save-dev`) if used in `package.json` scripts, or globally (`npm install -g shx`) if intended for direct command-line use.
Ensure all forward slashes in the regex or replacement string (that are not pattern delimiters) are escaped with a backslash. For `package.json` scripts, this often means `\\/`.
Enclose all glob patterns in escaped double quotes, e.g., `shx rm \"*.js\"` within your `package.json` script.
No dependency data recorded yet.