source: node_modules/simple-update-notifier/src/getDistVersion.ts@ 2d1ec46

main
Last change on this file since 2d1ec46 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 811 bytes
RevLine 
[81bc7da]1import https from 'https';
2
3const getDistVersion = async (packageName: string, distTag: string) => {
4 const url = `https://registry.npmjs.org/-/package/${packageName}/dist-tags`;
5
6 return new Promise<string>((resolve, reject) => {
7 https
8 .get(url, (res) => {
9 let body = '';
10
11 res.on('data', (chunk) => (body += chunk));
12 res.on('end', () => {
13 try {
14 const json = JSON.parse(body);
15 const version = json[distTag];
16 if (!version) {
17 reject(new Error('Error getting version'));
18 }
19 resolve(version);
20 } catch {
21 reject(new Error('Could not parse version response'));
22 }
23 });
24 })
25 .on('error', (err) => reject(err));
26 });
27};
28
29export default getDistVersion;
Note: See TracBrowser for help on using the repository browser.