MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / matchesPlatform

Function matchesPlatform

server/utils/dependency-resolver.ts:37–64  ·  view source on GitHub ↗
(version: PackumentVersion)

Source from the content-addressed store, hash-verified

35 * Returns false if the package explicitly excludes our target platform.
36 */
37export function matchesPlatform(version: PackumentVersion): boolean {
38 if (version.os && Array.isArray(version.os) && version.os.length > 0) {
39 const osMatch = version.os.some(os => {
40 if (os.startsWith('!')) return os.slice(1) !== TARGET_PLATFORM.os
41 return os === TARGET_PLATFORM.os
42 })
43 if (!osMatch) return false
44 }
45
46 if (version.cpu && Array.isArray(version.cpu) && version.cpu.length > 0) {
47 const cpuMatch = version.cpu.some(cpu => {
48 if (cpu.startsWith('!')) return cpu.slice(1) !== TARGET_PLATFORM.cpu
49 return cpu === TARGET_PLATFORM.cpu
50 })
51 if (!cpuMatch) return false
52 }
53
54 const libc = (version as { libc?: string[] }).libc
55 if (libc && Array.isArray(libc) && libc.length > 0) {
56 const libcMatch = libc.some(l => {
57 if (l.startsWith('!')) return l.slice(1) !== TARGET_PLATFORM.libc
58 return l === TARGET_PLATFORM.libc
59 })
60 if (!libcMatch) return false
61 }
62
63 return true
64}
65
66/**
67 * Resolve a semver range to a specific version from available versions.

Callers 2

resolveDependencyTreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected