UNPKG

912 BJavaScriptView Raw
1const request = require('request');
2
3const canConnect = require('./can-connect');
4const configstore = require('./configstore');
5
6async function fetchLatestVersion() {
7 const canConnectToNPM = await canConnect('registry.npm.org');
8
9 if (!canConnectToNPM) {
10 return;
11 }
12
13 request(
14 {
15 url: 'https://registry.npmjs.org/@creuna/cli',
16 headers: {
17 Accept: 'application/vnd.npm.install-v1+json'
18 }
19 },
20 (error, response, body) => {
21 if (error || response.statusCode < 200 || response.statuscode >= 400) {
22 // NOTE: Noop because we don't really care and there is no graceful fallback
23 return;
24 }
25
26 try {
27 configstore.set('latestVersion', JSON.parse(body)['dist-tags'].latest);
28 } catch (error) {
29 // NOTE: Noop because we don't really care and there is no graceful fallback
30 }
31 }
32 );
33}
34
35module.exports = fetchLatestVersion;