npx icon indicating copy to clipboard operation
npx copied to clipboard

feature request: use node-module-resolution algorithm when scanning for bins

Open iarna opened this issue 7 years ago • 7 comments

That is:

If the binary isn't global and can't be find in package-root/node_modules/.bin then check for parent packages, eg package-root/../node_modules/.bin.

This would make working in monorepos easier when things like the test client are installed at the top level, but you're inside a sub-project.

iarna avatar Sep 21 '17 20:09 iarna

This is interesting. I'm a bit worried about it potentially causing serious surprise for people. I'm also wondering about the perf impact, but... I guess we can literally just add every single combination of node_modules/.bin up the absolute path of the current prefix (in the right order), and let the OS handle it? That might be cool, and would require no extra fs hits for us.

Would you be interested in adding this feature?

zkat avatar Sep 30 '17 02:09 zkat

literally just add every single combination of node_modules/.bin up the absolute path of the current prefix

This is what I was thinking, yeah.

iarna avatar Sep 30 '17 02:09 iarna

@zkat

I'v implemented the feature and create a PR https://github.com/zkat/npx/pull/164 several months ago.

Would you please take some time to review it ?

malash avatar Jul 17 '18 06:07 malash

Could we at least add it as a flag --recurseUp or something? Would be really helpful for monorepo projects.

natew avatar Jul 20 '18 15:07 natew

I recently converted a project to a monorepo with hoisted dependencies and was surprised npx didn't use the module resolution algorithm, so I couldn't use my hoisted dependencies when running npx inside a specific package's folder. Not the worst thing to work around by any means, but it would be great if #164 or similar was added!

thomasboyt avatar Aug 04 '18 21:08 thomasboyt

Just trying to share my devDependencies in a monorepo using npx and this would allow me to get it to work, getting really tired of managing many packages when they become out of date. This seems like a very logical feature to implement, please can we work out a way to include this to reduce the maintenance burden of upgrading devDependencies.

tmpfs avatar Jan 01 '19 05:01 tmpfs

@zkat @iarna I am very interested in https://github.com/zkat/npx/pull/164 too, when using lerna in hoisted mode it is pretty essential.

Now npx is part of npm, is this the correct place to have this conversation?

blackmamo avatar Jan 04 '19 15:01 blackmamo