npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shx

v0.3.4

Published

Portable Shell Commands for Node

Downloads

3,038,472

Readme

Shx

Build Status Codecov npm version npm downloads

shx is a wrapper around ShellJS Unix commands, providing an easy solution for simple Unix-like, cross-platform commands in npm package scripts.

shx is proudly tested on every node release since v6!

Difference Between ShellJS and shx

  • ShellJS: Good for writing long scripts, all in JS, running via NodeJS (e.g. node myScript.js).
  • shx: Good for writing one-off commands in npm package scripts (e.g. "clean": "shx rm -rf out/").

Install

npm install shx --save-dev

This will allow using shx in your package.json scripts.

Usage

Command Line

If you'd like to use shx on the command line, install it globally with the -g flag. The following code can be run either a Unix or Windows command line:

$ shx pwd                       # ShellJS commands are supported automatically
/home/username/path/to/dir

$ shx ls                        # files are outputted one per line
file.txt
file2.txt

$ shx rm *.txt                  # a cross-platform way to delete files!

$ shx ls

$ shx echo "Hi there!"
Hi there!

$ shx touch helloworld.txt

$ shx cp helloworld.txt foobar.txt

$ shx mkdir sub

$ shx ls
foobar.txt
helloworld.txt
sub

$ shx rm -r sub                 # options work as well

$ shx --silent ls fakeFileName  # silence error output

All commands internally call the ShellJS corresponding function, guaranteeing cross-platform compatibility.

package.json

ShellJS is good for writing long scripts. If you want to write bash-like, platform-independent scripts, we recommend you go with that.

However, shx is ideal for one-liners inside package.json:

{
  "scripts": {
    "clean": "shx rm -rf build dist && shx echo Done"
  }
}

Tip: because Windows treats single quotes (ex. 'some string') differently than double quotes, we recommend wrapping your arguments in double quotes for cross platform compatibility (ex. "some string").

Command reference

Shx exposes most ShellJS commands. If a command is not listed here, assume it's supported!

sed

Shx provides unix-like syntax on top of shell.sed(). So ShellJS code like:

shell.sed('-i', /original string/g, 'replacement', 'filename.txt');

would turn into the following Shx command:

shx sed -i "s/original string/replacement/g" filename.txt

Note: like unix sed, shx sed treats / as a special character, and this must be escaped (as \/ in the shell, or \\/ in package.json) if you intend to use this character in either the regex or replacement string. Do not escape / characters in the file path.

Unsupported Commands

As mentioned above, most ShellJS commands are supported in ShellJS. Due to the differences in execution environments between ShellJS and shx (JS vs CLI) the following commands are not supported:

| Unsupported command | Recommend workaround | | ------------------- | -------------------- | | shx cd | Just use plain old cd (it's the same on windows too) | | shx pushd | Just use plain old pushd. Use forward slashes and double-quote the path. (e.g. pushd "../docs". This would fail on Windows without the quotes) | | shx popd | Just use plain old popd | | shx dirs | No workaround | | shx set | See below | | shx exit | Just use plain old exit | | shx exec | Instead of shx exec cmd, just use plain old cmd | | shx ShellString | No workaround (but why would you want this?) |

Shx options

Shx allows you to modify its behavior by passing arguments. Here's a list of supported options:

| set flag | shell.config setting | shx command | Effect | |:---:| --- | --- | --- | | -e | config.fatal = true | Not supported | Exit upon first error | | -v | config.verbose = true | shx --verbose cd foo | Log the command as it's run | | -f | config.noglob = true | shx --noglob cat '*.txt' | Don't expand wildcards | | N/A | config.silent = true | shx --silent cd noexist | Don't show error output |

Team

| Nate Fischer | Ari Porad | Levi Thomason | |:---:|:---:|:---:| | Nate Fischer | Ari Porad | Levi Thomason |