npm / rfcs

Public change requests/proposals & ideation
Other
730 stars 240 forks source link

[RRFC] Ensure that binaries defined by the current package are recognized as available binaries inside itself by npm run #673

Open fabiospampinato opened 1 year ago

fabiospampinato commented 1 year ago

Motivation ("The Why")

The motivations behind this is that it seems natural to me, even if a bit niche, and scripts defined like this are the cleanest possibly way to write them that I can think of:

{
  "name": "pkg",
  "bin": "./src/index.js",
  "scripts": {
     "something": "pkg something"
  }
}

Notice how the something script inside pkg references the pkg bin, i.e. itself.

Example

See above.

How

Current Behaviour

Currently running an npm run something leads to an error saying that pkg has not been found.

Desired Behaviour

npm run should take into consideration the binaries defined by the current package, and consider them as available binaries too.

References

ljharb commented 1 year ago

While I'd love this, I'm not sure how it would work, since npm run primarily works by setting up the PATH to include node_modules/.bin. I suppose npm install (only the toplevel one) could add its own bins to node_modules/.bin, and that would Just Work?