Make JS package manager configurable (vs. detected)
Is your feature request related to a problem? Please describe.
When I run bundle exec vite install in my pnpm subproject (which is a Rails app), I get the following:
Installing js dependencies
npm ERR! code ENOTSUP
npm ERR! notsup Unsupported engine for [email protected]: wanted: {"node":">=14.18.0","npm":">=8.0.0"} (current: {"node":"14.20.0","npm":"6.14.11"})
npm ERR! notsup Not compatible with your version of node/npm: [email protected]
npm ERR! notsup Not compatible with your version of node/npm: [email protected]
npm ERR! notsup Required: {"node":">=14.18.0","npm":">=8.0.0"}
npm ERR! notsup Actual: **{"npm":"6.14.11","node":"14.20.0"}
It is looking at npm versions, even though my pnpm is updated. I believe this is because the subproject (which I believe is the config.root) does not detect a pnpm-lock.yaml file (source). pnpm-lock.yaml does exist one directory above my subproject, in my repo (and pnpm workspace) root.
Describe the solution you'd like
It would be easier to allow a user to pass in their preferred package manager as a CLI argument (or ENV var) when running bundle exec vite install versus relying on detection. The detection is great as a default, but should be configurable/overridable by the user.
Describe alternatives you've considered
None, but happy to do so if it would help. When I hardcode my preferred pnpm install into the function below, bundle exec vite install works as expected. I'm happy to submit the PR if this suggestion seems reasonable!
Additional context
Context linked above, but the def npm_install method is probably the main place I would look to make changes, along with some command line argument parsing. Relevant function: https://github.com/ElMassimo/vite_ruby/blob/eb8f678248a02b693fffe5a49309984fed92a051/vite_ruby/lib/vite_ruby/cli/install.rb#L118-L124
Hi Thomas!
The detection logic could be improved by using pkg-up to detect the project root before checking the lockfiles.
Passing the preferred package manager to install with a --with flag would also be a nice improvement:
bundle exec vite install --with pnpm
I'd prefer this second option, as it's a small change, and avoids introducing a dependency to the install process.
@ElMassimo May I implement this?
Hi Leonardo!
Passing the preferred package manager to install with a
--withflag
I think that would be a simple way to make the installer more flexible, without adding another dependency or increasing the complexity.
Go for it!
🚀