I thought I'd throw out that in certain situations, there is another solution: install the tool as a dev depedency locally and call it from a run script.
npm does this trick that I don't think many folks are aware of: whenever you install a module with a "bin" entry in it's package.json, it installs a link to that bin entry in node_modules/.bin. Then, whenever you call a run script, npm will automatically append node_modules/.bin to your path before executing any commands. The upshot is that you don't have to require your users to do a manual step, you don't have to wait for npx to download the dependency on the fly, and you can control the version of prettydiff like you would for any other dependency.
Your package.json would effectively look like this:
This does assume that you want this dependency tracked in package.json though, which isn't always the case, and I do think npx is a little more flexible in the end. Still a good trick though.
This is really cool! I didn't know about this. Being able to execute the package without having to download it is pretty nice. Thanks for sharing this!
I never knew about this! I've seen many projects suggest using this, but was always incredibly frustrated because I could never quite get it to work and always ended up installing globally. My assumption was that the authors were making an assumption that I already have the module globally installed.
Thanks for sharing this, Bryan! 💖
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Cool article! 💜 npx!
I thought I'd throw out that in certain situations, there is another solution: install the tool as a dev depedency locally and call it from a run script.
npm does this trick that I don't think many folks are aware of: whenever you install a module with a
"bin"
entry in it'spackage.json
, it installs a link to that bin entry innode_modules/.bin
. Then, whenever you call a run script, npm will automatically appendnode_modules/.bin
to your path before executing any commands. The upshot is that you don't have to require your users to do a manual step, you don't have to wait for npx to download the dependency on the fly, and you can control the version of prettydiff like you would for any other dependency.Your package.json would effectively look like this:
This does assume that you want this dependency tracked in package.json though, which isn't always the case, and I do think npx is a little more flexible in the end. Still a good trick though.
This is really cool! I didn't know about this. Being able to execute the package without having to download it is pretty nice. Thanks for sharing this!
I never knew about this! I've seen many projects suggest using this, but was always incredibly frustrated because I could never quite get it to work and always ended up installing globally. My assumption was that the authors were making an assumption that I already have the module globally installed.
Thanks for sharing this, Bryan! 💖