@nartallax/npm-run
v1.0.3
Published
A small command-line tool to substitute `npm run` with.
Downloads
293
Readme
@nartallax/npm-run
A small command-line tool to substitute npm run
with.
Install
npm install -g @nartallax/npm-run
Use
nr my-command-from-packagejson
Optimization(s)
If command starts with node something.mjs
, or just ./something.mjs
- the mjs file will be imported within process of npm-run (with argv and cwd updated to match what file would expect). This avoids to spin up new NodeJS instance.
This optimization is applied on very specific conditions - all arguments must be alphanumeric (otherwise we are at risk of misinterpreting some smart-er shell syntax as arguments, which will lead to unexpected results).
Also there must be exactly one space between node
and path start (or no spaces in the case of shebanged script call). This allows to override this optimization by adding more spaces, which should not affect logic of the script.
Every command not matching above conditions will just be run in system's default shell.
Why?
I like to keep every single action I may want to run about my project in package.json
scripts. Literally everything - build actions, diagnostics, systemd management...
This requires me to run npm run commandname
every time I want to run a command. It's convenient to have everything in one place, but comes with some problems:
npm run
sometimes takes noticeably more time than just running the command in the shell (sometimes up to 400ms more time). It's not much, but in case of short-lived commands like "show me systemd status of my service" it is very noticeable. (and yes,yarn
also has this problem, sometimes even worse).npm run
is a bit too much characters to type for my taste.
So here comes this package, adding nr
command, that does exactly the same as npm run
, just slightly better.