antfu-collective / ni

💡 Use the right package manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to upgrade package manager itself

Lionad-Morotar opened this issue · comments

Clear and concise description of the problem

I would like to upgrade pnpm before installing it. It would be nice if I could use the command npx @antfu/ni upgrade self to upgrade the version of pnpm on my CI instead npm install -g pnpm

Suggested solution

  1. npx @antfu/ni upgrade self

Alternative

if [[ -f "pnpm-lock.yaml" ]]; then
   npm install -g pnpm
fi;

Validations

ni -g pnpm like this?

I would suggest using https://github.com/antfu/contribute#corepack so you don't even need to worry about that

ni -g pnpm like this?

I would suggest using antfu/contribute#corepack so you don't even need to worry about that

The only slightly inconvenient aspect is that if I don't use Corepack or other tools to lock the package manager version, I can only manually determine which package manager is being used to perform global installation and upgrades, for example:

if [[ -f "pnpm-lock.yaml" ]]; then
   npm install -g pnpm
elif [[ -f "package-lock.json" ]]; then
   npm install -g npm
fi;

em... what should I do in this situation? Thank you!

Use run npm install -g pnpm && npm install -g npm && npm install -g yarn - it's not that hard. I don't think it's belong to the scope of this project.

This is a good approach, but there are situations where it is not possible to update the versions of both npm and other package managers simultaneously #5621. Therefore, I am looking for a tool that can call the package manager to solve this problem, and I am still looking for possible answers. Thank you for your response.