primer cambio

This commit is contained in:
beseira13
2026-01-19 12:12:38 -03:00
parent 5f59dba52d
commit 44990f015a
4759 changed files with 588702 additions and 0 deletions

21
node_modules/simple-update-notifier/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Alex Brazier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

82
node_modules/simple-update-notifier/README.md generated vendored Normal file
View File

@@ -0,0 +1,82 @@
# simple-update-notifier [![GitHub stars](https://img.shields.io/github/stars/alexbrazier/simple-update-notifier?label=Star%20Project&style=social)](https://github.com/alexbrazier/simple-update-notifier/stargazers)
[![CI](https://github.com/alexbrazier/simple-update-notifier/workflows/Build%20and%20Deploy/badge.svg)](https://github.com/alexbrazier/simple-update-notifier/actions)
[![Dependencies](https://img.shields.io/librariesio/release/npm/simple-update-notifier)](https://www.npmjs.com/package/simple-update-notifier?activeTab=dependencies)
[![npm](https://img.shields.io/npm/v/simple-update-notifier)](https://www.npmjs.com/package/simple-update-notifier)
[![npm bundle size](https://img.shields.io/bundlephobia/min/simple-update-notifier)](https://bundlephobia.com/result?p=simple-update-notifier)
[![npm downloads](https://img.shields.io/npm/dw/simple-update-notifier)](https://www.npmjs.com/package/simple-update-notifier)
[![License](https://img.shields.io/npm/l/simple-update-notifier)](./LICENSE)
Simple update notifier to check for npm updates for cli applications.
<img src="./.github/demo.png" alt="Demo in terminal showing an update is required">
Checks for updates for an npm module and outputs to the command line if there is one available. The result is cached for the specified time so it doesn't check every time the app runs.
## Install
```bash
npm install simple-update-notifier
OR
yarn add simple-update-notifier
```
## Usage
```js
import updateNotifier from 'simple-update-notifier';
import packageJson from './package.json' assert { type: 'json' };
updateNotifier({ pkg: packageJson });
```
### Options
#### pkg
Type: `object`
##### name
_Required_\
Type: `string`
##### version
_Required_\
Type: `string`
#### updateCheckInterval
Type: `number`\
Default: `1000 * 60 * 60 * 24` _(1 day)_
How often to check for updates.
#### shouldNotifyInNpmScript
Type: `boolean`\
Default: `false`
Allows notification to be shown when running as an npm script.
#### distTag
Type: `string`\
Default: `'latest'`
Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version.
#### alwaysRun
Type: `boolean`\
Default: `false`
When set, `updateCheckInterval` will not be respected and a check for an update will always be performed.
#### debug
Type: `boolean`\
Default: `false`
When set, logs explaining the decision will be output to `stderr` whenever the module opts to not print an update notification

13
node_modules/simple-update-notifier/build/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
interface IUpdate {
pkg: {
name: string;
version: string;
};
updateCheckInterval?: number;
shouldNotifyInNpmScript?: boolean;
distTag?: string;
alwaysRun?: boolean;
debug?: boolean;
}
declare const simpleUpdateNotifier: (args: IUpdate) => Promise<void>;
export { simpleUpdateNotifier as default };

210
node_modules/simple-update-notifier/build/index.js generated vendored Normal file
View File

@@ -0,0 +1,210 @@
'use strict';
var process$1 = require('process');
var semver = require('semver');
var os = require('os');
var path = require('path');
var fs = require('fs');
var https = require('https');
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
var packageJson = process$1.env.npm_package_json;
var userAgent = process$1.env.npm_config_user_agent;
var isNpm6 = Boolean(userAgent && userAgent.startsWith('npm'));
var isNpm7 = Boolean(packageJson && packageJson.endsWith('package.json'));
var isNpm = isNpm6 || isNpm7;
var isYarn = Boolean(userAgent && userAgent.startsWith('yarn'));
var isNpmOrYarn = isNpm || isYarn;
var homeDirectory = os.homedir();
var configDir = process.env.XDG_CONFIG_HOME ||
path.join(homeDirectory, '.config', 'simple-update-notifier');
var getConfigFile = function (packageName) {
return path.join(configDir, "".concat(packageName.replace('@', '').replace('/', '__'), ".json"));
};
var createConfigDir = function () {
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}
};
var getLastUpdate = function (packageName) {
var configFile = getConfigFile(packageName);
try {
if (!fs.existsSync(configFile)) {
return undefined;
}
var file = JSON.parse(fs.readFileSync(configFile, 'utf8'));
return file.lastUpdateCheck;
}
catch (_a) {
return undefined;
}
};
var saveLastUpdate = function (packageName) {
var configFile = getConfigFile(packageName);
fs.writeFileSync(configFile, JSON.stringify({ lastUpdateCheck: new Date().getTime() }));
};
var getDistVersion = function (packageName, distTag) { return __awaiter(void 0, void 0, void 0, function () {
var url;
return __generator(this, function (_a) {
url = "https://registry.npmjs.org/-/package/".concat(packageName, "/dist-tags");
return [2 /*return*/, new Promise(function (resolve, reject) {
https
.get(url, function (res) {
var body = '';
res.on('data', function (chunk) { return (body += chunk); });
res.on('end', function () {
try {
var json = JSON.parse(body);
var version = json[distTag];
if (!version) {
reject(new Error('Error getting version'));
}
resolve(version);
}
catch (_a) {
reject(new Error('Could not parse version response'));
}
});
})
.on('error', function (err) { return reject(err); });
})];
});
}); };
var hasNewVersion = function (_a) {
var pkg = _a.pkg, _b = _a.updateCheckInterval, updateCheckInterval = _b === void 0 ? 1000 * 60 * 60 * 24 : _b, _c = _a.distTag, distTag = _c === void 0 ? 'latest' : _c, alwaysRun = _a.alwaysRun, debug = _a.debug;
return __awaiter(void 0, void 0, void 0, function () {
var lastUpdateCheck, latestVersion;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
createConfigDir();
lastUpdateCheck = getLastUpdate(pkg.name);
if (!(alwaysRun ||
!lastUpdateCheck ||
lastUpdateCheck < new Date().getTime() - updateCheckInterval)) return [3 /*break*/, 2];
return [4 /*yield*/, getDistVersion(pkg.name, distTag)];
case 1:
latestVersion = _d.sent();
saveLastUpdate(pkg.name);
if (semver.gt(latestVersion, pkg.version)) {
return [2 /*return*/, latestVersion];
}
else if (debug) {
console.error("Latest version (".concat(latestVersion, ") not newer than current version (").concat(pkg.version, ")"));
}
return [3 /*break*/, 3];
case 2:
if (debug) {
console.error("Too recent to check for a new update. simpleUpdateNotifier() interval set to ".concat(updateCheckInterval, "ms but only ").concat(new Date().getTime() - lastUpdateCheck, "ms since last check."));
}
_d.label = 3;
case 3: return [2 /*return*/, false];
}
});
});
};
var borderedText = function (text) {
var lines = text.split('\n');
var width = Math.max.apply(Math, lines.map(function (l) { return l.length; }));
var res = ["\u250C".concat('─'.repeat(width + 2), "\u2510")];
for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
var line = lines_1[_i];
res.push("\u2502 ".concat(line.padEnd(width), " \u2502"));
}
res.push("\u2514".concat('─'.repeat(width + 2), "\u2518"));
return res.join('\n');
};
var simpleUpdateNotifier = function (args) { return __awaiter(void 0, void 0, void 0, function () {
var latestVersion, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!args.alwaysRun &&
(!process.stdout.isTTY || (isNpmOrYarn && !args.shouldNotifyInNpmScript))) {
if (args.debug) {
console.error('Opting out of running simpleUpdateNotifier()');
}
return [2 /*return*/];
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, hasNewVersion(args)];
case 2:
latestVersion = _a.sent();
if (latestVersion) {
console.error(borderedText("New version of ".concat(args.pkg.name, " available!\nCurrent Version: ").concat(args.pkg.version, "\nLatest Version: ").concat(latestVersion)));
}
return [3 /*break*/, 4];
case 3:
err_1 = _a.sent();
// Catch any network errors or cache writing errors so module doesn't cause a crash
if (args.debug && err_1 instanceof Error) {
console.error('Unexpected error in simpleUpdateNotifier():', err_1);
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
}); };
module.exports = simpleUpdateNotifier;

View File

@@ -0,0 +1,188 @@
#!/usr/bin/env node
// Standalone semver comparison program.
// Exits successfully and prints matching version(s) if
// any supplied version is valid and passes all tests.
const argv = process.argv.slice(2)
let versions = []
const range = []
let inc = null
const version = require('../package.json').version
let loose = false
let includePrerelease = false
let coerce = false
let rtl = false
let identifier
let identifierBase
const semver = require('../')
const parseOptions = require('../internal/parse-options')
let reverse = false
let options = {}
const main = () => {
if (!argv.length) {
return help()
}
while (argv.length) {
let a = argv.shift()
const indexOfEqualSign = a.indexOf('=')
if (indexOfEqualSign !== -1) {
const value = a.slice(indexOfEqualSign + 1)
a = a.slice(0, indexOfEqualSign)
argv.unshift(value)
}
switch (a) {
case '-rv': case '-rev': case '--rev': case '--reverse':
reverse = true
break
case '-l': case '--loose':
loose = true
break
case '-p': case '--include-prerelease':
includePrerelease = true
break
case '-v': case '--version':
versions.push(argv.shift())
break
case '-i': case '--inc': case '--increment':
switch (argv[0]) {
case 'major': case 'minor': case 'patch': case 'prerelease':
case 'premajor': case 'preminor': case 'prepatch':
inc = argv.shift()
break
default:
inc = 'patch'
break
}
break
case '--preid':
identifier = argv.shift()
break
case '-r': case '--range':
range.push(argv.shift())
break
case '-n':
identifierBase = argv.shift()
if (identifierBase === 'false') {
identifierBase = false
}
break
case '-c': case '--coerce':
coerce = true
break
case '--rtl':
rtl = true
break
case '--ltr':
rtl = false
break
case '-h': case '--help': case '-?':
return help()
default:
versions.push(a)
break
}
}
options = parseOptions({ loose, includePrerelease, rtl })
versions = versions.map((v) => {
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
}).filter((v) => {
return semver.valid(v)
})
if (!versions.length) {
return fail()
}
if (inc && (versions.length !== 1 || range.length)) {
return failInc()
}
for (let i = 0, l = range.length; i < l; i++) {
versions = versions.filter((v) => {
return semver.satisfies(v, range[i], options)
})
if (!versions.length) {
return fail()
}
}
versions
.sort((a, b) => semver[reverse ? 'rcompare' : 'compare'](a, b, options))
.map(v => semver.clean(v, options))
.map(v => inc ? semver.inc(v, inc, options, identifier, identifierBase) : v)
.forEach(v => console.log(v))
}
const failInc = () => {
console.error('--inc can only be used on a single version with no range')
fail()
}
const fail = () => process.exit(1)
const help = () => console.log(
`SemVer ${version}
A JavaScript implementation of the https://semver.org/ specification
Copyright Isaac Z. Schlueter
Usage: semver [options] <version> [<version> [...]]
Prints valid versions sorted by SemVer precedence
Options:
-r --range <range>
Print versions that match the specified range.
-i --increment [<level>]
Increment a version by the specified level. Level can
be one of: major, minor, patch, premajor, preminor,
prepatch, or prerelease. Default level is 'patch'.
Only one version may be specified.
--preid <identifier>
Identifier to be used to prefix premajor, preminor,
prepatch or prerelease version increments.
-l --loose
Interpret versions and ranges loosely
-p --include-prerelease
Always include prerelease versions in range matching
-c --coerce
Coerce a string into SemVer if possible
(does not imply --loose)
--rtl
Coerce version strings right to left
--ltr
Coerce version strings left to right (default)
-n <base>
Base number to be used for the prerelease identifier.
Can be either 0 or 1, or false to omit the number altogether.
Defaults to 0.
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
If no satisfying versions are found, then exits failure.
Versions are printed in ascending order, so supplying
multiple versions to the utility will just sort them.`)
main()

100
node_modules/simple-update-notifier/package.json generated vendored Normal file
View File

@@ -0,0 +1,100 @@
{
"name": "simple-update-notifier",
"version": "2.0.0",
"description": "Simple update notifier to check for npm updates for cli applications",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/alexbrazier/simple-update-notifier.git"
},
"homepage": "https://github.com/alexbrazier/simple-update-notifier.git",
"author": "alexbrazier",
"license": "MIT",
"engines": {
"node": ">=10"
},
"scripts": {
"test": "jest src --noStackTrace",
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
"prettier:check": "prettier --check src/**/*.ts",
"prettier": "prettier --write src/**/*.ts",
"eslint": "eslint src/**/*.ts",
"lint": "yarn prettier:check && yarn eslint",
"prepare": "yarn lint && yarn build",
"release": "release-it"
},
"dependencies": {
"semver": "^7.5.3"
},
"devDependencies": {
"@babel/preset-env": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@release-it/conventional-changelog": "^5.1.1",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"release-it": "^15.11.0",
"rollup": "^3.25.2",
"rollup-plugin-ts": "^3.2.0",
"typescript": "^5.1.3"
},
"resolutions": {
"semver": "^7.5.3"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"files": [
"build",
"src"
],
"release-it": {
"git": {
"commitMessage": "chore: release ${version}",
"tagName": "v${version}"
},
"npm": {
"publish": true
},
"github": {
"release": true
},
"plugins": {
"@release-it/conventional-changelog": {
"preset": "angular",
"infile": "CHANGELOG.md"
}
}
},
"eslintConfig": {
"plugins": [
"@typescript-eslint",
"prettier"
],
"extends": [
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"rules": {
"prettier/prettier": [
"error",
{
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
]
}
}
}

View File

@@ -0,0 +1,12 @@
const borderedText = (text: string) => {
const lines = text.split('\n');
const width = Math.max(...lines.map((l) => l.length));
const res = [`${'─'.repeat(width + 2)}`];
for (const line of lines) {
res.push(`${line.padEnd(width)}`);
}
res.push(`${'─'.repeat(width + 2)}`);
return res.join('\n');
};
export default borderedText;

17
node_modules/simple-update-notifier/src/cache.spec.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
import { createConfigDir, getLastUpdate, saveLastUpdate } from './cache';
createConfigDir();
jest.useFakeTimers().setSystemTime(new Date('2022-01-01'));
const fakeTime = new Date('2022-01-01').getTime();
test('can save update then get the update details', () => {
saveLastUpdate('test');
expect(getLastUpdate('test')).toBe(fakeTime);
});
test('prefixed module can save update then get the update details', () => {
saveLastUpdate('@alexbrazier/test');
expect(getLastUpdate('@alexbrazier/test')).toBe(fakeTime);
});

44
node_modules/simple-update-notifier/src/cache.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
const homeDirectory = os.homedir();
const configDir =
process.env.XDG_CONFIG_HOME ||
path.join(homeDirectory, '.config', 'simple-update-notifier');
const getConfigFile = (packageName: string) => {
return path.join(
configDir,
`${packageName.replace('@', '').replace('/', '__')}.json`
);
};
export const createConfigDir = () => {
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}
};
export const getLastUpdate = (packageName: string) => {
const configFile = getConfigFile(packageName);
try {
if (!fs.existsSync(configFile)) {
return undefined;
}
const file = JSON.parse(fs.readFileSync(configFile, 'utf8'));
return file.lastUpdateCheck as number;
} catch {
return undefined;
}
};
export const saveLastUpdate = (packageName: string) => {
const configFile = getConfigFile(packageName);
fs.writeFileSync(
configFile,
JSON.stringify({ lastUpdateCheck: new Date().getTime() })
);
};

View File

@@ -0,0 +1,35 @@
import Stream from 'stream';
import https from 'https';
import getDistVersion from './getDistVersion';
jest.mock('https', () => ({
get: jest.fn(),
}));
test('Valid response returns version', async () => {
const st = new Stream();
(https.get as jest.Mock).mockImplementation((url, cb) => {
cb(st);
st.emit('data', '{"latest":"1.0.0"}');
st.emit('end');
});
const version = await getDistVersion('test', 'latest');
expect(version).toEqual('1.0.0');
});
test('Invalid response throws error', async () => {
const st = new Stream();
(https.get as jest.Mock).mockImplementation((url, cb) => {
cb(st);
st.emit('data', 'some invalid json');
st.emit('end');
});
expect(getDistVersion('test', 'latest')).rejects.toThrow(
'Could not parse version response'
);
});

View File

@@ -0,0 +1,29 @@
import https from 'https';
const getDistVersion = async (packageName: string, distTag: string) => {
const url = `https://registry.npmjs.org/-/package/${packageName}/dist-tags`;
return new Promise<string>((resolve, reject) => {
https
.get(url, (res) => {
let body = '';
res.on('data', (chunk) => (body += chunk));
res.on('end', () => {
try {
const json = JSON.parse(body);
const version = json[distTag];
if (!version) {
reject(new Error('Error getting version'));
}
resolve(version);
} catch {
reject(new Error('Could not parse version response'));
}
});
})
.on('error', (err) => reject(err));
});
};
export default getDistVersion;

View File

@@ -0,0 +1,82 @@
import hasNewVersion from './hasNewVersion';
import { getLastUpdate } from './cache';
import getDistVersion from './getDistVersion';
jest.mock('./getDistVersion', () => jest.fn().mockReturnValue('1.0.0'));
jest.mock('./cache', () => ({
getLastUpdate: jest.fn().mockReturnValue(undefined),
createConfigDir: jest.fn(),
saveLastUpdate: jest.fn(),
}));
const pkg = { name: 'test', version: '1.0.0' };
afterEach(() => jest.clearAllMocks());
const defaultArgs = {
pkg,
shouldNotifyInNpmScript: true,
alwaysRun: true,
};
test('it should not trigger update for same version', async () => {
const newVersion = await hasNewVersion(defaultArgs);
expect(newVersion).toBe(false);
});
test('it should trigger update for patch version bump', async () => {
(getDistVersion as jest.Mock).mockReturnValue('1.0.1');
const newVersion = await hasNewVersion(defaultArgs);
expect(newVersion).toBe('1.0.1');
});
test('it should trigger update for minor version bump', async () => {
(getDistVersion as jest.Mock).mockReturnValue('1.1.0');
const newVersion = await hasNewVersion(defaultArgs);
expect(newVersion).toBe('1.1.0');
});
test('it should trigger update for major version bump', async () => {
(getDistVersion as jest.Mock).mockReturnValue('2.0.0');
const newVersion = await hasNewVersion(defaultArgs);
expect(newVersion).toBe('2.0.0');
});
test('it should not trigger update if version is lower', async () => {
(getDistVersion as jest.Mock).mockReturnValue('0.0.9');
const newVersion = await hasNewVersion(defaultArgs);
expect(newVersion).toBe(false);
});
it('should trigger update check if last update older than config', async () => {
const TWO_WEEKS = new Date().getTime() - 1000 * 60 * 60 * 24 * 14;
(getLastUpdate as jest.Mock).mockReturnValue(TWO_WEEKS);
const newVersion = await hasNewVersion({
pkg,
shouldNotifyInNpmScript: true,
});
expect(newVersion).toBe(false);
expect(getDistVersion).toHaveBeenCalled();
});
it('should not trigger update check if last update is too recent', async () => {
const TWELVE_HOURS = new Date().getTime() - 1000 * 60 * 60 * 12;
(getLastUpdate as jest.Mock).mockReturnValue(TWELVE_HOURS);
const newVersion = await hasNewVersion({
pkg,
shouldNotifyInNpmScript: true,
});
expect(newVersion).toBe(false);
expect(getDistVersion).not.toHaveBeenCalled();
});

View File

@@ -0,0 +1,40 @@
import semver from 'semver';
import { createConfigDir, getLastUpdate, saveLastUpdate } from './cache';
import getDistVersion from './getDistVersion';
import { IUpdate } from './types';
const hasNewVersion = async ({
pkg,
updateCheckInterval = 1000 * 60 * 60 * 24,
distTag = 'latest',
alwaysRun,
debug,
}: IUpdate) => {
createConfigDir();
const lastUpdateCheck = getLastUpdate(pkg.name);
if (
alwaysRun ||
!lastUpdateCheck ||
lastUpdateCheck < new Date().getTime() - updateCheckInterval
) {
const latestVersion = await getDistVersion(pkg.name, distTag);
saveLastUpdate(pkg.name);
if (semver.gt(latestVersion, pkg.version)) {
return latestVersion;
} else if (debug) {
console.error(
`Latest version (${latestVersion}) not newer than current version (${pkg.version})`
);
}
} else if (debug) {
console.error(
`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${updateCheckInterval}ms but only ${
new Date().getTime() - lastUpdateCheck
}ms since last check.`
);
}
return false;
};
export default hasNewVersion;

27
node_modules/simple-update-notifier/src/index.spec.ts generated vendored Normal file
View File

@@ -0,0 +1,27 @@
import simpleUpdateNotifier from '.';
import hasNewVersion from './hasNewVersion';
const consoleSpy = jest.spyOn(console, 'error');
jest.mock('./hasNewVersion', () => jest.fn().mockResolvedValue('2.0.0'));
beforeEach(jest.clearAllMocks);
test('it logs message if update is available', async () => {
await simpleUpdateNotifier({
pkg: { name: 'test', version: '1.0.0' },
alwaysRun: true,
});
expect(consoleSpy).toHaveBeenCalledTimes(1);
});
test('it does not log message if update is not available', async () => {
(hasNewVersion as jest.Mock).mockResolvedValue(false);
await simpleUpdateNotifier({
pkg: { name: 'test', version: '2.0.0' },
alwaysRun: true,
});
expect(consoleSpy).toHaveBeenCalledTimes(0);
});

34
node_modules/simple-update-notifier/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,34 @@
import isNpmOrYarn from './isNpmOrYarn';
import hasNewVersion from './hasNewVersion';
import { IUpdate } from './types';
import borderedText from './borderedText';
const simpleUpdateNotifier = async (args: IUpdate) => {
if (
!args.alwaysRun &&
(!process.stdout.isTTY || (isNpmOrYarn && !args.shouldNotifyInNpmScript))
) {
if (args.debug) {
console.error('Opting out of running simpleUpdateNotifier()');
}
return;
}
try {
const latestVersion = await hasNewVersion(args);
if (latestVersion) {
console.error(
borderedText(`New version of ${args.pkg.name} available!
Current Version: ${args.pkg.version}
Latest Version: ${latestVersion}`)
);
}
} catch (err) {
// Catch any network errors or cache writing errors so module doesn't cause a crash
if (args.debug && err instanceof Error) {
console.error('Unexpected error in simpleUpdateNotifier():', err);
}
}
};
export default simpleUpdateNotifier;

12
node_modules/simple-update-notifier/src/isNpmOrYarn.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import process from 'process';
const packageJson = process.env.npm_package_json;
const userAgent = process.env.npm_config_user_agent;
const isNpm6 = Boolean(userAgent && userAgent.startsWith('npm'));
const isNpm7 = Boolean(packageJson && packageJson.endsWith('package.json'));
const isNpm = isNpm6 || isNpm7;
const isYarn = Boolean(userAgent && userAgent.startsWith('yarn'));
const isNpmOrYarn = isNpm || isYarn;
export default isNpmOrYarn;

8
node_modules/simple-update-notifier/src/types.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
export interface IUpdate {
pkg: { name: string; version: string };
updateCheckInterval?: number;
shouldNotifyInNpmScript?: boolean;
distTag?: string;
alwaysRun?: boolean;
debug?: boolean;
}