MCPcopy Create free account
hub / github.com/alibaba/open-code-review / fetchLatestVersion

Function fetchLatestVersion

scripts/update.js:77–115  ·  view source on GitHub ↗
(pkg)

Source from the content-addressed store, hash-verified

75}
76
77function fetchLatestVersion(pkg) {
78 const registry = (pkg.publishConfig && pkg.publishConfig.registry) || DEFAULT_REGISTRY;
79 const pkgName = pkg.name;
80 if (!pkgName) return Promise.resolve(null);
81 const encodedName = pkgName.replace(/\//g, "%2F");
82 const url = `${registry.replace(/\/$/, "")}/${encodedName}/latest`;
83 if (!url.startsWith("https://")) return Promise.resolve(null);
84
85 return new Promise((resolve) => {
86 const options = {
87 headers: { "User-Agent": "ocr-updater", Accept: "application/json" },
88 timeout: 15000,
89 };
90 const req = https
91 .get(url, options, (res) => {
92 if (res.statusCode !== 200) {
93 res.resume();
94 resolve(null);
95 return;
96 }
97 let data = "";
98 res.on("data", (chunk) => (data += chunk));
99 res.on("end", () => {
100 try {
101 const json = JSON.parse(data);
102 resolve(json.version || null);
103 } catch (_) {
104 resolve(null);
105 }
106 });
107 res.on("error", () => resolve(null));
108 })
109 .on("error", () => resolve(null));
110 req.on("timeout", () => {
111 req.destroy();
112 resolve(null);
113 });
114 });
115}
116
117function writeHint(latestVersion, pkgName) {
118 try {

Callers 1

mainFunction · 0.85

Calls 2

getMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected