MCPcopy
hub / github.com/smapiot/piral / findMatchingPackage

Function findMatchingPackage

src/framework/piral-base/src/utils/system.ts:13–36  ·  view source on GitHub ↗
(id: string)

Source from the content-addressed store, hash-verified

11}
12
13function findMatchingPackage(id: string) {
14 const sep = id.indexOf('@', 1);
15
16 if (sep > 1) {
17 const available = Object.keys((System as any).registerRegistry);
18 const name = id.substring(0, sep + 1);
19 const versionSpec = id.substring(sep + 1);
20
21 if (validate(versionSpec)) {
22 const loadedVersions = getLoadedVersions(name);
23 const allVersions = available.filter((m) => m.startsWith(name)).map((m) => m.substring(name.length));
24 // Moves the loaded versions to the top
25 const availableVersions = [...loadedVersions, ...allVersions.filter((m) => !loadedVersions.includes(m))];
26
27 for (const availableVersion of availableVersions) {
28 if (validate(availableVersion) && satisfies(availableVersion, versionSpec)) {
29 return name + availableVersion;
30 }
31 }
32 }
33 }
34
35 return undefined;
36}
37
38function isPrimitiveExport(content: any) {
39 const type = typeof content;

Callers 1

system.tsFile · 0.85

Calls 5

validateFunction · 0.90
satisfiesFunction · 0.90
getLoadedVersionsFunction · 0.85
mapMethod · 0.80
filterMethod · 0.65

Tested by

no test coverage detected