MCPcopy
hub / github.com/entropic-dev/entropic / visitPackage

Function visitPackage

cli/lib/commands/download.js:53–127  ·  view source on GitHub ↗
(opts, spec, now, range, seenFiles, fetching)

Source from the content-addressed store, hash-verified

51}
52
53async function visitPackage(opts, spec, now, range, seenFiles, fetching) {
54 const { canonical: name } = spec;
55
56 const data = await fetchPackage(opts, name, now);
57 if (!semver.validRange(range)) {
58 const version = data.tags[range];
59 if (!version) {
60 opts.log.error(`Failed to fetch resolve range for ${spec}: ${range}`);
61 throw new Error();
62 }
63 range = version; // peg it to a version
64 }
65
66 const checks = [];
67 for (const [version, integrity] of Object.entries(data.versions)) {
68 if (!semver.satisfies(version, range)) {
69 continue;
70 }
71
72 const check = cacache.get
73 .byDigest(opts.cache, integrity)
74 .catch(() => null)
75 .then(content => {
76 return content
77 ? content
78 : fetchPackageVersion(opts, name, version, integrity);
79 })
80 .then(content => [version, content]);
81
82 checks.push(check);
83 }
84
85 if (!checks.length) {
86 opts.log.error(
87 `Failed to fetch resolve range for ${name}: ${range} matched no versions!`
88 );
89 throw new Error();
90 }
91
92 const resolvedVersions = await Promise.all(checks);
93 const deps = new Set();
94 for (const [version, content] of resolvedVersions) {
95 const versiondata = JSON.parse(String(content));
96 for (const filename in versiondata.files) {
97 if (seenFiles.has(versiondata.files[filename])) {
98 continue;
99 }
100
101 seenFiles.add(versiondata.files[filename]);
102
103 const loading = fetchObject(opts, versiondata.files[filename]);
104
105 loading.catch(() => {});
106 fetching.push(loading);
107 }
108
109 for (const dep in versiondata.dependencies) {
110 deps.add(`${dep}@${versiondata.dependencies[dep]}`);

Callers 1

downloadFunction · 0.85

Calls 6

fetchPackageFunction · 0.85
fetchPackageVersionFunction · 0.85
fetchObjectFunction · 0.85
hasMethod · 0.80
errorMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected