mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-12 18:49:41 -04:00
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:
6
.changeset/check-platform-multi-negation.md
Normal file
6
.changeset/check-platform-multi-negation.md
Normal 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).
|
||||
@@ -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[] {
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user