zkat / npx

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

Q: How does npx finds the NPM_PATH? #135

Closed cswl closed 6 years ago

cswl commented 7 years ago

I'm trying to use libnpx for my nrs project. Which parses package.json and calls scripts as if with npx -c making npm run a few characters shorter..

And I see the npx cli's code here.. https://github.com/zkat/npx/blob/752db4847f42346e784a029a5e012145239d1496/bin/index.js#L6

From there it seems, npm is an depedency of npx itself.

However I couldnt find npx installed globally. it seems like it's bundled with npm itself..

bin/npx -> ../lib/node_modules/npm/bin/npx-cli.js

So how does it find it under node_modules?

zkat commented 6 years ago

because npx bundles npm, it can actually predict exactly where the npm binary is going to be, which is what that NPM_PATH is. It gets a little weird with the embedded version in npm, which goes kind of the opposite direction: npm bundles npx in that case, and there it has its own special bin file which is similar to npx/bin/index.js, but specific to the way libnpx is used in that project.

cswl commented 6 years ago

I see thanks for the information. Closing this now.