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

bin path in directory without package.json but with node_modules/ #104

Closed
kaleb opened this issue Jul 28, 2017 · 0 comments · Fixed by #128
Closed

bin path in directory without package.json but with node_modules/ #104

kaleb opened this issue Jul 28, 2017 · 0 comments · Fixed by #128

Comments

@kaleb
Copy link

kaleb commented Jul 28, 2017

If I am in a directory with a node_modules directory and no package.json, npx does not find the appropriate binary in my opinion.

Example:

$ mkdir -p /tmp/test
$ cd /tmp/test/
$ npm install -D typescript
npm WARN saveError ENOENT: no such file or directory, open '/tmp/test/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/tmp/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.

+ typescript@2.4.2
added 1 package in 1.757s
$ ./node_modules/.bin/tsc --version
Version 2.4.2
$ npx tsc --version
npx: installed 1 in 1.856s
message TS6029: Version 1.5.3
$ # EXPECTED: Version 2.4.2, but a different package from npm altogether was used.
$ npx -p typescript tsc --version
npx: installed 1 in 1.789s
Version 2.4.2
$ 

Changing the definition of path to allow directories that contain a node_modules directory without a package.json file would be useful because sometimes if a developer wanted to quickly test something without running npm init. Also, this would be similar to how node itself does package lookups.

jridgewell added a commit to jridgewell/npx that referenced this issue Oct 19, 2017
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 added a commit to jridgewell/npx that referenced this issue Oct 19, 2017
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).
@zkat zkat closed this as completed in #128 Nov 6, 2017
zkat pushed a commit that referenced this issue Nov 6, 2017
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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants