Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAutomatically detect package manager (npm.packageManager) #102050
Comments
|
I'm also not against making an extension for this, but I figured it would be best to propose it internally first for better support with existing features and other extensions. |
|
I am not opposed to an auto option for |
|
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation. Happy Coding! |
|
@alexr00 I'm willing to work on this one. Should the development be started only after this issue has moved from Backlog Candidate to the Backlog? |
|
@shivangg thanks for checking, especially since we aren't always consistent about what to do there. If you start working on it I will move it into the current milestone. More spec-ing details:
Making
Agree that default should be npm if there is not lock file.
A warning if there are multiple lock files AND |
|
@alexr00 Thanks for the reply. Here's a draft PR. As |
|
@alexr00 I'm not sure of the cleanest way to detect multiple lockfiles. Is there a better way to proceed without deduplicating the |
|
@shivangg, I don't know of a better way. |
Problem
When switching between many JavaScript projects, it's often easy to forget which package manager should be used in each project. JavaScript package managers aren't quite compatible either. Each package manager resolves dependencies differently, so accidentally installing with npm could cause a yarn project to break.
While VSCode has the
npm.packageManageroption to switch between npm, yarn, and pnpm, it's not very convenient to have to remember to set it on every project. Even if a user has a global preference, they will often have to clone several projects they're contributing to using other package managers anyway. Personally, I have so many projects installed that it's too inconvenient for me to set this option, so I end up figuring out which package manager to use manually and running it in the terminal.Proposed option changes
I would like
npm.packageManagerto default to a newautooption, which would select a package manager based on the presence of workspace and lock files usingpreferred-pm. If a lock file doesn't exist, the user is probably using npm anyway, and we can just default tonpmlike we already are. It would also be nice to set up some sort of warning if multiple lock files are found, as most package managers do this to inform users that their package installations can break because of differences in version resolution.Ideas for extension API changes
I'm not actually familiar with the extension APIs, but I think it would be nice to expose this as some sort of generic API for extensions so they don't have to reimplement this functionality or reinstall dependencies. This would also prevent extensions from breaking if VSCode changed its package manager detection heuristics in the future. This also might be useful for other internal features like automatically installing projects when cloned with the right package manager, though with the extension API users would have an alternative if something wasn't officially supported.