/
index.ts
93 lines (83 loc) · 2.24 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
installCheckLogger,
skippedOptionalDependencyLogger,
} from '@pnpm/core-loggers'
import { checkEngine, UnsupportedEngineError, type WantedEngine } from './checkEngine'
import { checkPlatform, UnsupportedPlatformError } from './checkPlatform'
import { getSystemNodeVersion } from './getSystemNodeVersion'
import { type SupportedArchitectures } from '@pnpm/types'
export type { Engine } from './checkEngine'
export type { Platform, WantedPlatform } from './checkPlatform'
export {
UnsupportedEngineError,
UnsupportedPlatformError,
type WantedEngine,
}
export function packageIsInstallable (
pkgId: string,
pkg: {
name: string
version: string
engines?: WantedEngine
cpu?: string[]
os?: string[]
libc?: string[]
},
options: {
engineStrict?: boolean
nodeVersion?: string
optional: boolean
pnpmVersion?: string
lockfileDir: string
supportedArchitectures?: SupportedArchitectures
}
): boolean | null {
const warn = checkPackage(pkgId, pkg, options)
if (warn == null) return true
installCheckLogger.warn({
message: warn.message,
prefix: options.lockfileDir,
})
if (options.optional) {
skippedOptionalDependencyLogger.debug({
details: warn.toString(),
package: {
id: pkgId,
name: pkg.name,
version: pkg.version,
},
prefix: options.lockfileDir,
reason: warn.code === 'ERR_PNPM_UNSUPPORTED_ENGINE' ? 'unsupported_engine' : 'unsupported_platform',
})
return false
}
if (options.engineStrict) throw warn
return null
}
export function checkPackage (
pkgId: string,
manifest: {
engines?: WantedEngine
cpu?: string[]
os?: string[]
libc?: string[]
},
options: {
nodeVersion?: string
pnpmVersion?: string
supportedArchitectures?: SupportedArchitectures
}
): null | UnsupportedEngineError | UnsupportedPlatformError {
return checkPlatform(pkgId, {
cpu: manifest.cpu ?? ['any'],
os: manifest.os ?? ['any'],
libc: manifest.libc ?? ['any'],
}, options.supportedArchitectures) ?? (
(manifest.engines == null)
? null
: checkEngine(pkgId, manifest.engines, {
node: options.nodeVersion ?? getSystemNodeVersion(),
pnpm: options.pnpmVersion,
})
)
}