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

Handle node_modules without package.json #128

Merged
merged 1 commit into from
Nov 6, 2017

Conversation

jridgewell
Copy link
Contributor

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 #104.
Fixes babel/babel#4066 (comment).

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 zkat#104.
Fixes babel/babel#4066 (comment).
@jridgewell
Copy link
Contributor Author

Ping @zkat, in case this slipped your radar.

@zkat
Copy link
Owner

zkat commented Nov 6, 2017

It did indeed slip my radar!

Copy link
Owner

@zkat zkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks a bunch for the patch!

@zkat zkat merged commit f64ae43 into zkat:latest Nov 6, 2017
@jridgewell jridgewell deleted the without-package.json branch December 13, 2017 19:35
@back2dos
Copy link

back2dos commented Feb 3, 2018

Any plans for a release that would include this?

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