Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiny-updater

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-updater - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

dist/compare.d.ts

8

dist/index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc