pnpm / pnpm

Fast, disk space efficient package manager

Home Page:https://pnpm.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pnpm update --global --latest does not work properly

vemoo opened this issue · comments

commented

pnpm version: 6.14.3

Code to reproduce the issue:

Running inside docker run --interactive --rm --tty node:14 /bin/bash

> npm install --global pnpm
> pnpm install --global typescript@4.3
> tsc --version
Version 4.3.5
> pnpm update --global --latest
Already up-to-date # error, should have installed 4.4.2
> pnpm update --global --interactive --latest
? Choose which packages to update (Press <space> to select, <a> to toggle all, <i> to invert selection) … 
❯ ● typescript 4.3.5 ❯ 4.4.2

Enter to start updating. Ctrl-c to cancel.
# Select it and press enter
Already up-to-date
> tsc --version
Version 4.3.5
# error, did not install

Expected behavior:

Global packages get updated to latest version.

Actual behavior:

Global packages are not updated.

Additional information:

  • node -v prints: v14.17.4
  • Windows, macOS, or Linux?: Linux (node:14 image), not tested on other OS

Same here:

node: v14.17.5
pnpm: v6.14.3
System:
  Host: ZenBook Kernel: 5.4.0-81-generic x86_64 bits: 64
  Desktop: KDE Plasma 5.18.5 Distro: Ubuntu 20.04.3 LTS (Focal Fossa)
commented

I've been investigating this and I've found the following:

For the global case I prepare by running:
pnpm add --global cross-env@6, then I run pnpm update --global --latest and here:

async function installSome (project: any) { // eslint-disable-line
const currentPrefs = opts.ignoreCurrentPrefs ? {} : getAllDependenciesFromManifest(project.manifest)
const optionalDependencies = project.targetDependenciesField ? {} : project.manifest.optionalDependencies || {}
const devDependencies = project.targetDependenciesField ? {} : project.manifest.devDependencies || {}
if (preferredSpecs == null) {
preferredSpecs = getAllUniqueSpecs(flatten(Object.values(opts.workspacePackages).map(obj => Object.values(obj))).map(({ manifest }) => manifest))
}
const wantedDeps = parseWantedDependencies(project.dependencySelectors, {
allowNew: project.allowNew !== false,

opts.ignoreCurrentPrefs is true, which causes parseWantedDependencies to return an empty array and the package doesn't get updated.

But if do the equivalent in a project: pnpm add cross-env@6
and then pnpm update --latest, opts.ignoreCurrentPrefs is false, and parseWantedDependencies returns

[
  {
    alias: 'cross-env',
    dev: false,
    optional: false,
    pinnedVersion: undefined,
    raw: 'cross-env@latest',
    pref: 'latest'
  }
]

But what I don't know is whether the issue is that opts.ignoreCurrentPrefs shouldn't be true or maybe is the line 464 that's wrong.

Duplicate of #3779

@vemoo thanks for finding the solution. I'll make a PR.