fix: catalogs exception when running pnpm outdated with --compatible flag (#8825)

close #8566
This commit is contained in:
Brandon Cheng
2024-12-02 06:03:38 -05:00
committed by GitHub
parent d2e83b0f3e
commit a724295578
15 changed files with 194 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/outdated": patch
pnpm: patch
---
Fix an exception when running `pnpm update --interactive` if catalogs are used.

View File

@@ -0,0 +1,2 @@
!**/node_modules/**/*
!/node_modules/

View File

@@ -0,0 +1 @@
shared-workspace-lockfile=false

View File

@@ -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

View File

@@ -0,0 +1,9 @@
'use strict';
module.exports = function (n) {
if (typeof n !== 'number') {
throw new TypeError('Expected a number');
}
return n < 0;
};

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Kevin Martensson <kevinmartensson@gmail.com> (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.

View File

@@ -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"
}
}

View File

@@ -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)

View File

@@ -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: {}

View File

@@ -0,0 +1 @@
.pnpm/is-negative@1.0.0/node_modules/is-negative

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"is-negative-alias": "npm:is-negative@^1.0.0"
}
}

View File

@@ -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: {}

View File

@@ -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

View File

@@ -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()