pnpm icon indicating copy to clipboard operation
pnpm copied to clipboard

pnpx / pnpm exec that only runs a projects local package bin (ignores global)

Open basickarl opened this issue 4 months ago • 0 comments

Contribution

Describe the user story

We would like a way (preferably a flag) to run only locally installed packages to a project. When I say locally, I mean within the scope of a project (package.json). Currently when using pnpx or pnpm exec it first looks for the pacakge in the local projects node_modules bin directory then moves onto the global user node_modules (installed via npm install -g).

The reason we want this, is because we want to make sure that 1. the package to be used was indeed installed locally to the project 2. we wish that the correct version of the package is being used (globally installed might differ in version). We might have a script that has a special build with caching of packages and we want to make sure than when our scripts are run via pnpx/pnpm exec that the intended package is indeed being run.

There is one way of doing this currently and it is to specify the path to the bin when trying to invoke it e.g.: ./node_modules/.bin/foo.

Describe the solution you'd like

A flag. Something like pnpx --local foo / pnpm exec --local foo. This would be akin to also not automatically installing the package if not found nor temporarily installing and hotloading.

Other ideas of flag terms:

--no-global
--only-local
--only-project-local

Describe the drawbacks of your solution

There are no drawbacks, it's a perfect solution to a problem.

Describe alternatives you've considered

Hard coded paths as mentioned can solve this currently. We shouldn't have to hard code these paths in our scripts.

basickarl avatar Oct 11 '24 15:10 basickarl