MCPcopy
hub / github.com/foambubble/foam / fetchLatestVersion

Function fetchLatestVersion

packages/foam-cli/src/support/version.ts:29–61  ·  view source on GitHub ↗
(options: { allowProcessExit?: boolean } = {})

Source from the content-addressed store, hash-verified

27}
28
29export function fetchLatestVersion(options: { allowProcessExit?: boolean } = {}): Promise<string> {
30 return new Promise((resolve, reject) => {
31 const req = https.get(
32 `https://registry.npmjs.org/${NPM_PACKAGE}/latest`,
33 { timeout: 5000 },
34 res => {
35 let body = '';
36 res.on('data', chunk => (body += chunk));
37 res.on('end', () => {
38 try {
39 const data = JSON.parse(body);
40 if (typeof data.version === 'string') {
41 resolve(data.version);
42 } else {
43 reject(new Error('Unexpected registry response'));
44 }
45 } catch {
46 reject(new Error('Failed to parse registry response'));
47 }
48 });
49 }
50 );
51 req.on('error', reject);
52 req.on('timeout', () => {
53 req.destroy();
54 reject(new Error('Registry request timed out'));
55 });
56 if (options.allowProcessExit) {
57 // Allow the process to exit even if this request is still pending
58 req.on('socket', (socket: { unref: () => void }) => socket.unref());
59 }
60 });
61}
62
63export function formatUpdateNotice(latestVersion: string): string {
64 return (

Callers 3

runUpdateCommandFunction · 0.90
version.test.tsFile · 0.90
checkForUpdateNoticeFunction · 0.85

Calls 4

resolveFunction · 0.85
getMethod · 0.65
onMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected