tiny-updater
Advanced tools
Comparing version 1.0.0 to 1.0.1
declare const Utils: { | ||
getExitSignal: () => any; | ||
fetch: (url: string) => any; | ||
getExitSignal: () => import("aborter/dist/signal").default; | ||
getLatestVersion: (name: string) => Promise<string | undefined>; | ||
@@ -4,0 +5,0 @@ isUpdateAvailable: (current: string, latest: string) => boolean; |
@@ -9,3 +9,3 @@ "use strict"; | ||
const colorette_1 = require("colorette"); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const simple_get_1 = __importDefault(require("simple-get")); | ||
const semver_compare_1 = __importDefault(require("semver-compare")); | ||
@@ -16,12 +16,21 @@ const signal_exit_1 = __importDefault(require("signal-exit")); | ||
/* API */ | ||
fetch: (url) => { | ||
return new Promise((resolve, reject) => { | ||
const signal = Utils.getExitSignal(); | ||
const request = simple_get_1.default.concat(url, (error, response, data) => { | ||
if (error) | ||
return reject(error); | ||
return resolve(JSON.parse(data.toString())); | ||
}); | ||
signal.addEventListener('abort', request.abort.bind(request)); | ||
}); | ||
}, | ||
getExitSignal: () => { | ||
const aborter = new aborter_1.default(); | ||
signal_exit_1.default(() => aborter.abort()); | ||
return aborter.signal; //TSC: Not techincally 100% compliant with AbortSignal, but good enough for node-fetch | ||
return aborter.signal; | ||
}, | ||
getLatestVersion: async (name) => { | ||
const latestUrl = `http://registry.npmjs.org/${name}/latest`; | ||
const signal = Utils.getExitSignal(); | ||
const response = await node_fetch_1.default(latestUrl, { signal }); | ||
const latest = await response.json(); | ||
const latest = await Utils.fetch(latestUrl); | ||
return latest.version; | ||
@@ -28,0 +37,0 @@ }, |
{ | ||
"name": "tiny-updater", | ||
"description": "The smallest update notifier for NPM packages, useful for CLI apps.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "dist/index.js", | ||
@@ -38,8 +38,8 @@ "types": "dist/index.d.ts", | ||
"colorette": "^1.2.2", | ||
"node-fetch": "^2.6.1", | ||
"semver-compare": "^1.0.0", | ||
"signal-exit": "^3.0.3" | ||
"signal-exit": "^3.0.3", | ||
"simple-get": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.5.10", | ||
"@types/node": "^16.11.7", | ||
"@types/semver-compare": "^1.0.1", | ||
@@ -46,0 +46,0 @@ "@types/signal-exit": "^3.0.0", |
@@ -6,3 +6,3 @@ | ||
import {cyan, gray, green} from 'colorette'; | ||
import fetch from 'node-fetch'; | ||
import get from 'simple-get'; | ||
import compare from 'semver-compare'; | ||
@@ -17,6 +17,17 @@ import onExit from 'signal-exit'; | ||
fetch: ( url: string ): any => { | ||
return new Promise ( ( resolve, reject ) => { | ||
const signal = Utils.getExitSignal (); | ||
const request = get.concat ( url, ( error, response, data ) => { | ||
if ( error ) return reject ( error ); | ||
return resolve ( JSON.parse ( data.toString () ) ); | ||
}); | ||
signal.addEventListener ( 'abort', request.abort.bind ( request ) ); | ||
}); | ||
}, | ||
getExitSignal: () => { | ||
const aborter = new Aborter (); | ||
onExit ( () => aborter.abort () ); | ||
return aborter.signal as any; //TSC: Not techincally 100% compliant with AbortSignal, but good enough for node-fetch | ||
return aborter.signal; | ||
}, | ||
@@ -26,5 +37,3 @@ | ||
const latestUrl = `http://registry.npmjs.org/${name}/latest`; | ||
const signal = Utils.getExitSignal (); | ||
const response = await fetch ( latestUrl, {signal} ); | ||
const latest = await response.json (); | ||
const latest = await Utils.fetch ( latestUrl ); | ||
return latest.version; | ||
@@ -31,0 +40,0 @@ }, |
/* IMPORT */ | ||
const updater = require ( '../dist' ); | ||
const {default: updater} = require ( '../dist' ); | ||
@@ -6,0 +6,0 @@ /* MAIN */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11095
192
+ Addedsimple-get@^4.0.0
+ Addeddecompress-response@6.0.0(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@4.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removednode-fetch@^2.6.1
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)