Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

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

Open
rottmann opened this issue Apr 6, 2018 · 2 comments
Open

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

rottmann opened this issue Apr 6, 2018 · 2 comments

Comments

@rottmann
Copy link

rottmann commented Apr 6, 2018

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
Copy link
Owner

zkat commented May 3, 2018

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants