tiny-updater
Advanced tools
Comparing version 3.5.0 to 3.5.1
@@ -10,3 +10,3 @@ /* IMPORT */ | ||
const isFresh = !record || (timestamp - record.timestampFetch) >= ttl; | ||
const latest = isFresh ? await Utils.getLatestVersion(name).catch(() => undefined) : record?.version; | ||
const latest = isFresh ? await Utils.getLatestVersion(name).catch(Utils.noop) : record?.version; | ||
if (!latest) | ||
@@ -18,4 +18,5 @@ return false; | ||
} | ||
if (!Utils.isUpdateAvailable(version, latest)) | ||
if (!Utils.isUpdateAvailable(version, latest)) { | ||
return false; | ||
} | ||
if (isFresh) { | ||
@@ -22,0 +23,0 @@ Utils.notify(name, version, latest); |
@@ -10,4 +10,5 @@ declare const Utils: { | ||
isUpdateAvailable: (current: string, latest: string) => boolean; | ||
noop: () => undefined; | ||
notify: (name: string, version: string, latest: string) => void; | ||
}; | ||
export default Utils; |
@@ -20,3 +20,3 @@ /* IMPORT */ | ||
getLatestVersion: async (name) => { | ||
const latestUrl = `http://registry.npmjs.org/${name}/latest`; | ||
const latestUrl = `https://registry.npmjs.org/${name}/latest`; | ||
const latest = await Utils.fetch(latestUrl); | ||
@@ -34,2 +34,5 @@ return latest.version; | ||
}, | ||
noop: () => { | ||
return; | ||
}, | ||
notify: (name, version, latest) => { | ||
@@ -36,0 +39,0 @@ if (!globalThis.process?.stdout?.isTTY) |
@@ -5,3 +5,3 @@ { | ||
"description": "A small update notifier for NPM packages, useful for CLI apps.", | ||
"version": "3.5.0", | ||
"version": "3.5.1", | ||
"type": "module", | ||
@@ -31,9 +31,9 @@ "main": "dist/index.js", | ||
"tiny-colors": "^2.0.2", | ||
"when-exit": "^2.1.0" | ||
"when-exit": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"fava": "^0.1.2", | ||
"tsex": "^2.1.0", | ||
"typescript": "^4.9.5" | ||
"fava": "^0.2.0", | ||
"tsex": "^3.0.0", | ||
"typescript": "^5.1.6" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # Tiny Updater | ||
- **Small**: This library has only a handful of small and reliable dependencies. This library weighs about ~6kb total. | ||
- **Small**: This library has only a handful of small and reliable dependencies. This library weighs about ~5kb total. | ||
- **Bundler-ready**: This library can be bundled, which is important for achieving the best startup times. `update-notifier` on the other hand uses highly dyanmic imports and spawns a child process, if you are using it you can't bundle your CLI app. | ||
@@ -12,0 +12,0 @@ - **Fast**: Startup performance is paramount for CLI apps, in order to improve that you need to bundle your app and make the bundle as small as possible, using this library won't compromise your startup times much. |
@@ -17,3 +17,3 @@ | ||
const isFresh = !record || ( timestamp - record.timestampFetch ) >= ttl; | ||
const latest = isFresh ? await Utils.getLatestVersion ( name ).catch ( () => undefined ) : record?.version; | ||
const latest = isFresh ? await Utils.getLatestVersion ( name ).catch ( Utils.noop ) : record?.version; | ||
@@ -30,4 +30,8 @@ if ( !latest ) return false; | ||
if ( !Utils.isUpdateAvailable ( version, latest ) ) return false; | ||
if ( !Utils.isUpdateAvailable ( version, latest ) ) { | ||
return false; | ||
} | ||
if ( isFresh ) { | ||
@@ -34,0 +38,0 @@ |
@@ -28,3 +28,3 @@ | ||
getLatestVersion: async ( name: string ): Promise<string | undefined> => { | ||
const latestUrl = `http://registry.npmjs.org/${name}/latest`; | ||
const latestUrl = `https://registry.npmjs.org/${name}/latest`; | ||
const latest = await Utils.fetch ( latestUrl ); | ||
@@ -46,2 +46,6 @@ return latest.version; | ||
noop: (): undefined => { | ||
return; | ||
}, | ||
notify: ( name: string, version: string, latest: string ): void => { | ||
@@ -48,0 +52,0 @@ if ( !globalThis.process?.stdout?.isTTY ) return; // Probably piping stdout |
17013
374
Updatedwhen-exit@^2.1.1