r-darwish / topgrade

Upgrade everything
GNU General Public License v3.0
3.37k stars 162 forks source link

PNPM update is skipped or fails #1018

Closed kothavade closed 1 year ago

kothavade commented 1 year ago

What did you expect to happen?

If pnpm is installed, to run pnpm up -g as the user (not as root).

What actually happened?

  1. If there is no /usr/local/lib/node_modules (which, if you use pnpm instead of npm to install global packages, doesn't exist): npm: SKIPPED: NPM root at /usr/local/lib/node_modules doesn't exist
  2. If that directory is arbitrarily created: npm: SKIPPED: NPM root is owned by another user which is not the current user. Set use_sudo = true under the NPM section in your configuration to run NPM as sudo
  3. If use_sudo is set to true, pnpm cannot update as it operates in the user's home directory

This means that there is no way for topgrade update pnpm's global packages.

Per the logs (attached in details), even after it detects that pnpm exists, it runs npm root -g. It should instead run pnpm root -g as that correctly returns /home/$USER/.local/share/pnpm/global/5/node_modules.

Proposed Fix

Topgrade could possibly keep track of a variable such as node-package-manager, set it to npm by default, and if pnpm is detected, set it to pnpm instead. Any commands run, such as up or root would be run based on the package-manager. This might also simplify the logic in checking pnpm, as once the node-package-manager variable is set, all other commands can run agnostic to which package manager is actually being used (versus tracking pnpm as a seperate option, as seems to be done at a cursory glance at the code). This method would also allow easier support to other npm-compatible package managers that become popular in the future.

Additional Details

kothavade commented 1 year ago

I'm willing to work on fixing this :)