From a724295578abe0bbb1e773263a4dc3697f4855e0 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Mon, 2 Dec 2024 06:03:38 -0500 Subject: [PATCH] fix: catalogs exception when running `pnpm outdated` with `--compatible` flag (#8825) close #8566 --- .changeset/weak-peaches-sip.md | 6 ++++ .../.gitignore | 2 ++ .../has-outdated-deps-using-npm-alias/.npmrc | 1 + .../node_modules/.modules.yaml | 22 +++++++++++++ .../node_modules/is-negative/index.js | 9 ++++++ .../node_modules/is-negative/license | 21 +++++++++++++ .../node_modules/is-negative/package.json | 29 +++++++++++++++++ .../node_modules/is-negative/readme.md | 31 +++++++++++++++++++ .../node_modules/.pnpm/lock.yaml | 23 ++++++++++++++ .../node_modules/is-negative-alias | 1 + .../package.json | 5 +++ .../pnpm-lock.yaml | 23 ++++++++++++++ .../pnpm-workspace.yaml | 0 reviewing/outdated/src/outdated.ts | 2 +- .../plugin-commands-outdated/test/index.ts | 20 ++++++++++++ 15 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 .changeset/weak-peaches-sip.md create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/.gitignore create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/.npmrc create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/.modules.yaml create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/index.js create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/license create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/package.json create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/readme.md create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/lock.yaml create mode 120000 __fixtures__/has-outdated-deps-using-npm-alias/node_modules/is-negative-alias create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/package.json create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/pnpm-lock.yaml create mode 100644 __fixtures__/has-outdated-deps-using-npm-alias/pnpm-workspace.yaml diff --git a/.changeset/weak-peaches-sip.md b/.changeset/weak-peaches-sip.md new file mode 100644 index 0000000000..c2c0ef559b --- /dev/null +++ b/.changeset/weak-peaches-sip.md @@ -0,0 +1,6 @@ +--- +"@pnpm/outdated": patch +pnpm: patch +--- + +Fix an exception when running `pnpm update --interactive` if catalogs are used. diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/.gitignore b/__fixtures__/has-outdated-deps-using-npm-alias/.gitignore new file mode 100644 index 0000000000..5867a0493e --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/.gitignore @@ -0,0 +1,2 @@ +!**/node_modules/**/* +!/node_modules/ diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/.npmrc b/__fixtures__/has-outdated-deps-using-npm-alias/.npmrc new file mode 100644 index 0000000000..135f7a0d5d --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/.npmrc @@ -0,0 +1 @@ +shared-workspace-lockfile=false diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.modules.yaml b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.modules.yaml new file mode 100644 index 0000000000..ebd438ccd3 --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.modules.yaml @@ -0,0 +1,22 @@ +hoistPattern: + - '*' +hoistedDependencies: {} +included: + dependencies: true + devDependencies: true + optionalDependencies: true +injectedDeps: {} +layoutVersion: 5 +nodeLinker: isolated +packageManager: pnpm@9.9.0 +pendingBuilds: [] +prunedAt: Sun, 01 Dec 2024 19:56:24 GMT +publicHoistPattern: + - '*eslint*' + - '*prettier*' +registries: + default: https://registry.npmjs.org/ +skipped: [] +storeDir: /Users/gluxon/Library/pnpm/store/v3 +virtualStoreDir: .pnpm +virtualStoreDirMaxLength: 120 diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/index.js b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/index.js new file mode 100644 index 0000000000..342e43c190 --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/index.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = function (n) { + if (typeof n !== 'number') { + throw new TypeError('Expected a number'); + } + + return n < 0; +}; diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/license b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/license new file mode 100644 index 0000000000..0f8cf79c3c --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Kevin Martensson (github.com/kevva) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/package.json b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/package.json new file mode 100644 index 0000000000..d1dbf34643 --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/package.json @@ -0,0 +1,29 @@ +{ + "name": "is-negative", + "version": "1.0.0", + "description": "Test if a number is negative", + "license": "MIT", + "repository": "kevva/is-negative", + "author": { + "name": "Kevin Martensson", + "email": "kevinmartensson@gmail.com", + "url": "github.com/kevva" + }, + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "node test.js" + }, + "files": [ + "index.js" + ], + "keywords": [ + "negative", + "number", + "test" + ], + "devDependencies": { + "ava": "^0.0.4" + } +} diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/readme.md b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/readme.md new file mode 100644 index 0000000000..0b3aa99fda --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/is-negative@1.0.0/node_modules/is-negative/readme.md @@ -0,0 +1,31 @@ +# is-negative [![Build Status](https://travis-ci.org/kevva/is-negative.svg?branch=master)](https://travis-ci.org/kevva/is-negative) + +> Test if a number is positive + + +## Install + +``` +$ npm install --save is-negative +``` + + +## Usage + +```js +var isNegative = require('is-negative'); + +isNegative(-1); +//=> true + +isNegative(1); +//=> false + +isNegative(0); +//=> false +``` + + +## License + +MIT © [Kevin Martensson](http://github.com/kevva) diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/lock.yaml b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/lock.yaml new file mode 100644 index 0000000000..32c75fd187 --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/.pnpm/lock.yaml @@ -0,0 +1,23 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + is-negative-alias: + specifier: npm:is-negative@^1.0.0 + version: is-negative@1.0.0 + +packages: + + is-negative@1.0.0: + resolution: {integrity: sha512-1aKMsFUc7vYQGzt//8zhkjRWPoYkajY/I5MJEvrc0pDoHXrW7n5ri8DYxhy3rR+Dk0QFl7GjHHsZU1sppQrWtw==} + engines: {node: '>=0.10.0'} + +snapshots: + + is-negative@1.0.0: {} diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/is-negative-alias b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/is-negative-alias new file mode 120000 index 0000000000..b9e7110b6c --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/node_modules/is-negative-alias @@ -0,0 +1 @@ +.pnpm/is-negative@1.0.0/node_modules/is-negative \ No newline at end of file diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/package.json b/__fixtures__/has-outdated-deps-using-npm-alias/package.json new file mode 100644 index 0000000000..98f75921c6 --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "is-negative-alias": "npm:is-negative@^1.0.0" + } +} diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/pnpm-lock.yaml b/__fixtures__/has-outdated-deps-using-npm-alias/pnpm-lock.yaml new file mode 100644 index 0000000000..32c75fd187 --- /dev/null +++ b/__fixtures__/has-outdated-deps-using-npm-alias/pnpm-lock.yaml @@ -0,0 +1,23 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + is-negative-alias: + specifier: npm:is-negative@^1.0.0 + version: is-negative@1.0.0 + +packages: + + is-negative@1.0.0: + resolution: {integrity: sha512-1aKMsFUc7vYQGzt//8zhkjRWPoYkajY/I5MJEvrc0pDoHXrW7n5ri8DYxhy3rR+Dk0QFl7GjHHsZU1sppQrWtw==} + engines: {node: '>=0.10.0'} + +snapshots: + + is-negative@1.0.0: {} diff --git a/__fixtures__/has-outdated-deps-using-npm-alias/pnpm-workspace.yaml b/__fixtures__/has-outdated-deps-using-npm-alias/pnpm-workspace.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/reviewing/outdated/src/outdated.ts b/reviewing/outdated/src/outdated.ts index f370faed6c..7dc55ff72e 100644 --- a/reviewing/outdated/src/outdated.ts +++ b/reviewing/outdated/src/outdated.ts @@ -155,7 +155,7 @@ export async function outdated ( const latestManifest = await opts.getLatestManifest( name, - opts.compatible ? (allDeps[name] ?? 'latest') : 'latest' + opts.compatible ? (pref ?? 'latest') : 'latest' ) if (latestManifest == null) return diff --git a/reviewing/plugin-commands-outdated/test/index.ts b/reviewing/plugin-commands-outdated/test/index.ts index 03fc5ada75..0627af5078 100644 --- a/reviewing/plugin-commands-outdated/test/index.ts +++ b/reviewing/plugin-commands-outdated/test/index.ts @@ -18,6 +18,7 @@ const hasMajorOutdatedDepsFixture = f.find('has-major-outdated-deps') const hasNoLockfileFixture = f.find('has-no-lockfile') const withPnpmUpdateIgnore = f.find('with-pnpm-update-ignore') const hasOutdatedDepsUsingCatalogProtocol = f.find('has-outdated-deps-using-catalog-protocol') +const hasOutdatedDepsUsingNpmAlias = f.find('has-outdated-deps-using-npm-alias') const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}` @@ -409,6 +410,25 @@ test('pnpm outdated: catalog protocol', async () => { `) }) +test('pnpm outdated: --compatible works with npm aliases', async () => { + const { output, exitCode } = await outdated.handler({ + ...OUTDATED_OPTIONS, + compatible: true, + dir: hasOutdatedDepsUsingNpmAlias, + }) + + // Although is-negative@2.1.0 is the latest version at the time of writing, + // the "compatible: true" option above should make pnpm to only find 1.0.1. + expect(exitCode).toBe(1) + expect(stripAnsi(output)).toBe(`\ +┌─────────────┬─────────┬────────┐ +│ Package │ Current │ Latest │ +├─────────────┼─────────┼────────┤ +│ is-negative │ 1.0.0 │ 1.0.1 │ +└─────────────┴─────────┴────────┘ +`) +}) + test('pnpm outdated: support --sortField option', async () => { tempDir()