fix: negated os / cpu skipped under multi-platform supportedArchitectures (#11375)

* fix: bug with checkList fn

* refactor: simplify checkList, add changeset

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Armaan Aggarwal
2026-04-30 08:04:53 -07:00
committed by GitHub
parent 3b12eb27de
commit dbf19076f3
3 changed files with 35 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/config.package-is-installable": patch
"pnpm": patch
---
Fix negated `os` / `cpu` entries (e.g. `["!win32"]`) being incorrectly rejected when `supportedArchitectures` expands to multiple platforms [#11375](https://github.com/pnpm/pnpm/pull/11375).

View File

@@ -56,7 +56,6 @@ export type WantedPlatform = Partial<Platform>
function checkList (value: string | string[], list: string | string[]): boolean {
let tmp
let match = false
let blc = 0
if (typeof list === 'string') {
list = [list]
@@ -76,13 +75,14 @@ function checkList (value: string | string[], list: string | string[]): boolean
if (tmp === value) {
return false
}
++blc
} else {
match = match || tmp === value
}
}
}
return match || blc === list.length
// No negation rejected any value. Accept if a positive entry matched, or if the list
// contains only negations (no positive constraints to satisfy).
return match || list.every(entry => entry[0] === '!')
}
function dedupeCurrent (current: string, supported: string[]): string[] {

View File

@@ -151,3 +151,29 @@ test('accept another libc', () => {
libc: ['current', 'glibc'],
})).toBeNull()
})
test('accept negated os with multi-valued supportedArchitectures', () => {
expect(checkPlatform(packageId, { cpu: 'any', os: ['!win32'], libc: 'any' }, {
os: ['linux', 'current'],
cpu: ['current'],
libc: ['current'],
})).toBeNull()
})
test('accept negated cpu with multi-valued supportedArchitectures', () => {
expect(checkPlatform(packageId, { cpu: ['!ia32'], os: 'any', libc: 'any' }, {
os: ['current'],
cpu: ['x64', 'current'],
libc: ['current'],
})).toBeNull()
})
test('reject negated os when any supported value matches the negation', () => {
const err = checkPlatform(packageId, { cpu: 'any', os: ['!win32'], libc: 'any' }, {
os: ['win32', 'current'],
cpu: ['current'],
libc: ['current'],
})
expect(err).toBeTruthy()
expect(err?.code).toBe('ERR_PNPM_UNSUPPORTED_PLATFORM')
})