-
Notifications
You must be signed in to change notification settings - Fork 71
[BUG] npx stops traversing looking for match if directory has package.json file #69
Comments
Typically I'd expect all commands in a repo to only ever be used at the repo root; in a monorepo, that means not running commands directly inside |
Well not everyone does it the same way. We have commands in specific packages, but none of those packages defines its own dependencies, so we can manage them all in one place from release to release. How about: if a package.json does not define dependencies or devDependencies, npx should traverse farther up the tree? |
Agree this would be pretty great, and it would be at parity with how node_modules are resolved. For modules that are shared across an entire monorepo (linters, prettier, etc) it is common to hoist or install these in the root domain. If a file deep inside the directory tree imports or requires this module it resolves fine. Yet, trying to run an npx command with a binary from one of these modules from a subdirectory fails because npx does not traverse up similar to module resolving. |
To provide more insight on why I believe this is important... Some insight: I have a mono repo. I have 1 rule, never install any packages globally. All packages, including CLI tools, are installed locally. I am wanting to remove Again the entire purpose of this is DRY. The last thing I need is over 100 packages with the same If we had a way to allow for it to traverse up to the parent root |
What / Why
copied from zkat/npx#222
We hoist all our common deps to the top-level parent, as well as common utilities (jest, eslint, pm2, etc.)
However, many of the child folders have their own package.json for one reason or another. (version strings, main: declaration, etc.)
npx won't traverse past the current directory, but only if it has a package.json. (This was reported and then closed in #210)
/package.json
/node_modules
/node_modules/.bin/foo
/packages
/packages/bar
/packages/bar/package.json
I should be able to, in packages/bar, call npx foo and have it resolve. This is expected behavior. But it won't.
If packages/bar does NOT have a package.json, npx foo will resolve to the correct in 2 parents up.
Is there a way to tell npx to keep going up the directory hierarchy looking for matches?
The text was updated successfully, but these errors were encountered: