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:
Emil Nordling
2024-08-22 12:20:39 +02:00
committed by GitHub
parent 840e2000b5
commit 33ba536b95
3 changed files with 36 additions and 0 deletions

View 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).

View File

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

View File

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