Open rottmann opened 6 years ago
npx already has some logic around local directory execution. What you're suggesting can already work with npx -p . install
. I think this is reasonable enough, as I don't want to take on the breaking change that would be to allow arbitrary shadowing of commands based on the current directory -- which I would've been more comfortable with earlier in npx
's life.
I'll think about this, though. I think this might actually be a handy thing to make default behavior 🤔
I agree this makes a lot of sense, because it means you're testing you own bin scripts using the same command (npx install
) everyone else will be using, rather than node ./bin/my-installer.js
.
I'm unclear on how npm
handles bin name collisions across packages. That's the only case where I can imagine shadowing being a problem.
Let npx locate the "bin" from package.json first and execute it. It is meant for when you develop a project and you work in the directory, at this point your project isn't installed and you don't have bin-files in
node_modules
.Example: Structure
package.json
$ cd project
$ npx install
should look into package.json for "bin.install" and execute "bin/my-installer.js"$ npx foo
should look into package.json for "bin.foo" and execute "bin/my-other-bin.js"It will be a nicer version of defined "scripts" and exec them with "npm run", you can always work with npx.