zkat / npx

execute npm package binaries (moved)
https://github.com/npm/npx
Other
2.63k stars 105 forks source link

Benefit of this over npm run? #235

Closed garygreen closed 5 years ago

garygreen commented 5 years ago

The readme seems to allude to the main difference being that it will automatically install the needed dependencies to run a command. Wouldn't the dev dependencies etc already be listed and installed in package.json, anyway? It would be good if the readme can be a bit more clear in what the actual benefit of using this has over just using npm i && npm run

benfletcher commented 5 years ago

It's about running a package that is not part of any repo or project.

npx executes a package without having to install it or leave any residue on the system. It also works in the way you described similarly to npm run, but is much more flexible than just that.

I use it for things that I don't want globally installed nor part of a specific project. I've used it for parsing and generating documentation from markdown files for distribution to customers. That's an occasional task for which the package being part of the repo would significantly bloat things, but I also don't want to install the package globally on any machine I might be using. There's one package in particular I've used that would slow down npm i by a factor of 10x, so I left it out of the dependencies. It takes forever to run using npx (if I don't have it installed globally), but I can just let it go in a separate terminal and work on other stuff. If it slowed down npm i, it would be a blocker.

There's a particularly good tutorial on egghead.io about npx that I believe is at least partially free. I'm using and describing here just a small fraction of its power, but still appreciate it (and fingers crossed that the project isn't abandoned: #223.)

garygreen commented 5 years ago

It sounds to me this library crosses over a bit with peerDependencies and devDependencies - except it installs only when you manually want it to. I question the complexity if this package when it has a lot of similarities when all your essentially wanting is a "throwaway" node_modules folder created with certain dependencies, on-demand. That's how I'm understanding the purpose of this project? Maybe I have a simplistic view of it though.

I think a lot of libraries could benefit from not listing huge unnecessary dependencies though, but again surely that's something that devDependencies and peerDependencies already solves pretty well?

benfletcher commented 5 years ago

I use npx to:

E.g., I'll use it to npx eslint --init a new project (that has ESLint as a dev-dependency), which is not a command that makes sense to have in my package.json scripts section.

garygreen commented 5 years ago

I'll use it to npx eslint --init a new project (that has ESLint as a dev-dependency), which is not a command that makes sense to have in my package.json scripts section.

😕 why wouldn't it make sense to have that in package.json ? I would argue it's the perfect place; just as you would commit your lint config file.

benfletcher commented 5 years ago

Of course the package is a dev dependency. But the script to init isn't.