mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix(package-is-installable): handle null values in wanted platform gracefully (#8431)
* fix(package-is-installable): handle null values in wanted platform gracefully * refactor: package-is-installable --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/light-walls-flash.md
Normal file
6
.changeset/light-walls-flash.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/package-is-installable": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Ignore non-string value in the os, cpu, libc fields, which checking optional dependencies [#8431](https://github.com/pnpm/pnpm/pull/8431).
|
||||
@@ -61,6 +61,9 @@ function checkList (value: string | string[], list: string | string[]): boolean
|
||||
if (typeof list === 'string') {
|
||||
list = [list]
|
||||
}
|
||||
|
||||
list = list.filter((value) => typeof value === 'string')
|
||||
|
||||
if (list.length === 1 && list[0] === 'any') {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -43,6 +43,33 @@ test('libc wrong', () => {
|
||||
expect(err?.code).toBe('ERR_PNPM_UNSUPPORTED_PLATFORM')
|
||||
})
|
||||
|
||||
test('cpu null', () => {
|
||||
const target = {
|
||||
cpu: [null] as unknown as string[], // Casting since this is technically invalid by the pnpm spec.
|
||||
os: 'any',
|
||||
libc: 'any',
|
||||
}
|
||||
expect(checkPlatform(packageId, target)).toBeFalsy()
|
||||
})
|
||||
|
||||
test('os null', () => {
|
||||
const target = {
|
||||
cpu: 'any',
|
||||
os: [null] as unknown as string[], // Casting since this is technically invalid by the pnpm spec.
|
||||
libc: 'any',
|
||||
}
|
||||
expect(checkPlatform(packageId, target)).toBeFalsy()
|
||||
})
|
||||
|
||||
test('libc null', () => {
|
||||
const target = {
|
||||
cpu: 'any',
|
||||
os: 'any',
|
||||
libc: [null] as unknown as string[], // Casting since this is technically invalid by the pnpm spec.
|
||||
}
|
||||
expect(checkPlatform(packageId, target)).toBeFalsy()
|
||||
})
|
||||
|
||||
test('nothing wrong', () => {
|
||||
const target = {
|
||||
cpu: 'any',
|
||||
|
||||
Reference in New Issue
Block a user