zkat / npx

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

Feature Request: exec files from package.json "bin" #169

Open rottmann opened 6 years ago

rottmann commented 6 years ago

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

project
|- bin
    |- my-installer.js
    |- my-other-bin.js

package.json

{
  ...
  "bin": {
    "install": "bin/my-installer.js",
    "foo": "bin/my-ohter-bin.js",
  }
  ...
}

$ 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.

zkat commented 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 🤔

benallfree commented 5 years ago

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.