Skip to content

Automatically detect package manager (npm.packageManager) #102050

@nickserv

Description

@nickserv

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.packageManager option 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.packageManager to default to a new auto option, which would select a package manager based on the presence of workspace and lock files using preferred-pm. If a lock file doesn't exist, the user is probably using npm anyway, and we can just default to npm like 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.

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityinsiders-releasedPatch has been released in VS Code Insiderson-testplantasksTask system issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions