tiny-updater
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -5,8 +5,2 @@ declare const updater: ({ name, version }: { | ||
}) => Promise<boolean>; | ||
declare const _default: typeof updater & { | ||
default: typeof updater; | ||
} | ||
declare namespace _default { | ||
export type type = updater; | ||
} | ||
export = _default; | ||
export default updater; |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
/* IMPORT */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
const utils_1 = __importDefault(require("./utils")); | ||
import Utils from './utils.js'; | ||
/* MAIN */ | ||
@@ -18,13 +14,11 @@ //TODO: Provide command suggestion for updating | ||
const updater = async ({ name, version }) => { | ||
const latest = await utils_1.default.getLatestVersion(name).catch(() => undefined); | ||
const latest = await Utils.getLatestVersion(name).catch(() => undefined); | ||
if (!latest) | ||
return false; | ||
if (!utils_1.default.isUpdateAvailable(version, latest)) | ||
if (!Utils.isUpdateAvailable(version, latest)) | ||
return false; | ||
utils_1.default.notify(name, version, latest); | ||
Utils.notify(name, version, latest); | ||
return true; | ||
}; | ||
/* EXPORT */ | ||
module.exports = updater; | ||
module.exports.default = updater; | ||
Object.defineProperty(module.exports, "__esModule", { value: true }); | ||
export default updater; |
declare const Utils: { | ||
fetch: (url: string) => any; | ||
getExitSignal: () => import("aborter/dist/signal").default; | ||
fetch: (url: string) => Promise<{ | ||
version?: string; | ||
}>; | ||
getExitSignal: () => AbortSignal; | ||
getLatestVersion: (name: string) => Promise<string | undefined>; | ||
@@ -5,0 +7,0 @@ isUpdateAvailable: (current: string, latest: string) => boolean; |
@@ -1,29 +0,18 @@ | ||
"use strict"; | ||
/* IMPORT */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const aborter_1 = __importDefault(require("aborter")); | ||
const colorette_1 = require("colorette"); | ||
const simple_get_1 = __importDefault(require("simple-get")); | ||
const semver_compare_1 = __importDefault(require("semver-compare")); | ||
const signal_exit_1 = __importDefault(require("signal-exit")); | ||
import fetch from 'fetch-shim'; | ||
import colors from 'tiny-colors'; | ||
import whenExit from 'when-exit'; | ||
import compare from './compare.js'; | ||
/* MAIN */ | ||
const Utils = { | ||
/* 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)); | ||
}); | ||
fetch: async (url) => { | ||
const signal = Utils.getExitSignal(); | ||
const request = await fetch(url, { signal }); | ||
const json = await request.json(); | ||
return json; | ||
}, | ||
getExitSignal: () => { | ||
const aborter = new aborter_1.default(); | ||
signal_exit_1.default(() => aborter.abort()); | ||
const aborter = new AbortController(); | ||
whenExit(() => aborter.abort()); | ||
return aborter.signal; | ||
@@ -37,10 +26,10 @@ }, | ||
isUpdateAvailable: (current, latest) => { | ||
return semver_compare_1.default(current, latest) === -1; | ||
return compare(current, latest) === -1; | ||
}, | ||
notify: (name, version, latest) => { | ||
const log = () => console.log(`\n\n📦 Update available for ${colorette_1.cyan(name)}: ${colorette_1.gray(version)} → ${colorette_1.green(latest)}`); | ||
signal_exit_1.default(log, { alwaysLast: true }); | ||
const log = () => console.log(`\n\n📦 Update available for ${colors.cyan(name)}: ${colors.gray(version)} → ${colors.green(latest)}`); | ||
whenExit(log); | ||
} | ||
}; | ||
/* EXPORT */ | ||
exports.default = Utils; | ||
export default Utils; |
{ | ||
"name": "tiny-updater", | ||
"description": "The smallest update notifier for NPM packages, useful for CLI apps.", | ||
"version": "1.0.1", | ||
"repository": "github:fabiospampinato/tiny-updater", | ||
"description": "A small update notifier for NPM packages, useful for CLI apps.", | ||
"version": "2.0.0", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"compile": "tsc --skipLibCheck && tstei", | ||
"compile:watch": "tsc --skipLibCheck --watch", | ||
"test": "node test/index.js", | ||
"clean": "tsex clean", | ||
"compile": "tsex compile", | ||
"compile:watch": "tsex compile --watch", | ||
"test": "tsex test", | ||
"test:watch": "tsex test --watch", | ||
"prepublishOnly": "npm run clean && npm run compile && npm run test" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fabiospampinato/tiny-updater/issues" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Fabio Spampinato", | ||
"email": "spampinabio@gmail.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fabiospampinato/tiny-updater.git" | ||
}, | ||
"keywords": [ | ||
@@ -36,16 +28,11 @@ "tiny", | ||
"dependencies": { | ||
"aborter": "^1.0.0", | ||
"colorette": "^1.2.2", | ||
"semver-compare": "^1.0.0", | ||
"signal-exit": "^3.0.3", | ||
"simple-get": "^4.0.0" | ||
"fetch-shim": "^1.1.0", | ||
"tiny-colors": "^2.0.1", | ||
"when-exit": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.11.7", | ||
"@types/semver-compare": "^1.0.1", | ||
"@types/signal-exit": "^3.0.0", | ||
"rimraf": "^3.0.0", | ||
"typescript": "^3.5.3", | ||
"typescript-transform-export-interop": "^1.0.2" | ||
"fava": "^0.0.6", | ||
"tsex": "^1.1.2", | ||
"typescript": "^4.7.3" | ||
} | ||
} |
/* IMPORT */ | ||
import Aborter from 'aborter'; | ||
import {cyan, gray, green} from 'colorette'; | ||
import get from 'simple-get'; | ||
import compare from 'semver-compare'; | ||
import onExit from 'signal-exit'; | ||
import fetch from 'fetch-shim'; | ||
import colors from 'tiny-colors'; | ||
import whenExit from 'when-exit'; | ||
import compare from './compare'; | ||
@@ -16,16 +15,12 @@ /* MAIN */ | ||
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 ) ); | ||
}); | ||
fetch: async ( url: string ): Promise<{ version?: string }> => { | ||
const signal = Utils.getExitSignal (); | ||
const request = await fetch ( url, { signal } ); | ||
const json = await request.json (); | ||
return json; | ||
}, | ||
getExitSignal: () => { | ||
const aborter = new Aborter (); | ||
onExit ( () => aborter.abort () ); | ||
const aborter = new AbortController (); | ||
whenExit ( () => aborter.abort () ); | ||
return aborter.signal; | ||
@@ -45,4 +40,4 @@ }, | ||
notify: ( name: string, version: string, latest: string ): void => { | ||
const log = () => console.log ( `\n\n📦 Update available for ${cyan ( name )}: ${gray ( version )} → ${green ( latest )}` ); | ||
onExit ( log, { alwaysLast: true } ); | ||
const log = () => console.log ( `\n\n📦 Update available for ${colors.cyan ( name )}: ${colors.gray ( version )} → ${colors.green ( latest )}` ); | ||
whenExit ( log ); | ||
} | ||
@@ -49,0 +44,0 @@ |
/* IMPORT */ | ||
const {default: updater} = require ( '../dist' ); | ||
import {describe} from 'fava'; | ||
import updater from '../dist/index.js'; | ||
/* MAIN */ | ||
const test = async () => { | ||
describe ( 'TinyUpdater', it => { | ||
const yes = await updater ({ name: 'aborter', version: '0.0.0' }); | ||
it ( 'works', async t => { | ||
console.assert ( yes ); | ||
const yes = await updater ({ name: 'aborter', version: '0.0.0' }); | ||
const no = await updater ({ name: 'aborter', version: '100.0.0' }); | ||
t.true ( yes ); | ||
console.assert ( !no ); | ||
const no = await updater ({ name: 'aborter', version: '100.0.0' }); | ||
}; | ||
t.false ( no ); | ||
test (); | ||
}); | ||
}); |
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"declaration": true, | ||
"emitDecoratorMetadata": true, | ||
"esModuleInterop": true, | ||
"experimentalDecorators": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"inlineSourceMap": false, | ||
"jsx": "react", | ||
"lib": ["es2020"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"newLine": "LF", | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": false, | ||
"outDir": "dist", | ||
"pretty": true, | ||
"strictNullChecks": true, | ||
"target": "es2018" | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
"extends": "tsex/tsconfig.json" | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
13392
3
3
15
242
Yes
2
1
2
+ Addedfetch-shim@^1.1.0
+ Addedtiny-colors@^2.0.1
+ Addedwhen-exit@^2.0.0
+ Added@fastify/busboy@2.1.1(transitive)
+ Addedfetch-shim@1.1.1(transitive)
+ Addedtiny-colors@2.2.1(transitive)
+ Addedundici@5.28.4(transitive)
+ Addedwhen-exit@2.1.3(transitive)
- Removedaborter@^1.0.0
- Removedcolorette@^1.2.2
- Removedsemver-compare@^1.0.0
- Removedsignal-exit@^3.0.3
- Removedsimple-get@^4.0.0
- Removedaborter@1.1.0(transitive)
- Removedcolorette@1.4.0(transitive)
- Removeddecompress-response@6.0.0(transitive)
- Removedmimic-response@3.1.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedsemver-compare@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@4.0.1(transitive)
- Removedwrappy@1.0.2(transitive)