zkat / npx

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

Handle node_modules without package.json #128

Closed jridgewell closed 7 years ago

jridgewell commented 7 years ago

This fixes running npx inside temporary projects (ones that have a node_modules but don't have a package.json).

getPrefix() has useful cases:

  1. Finds a path with a package.json, returns it.
  2. Finds a path with a node_modules, returns it.
  3. Finds nothing, returns the original path.

Cases 1 and 2 return a path that's useful to npx, but case 3 doesn't. But, localBinPath() confused case 2 and 3 (by stating for a package.json), making npx only work with case 1. That's no good.

This makes cases 1 and 2 distinct from case 3 (it just returns false now). And localBinPath() no longer has to do any stating to differentiate between paths and false, so it's happy. And now npx can run without a local package.json. Yay!

Fixes https://github.com/zkat/npx/issues/104. Fixes https://github.com/babel/babel/issues/4066#issuecomment-336705199.

jridgewell commented 7 years ago

Ping @zkat, in case this slipped your radar.

zkat commented 7 years ago

It did indeed slip my radar!

back2dos commented 6 years ago

Any plans for a release that would include this?