0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

feat: replace chalk with kleur (#1289) @DanielRuf

* chore: replace chalk with kleur

* build: add updated lockfile

* chore: add flow-typed stub for kleur 3.0.3

* chore: remove unnecessary whitespace

* test: update snapshot for update-banner.js

* chore: migrate logger.js from chalk to kleur

* chore: use import instead of require
This commit is contained in:
Daniel Ruf 2019-04-29 08:44:29 +02:00 committed by Juan Picado @jotadeveloper
parent 780ba27014
commit ff71640e8a
13 changed files with 105 additions and 170 deletions

View file

@ -1,98 +0,0 @@
// flow-typed signature: db5b2cdde8db39d47e27cc8ab84f89bf
// flow-typed version: d662d43161/chalk_v2.x.x/flow_>=v0.25.x
// From: https://github.com/chalk/chalk/blob/master/index.js.flow
declare module "chalk" {
declare type TemplateStringsArray = $ReadOnlyArray<string>;
declare type Level = $Values<{
None: 0,
Basic: 1,
Ansi256: 2,
TrueColor: 3
}>;
declare type ChalkOptions = {|
enabled?: boolean,
level?: Level
|};
declare type ColorSupport = {|
level: Level,
hasBasic: boolean,
has256: boolean,
has16m: boolean
|};
declare interface Chalk {
(...text: string[]): string,
(text: TemplateStringsArray, ...placeholders: string[]): string,
constructor(options?: ChalkOptions): Chalk,
enabled: boolean,
level: Level,
rgb(r: number, g: number, b: number): Chalk,
hsl(h: number, s: number, l: number): Chalk,
hsv(h: number, s: number, v: number): Chalk,
hwb(h: number, w: number, b: number): Chalk,
bgHex(color: string): Chalk,
bgKeyword(color: string): Chalk,
bgRgb(r: number, g: number, b: number): Chalk,
bgHsl(h: number, s: number, l: number): Chalk,
bgHsv(h: number, s: number, v: number): Chalk,
bgHwb(h: number, w: number, b: number): Chalk,
hex(color: string): Chalk,
keyword(color: string): Chalk,
+reset: Chalk,
+bold: Chalk,
+dim: Chalk,
+italic: Chalk,
+underline: Chalk,
+inverse: Chalk,
+hidden: Chalk,
+strikethrough: Chalk,
+visible: Chalk,
+black: Chalk,
+red: Chalk,
+green: Chalk,
+yellow: Chalk,
+blue: Chalk,
+magenta: Chalk,
+cyan: Chalk,
+white: Chalk,
+gray: Chalk,
+grey: Chalk,
+blackBright: Chalk,
+redBright: Chalk,
+greenBright: Chalk,
+yellowBright: Chalk,
+blueBright: Chalk,
+magentaBright: Chalk,
+cyanBright: Chalk,
+whiteBright: Chalk,
+bgBlack: Chalk,
+bgRed: Chalk,
+bgGreen: Chalk,
+bgYellow: Chalk,
+bgBlue: Chalk,
+bgMagenta: Chalk,
+bgCyan: Chalk,
+bgWhite: Chalk,
+bgBlackBright: Chalk,
+bgRedBright: Chalk,
+bgGreenBright: Chalk,
+bgYellowBright: Chalk,
+bgBlueBright: Chalk,
+bgMagentaBright: Chalk,
+bgCyanBright: Chalk,
+bgWhiteBrigh: Chalk,
supportsColor: ColorSupport
}
declare module.exports: Chalk;
}

33
flow-typed/npm/kleur_vx.x.x.js vendored Normal file
View file

@ -0,0 +1,33 @@
// flow-typed signature: 27250091946c7286334b6d8e332b126f
// flow-typed version: <<STUB>>/kleur_v3.0.3/flow_v0.81.0
/**
* This is an autogenerated libdef stub for:
*
* 'kleur'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/
declare module 'kleur' {
declare module.exports: any;
}
/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
// Filename aliases
declare module 'kleur/index' {
declare module.exports: $Exports<'kleur'>;
}
declare module 'kleur/index.js' {
declare module.exports: $Exports<'kleur'>;
}

View file

@ -22,7 +22,6 @@
"async": "3.0.1-0",
"body-parser": "1.19.0",
"bunyan": "1.8.12",
"chalk": "2.4.2",
"commander": "2.20.0",
"compression": "1.7.4",
"cookies": "0.7.3",
@ -36,6 +35,7 @@
"js-string-escape": "1.0.1",
"js-yaml": "3.13.1",
"jsonwebtoken": "8.5.1",
"kleur": "3.0.3",
"lockfile": "1.0.4",
"lodash": "4.17.11",
"lunr-mutable-indexes": "2.3.2",

View file

@ -8,20 +8,20 @@
import path from 'path';
import semver from 'semver';
import chalk from 'chalk';
import { bgYellow, bgRed } from 'kleur';
import {startVerdaccio, listenDefaultCallback} from './bootstrap';
import findConfigFile from './config-path';
import {verdaccioUpdateBanner} from './update-banner';
import { parseConfigFile } from './utils';
if (process.getuid && process.getuid() === 0) {
global.console.warn(chalk.bgYellow('Verdaccio doesn\'t need superuser privileges. Don\'t run it under root.'));
global.console.warn(bgYellow('Verdaccio doesn\'t need superuser privileges. Don\'t run it under root.'));
}
const MIN_NODE_VERSION = '6.9.0';
if (semver.satisfies(process.version, `>=${MIN_NODE_VERSION}`) === false) {
global.console.error(chalk.bgRed(`Verdaccio requires at least Node.js ${MIN_NODE_VERSION} or higher, please upgrade your Node.js distribution`));
global.console.error(bgRed(`Verdaccio requires at least Node.js ${MIN_NODE_VERSION} or higher, please upgrade your Node.js distribution`));
process.exit(1);
}

View file

@ -7,7 +7,7 @@ const cluster = require('cluster');
const Logger = require('bunyan');
const Error = require('http-errors');
const Stream = require('stream');
const chalk = require('chalk');
const { red, yellow, cyan, magenta, green, white, black, blue } = require('kleur');
const pkgJSON = require('../../package.json');
const _ = require('lodash');
const dayjs = require('dayjs');
@ -155,13 +155,13 @@ function setup(logs) {
// level to color
const levels = {
fatal: chalk.red,
error: chalk.red,
warn: chalk.yellow,
http: chalk.magenta,
info: chalk.cyan,
debug: chalk.green,
trace: chalk.white,
fatal: red,
error: red,
warn: yellow,
http: magenta,
info: cyan,
debug: green,
trace: white,
};
let max = 0;
@ -206,9 +206,9 @@ function fillInMsgTemplate(msg, obj, colors) {
if (!colors || str.includes('\n')) {
return str;
} else if (is_error) {
return chalk.red(str);
return red(str);
} else {
return chalk.green(str);
return green(str);
}
} else {
return require('util').inspect(str, null, null, colors);
@ -232,10 +232,10 @@ function print(type, msg, obj, colors) {
const subsystems = [
{
in: chalk.green('<--'),
out: chalk.yellow('-->'),
fs: chalk.black('-=-'),
default: chalk.blue('---'),
in: green('<--'),
out: yellow('-->'),
fs: black('-=-'),
default: blue('---'),
},
{
in: '<--',
@ -247,7 +247,7 @@ function print(type, msg, obj, colors) {
const sub = subsystems[colors ? 0 : 1][obj.sub] || subsystems[+!colors].default;
if (colors) {
return ` ${levels[type](pad(type))}${chalk.white(`${sub} ${finalMessage}`)}`;
return ` ${levels[type](pad(type))}${white(`${sub} ${finalMessage}`)}`;
} else {
return ` ${pad(type)}${sub} ${finalMessage}`;
}

View file

@ -5,7 +5,7 @@
import request from 'request';
import semver from 'semver';
import chalk from 'chalk';
import { red, green, blue, white, bold } from 'kleur';
import _ from 'lodash';
import { UPDATE_BANNER, DEFAULT_REGISTRY, HTTP_STATUS } from './constants';
@ -13,16 +13,16 @@ import { UPDATE_BANNER, DEFAULT_REGISTRY, HTTP_STATUS } from './constants';
const VERDACCIO_LATEST_REGISTRY_URL = `${DEFAULT_REGISTRY}/verdaccio/latest`;
/**
* Creates NPM update banner using chalk
* Creates NPM update banner using kleur
*/
export function createBanner(currentVersion: string, newVersion: string, releaseType: string): string {
const changelog = `${UPDATE_BANNER.CHANGELOG_URL}v${newVersion}`;
const versionUpdate = `${chalk.bold.red(currentVersion)}${chalk.bold.green(newVersion)}`;
const banner = chalk`
{white.bold A new ${_.upperCase(releaseType)} version of Verdaccio is available. ${versionUpdate} }
{white.bold Run ${chalk.green.bold('npm install -g verdaccio')} to update}.
{white.bold Registry: ${DEFAULT_REGISTRY}}
{blue.bold Changelog: ${changelog}}
const versionUpdate = `${bold().red(currentVersion)}${bold().green(newVersion)}`;
const banner = `
${white().bold('A new ' + _.upperCase(releaseType) + ' version of Verdaccio is available. ' + versionUpdate)}
${white().bold('Run ' + green('npm install -g verdaccio') + ' to update.')}
${white().bold('Registry: ' + DEFAULT_REGISTRY)}
${blue().bold('Changelog: ' + changelog)}
`;
return banner;
}
@ -31,9 +31,9 @@ export function createBanner(currentVersion: string, newVersion: string, release
* creates error banner
*/
export function createErrorBanner(message: string): string {
const banner = chalk`
{red.bold Unable to check verdaccio version on ${DEFAULT_REGISTRY}}
{red.bold Error: ${message}}
const banner = `
${red().bold('Unable to check verdaccio version on ' + DEFAULT_REGISTRY)}
${red().bold('Error: ' + message)}
`;
return banner;
}

View file

@ -1,4 +1,4 @@
const chalk = require('chalk');
const { yellow } = require('kleur');
const NodeEnvironment = require('jest-environment-node');
const puppeteer = require('puppeteer');
const fs = require('fs');
@ -30,7 +30,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
this.global.__VERDACCIO_E2E__ = fork[0];
this.global.__VERDACCIO__PROTECTED_E2E__ = fork2[0];
console.log(chalk.yellow('Setup Test Environment.'));
console.log(yellow('Setup Test Environment.'));
await super.setup();
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
@ -44,7 +44,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
}
async teardown() {
console.log(chalk.yellow('Teardown Test Environment.'));
console.log(yellow('Teardown Test Environment.'));
await super.teardown();
this.global.__VERDACCIO_E2E__.stop();
this.global.__VERDACCIO__PROTECTED_E2E__.stop();

View file

@ -1,4 +1,4 @@
const chalk = require('chalk');
const { green } = require('kleur');
const puppeteer = require('puppeteer');
const fs = require('fs');
const mkdirp = require('mkdirp');
@ -8,7 +8,7 @@ const path = require('path');
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function() {
console.log(chalk.green('Setup Puppeteer'));
console.log(green('Setup Puppeteer'));
const browser = await puppeteer.launch({ headless: true, /* slowMo: 300 */ args: ['--no-sandbox'] });
global.__BROWSER__ = browser;
mkdirp.sync(DIR);

View file

@ -1,4 +1,4 @@
const chalk = require('chalk');
const { green } = require('kleur');
const rimraf = require('rimraf');
const os = require('os');
const path = require('path');
@ -6,7 +6,7 @@ const path = require('path');
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function() {
console.log(chalk.green('Teardown Puppeteer'));
console.log(green('Teardown Puppeteer'));
await global.__BROWSER__.close();
rimraf.sync(DIR)
};

View file

@ -1,6 +1,6 @@
// @flow
import chalk from 'chalk';
import { yellow, green, blue, magenta } from 'kleur';
import path from 'path';
import NodeEnvironment from 'jest-environment-node';
import {VerdaccioConfig} from '../../lib/verdaccio-server';
@ -50,7 +50,7 @@ class FunctionalEnvironment extends NodeEnvironment {
storage: '/test-storage3'
}
];
console.log(chalk.green('Setup Verdaccio Servers'));
console.log(green('Setup Verdaccio Servers'));
const app = await this.startWeb();
this.global.__WEB_SERVER__ = app;
@ -60,13 +60,13 @@ class FunctionalEnvironment extends NodeEnvironment {
path.join(pathStore, config.storage),
path.join(pathStore, config.config),
`http://${DOMAIN_SERVERS}:${config.port}/`, config.port);
console.log(chalk.magentaBright(`Running registry ${config.config} on port ${config.port}`));
console.log(magenta(`Running registry ${config.config} on port ${config.port}`));
const server: IServerBridge = new Server(verdaccioConfig.domainPath);
serverList.push(server);
const process = new VerdaccioProcess(verdaccioConfig, server, SILENCE_LOG, DEBUG_INJECT);
const fork = await process.init();
console.log(chalk.blue(`Fork PID ${fork[1]}`));
console.log(blue(`Fork PID ${fork[1]}`));
forkList.push(fork);
}
@ -76,7 +76,7 @@ class FunctionalEnvironment extends NodeEnvironment {
async teardown() {
await super.teardown();
console.log(chalk.yellow('Teardown Test Environment.'));
console.log(yellow('Teardown Test Environment.'));
if (!this.global.__SERVERS_PROCESS__) {
throw new Error("There are no servers to stop");
}

View file

@ -1,4 +1,4 @@
module.exports = async function() {
// console.log(chalk.green('Teardown Verdaccio Functional'));
// console.log(chalk.blue('Teardown:: all server were closed'));
// console.log(green('Teardown Verdaccio Functional'));
// console.log(blue('Teardown:: all server were closed'));
};

View file

@ -5,10 +5,10 @@ exports[`Verdaccio update banner should print major update banner 1`] = `
"calls": Array [
Array [
"
A new MAJOR version of Verdaccio is available. 3.0.0 → 4.5.6 
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v4.5.6
A new MAJOR version of Verdaccio is available. 3.0.0 → 4.5.6
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v4.5.6
",
],
],
@ -26,10 +26,10 @@ exports[`Verdaccio update banner should print minor update banner 1`] = `
"calls": Array [
Array [
"
A new MINOR version of Verdaccio is available. 4.0.0 → 4.5.6 
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v4.5.6
A new MINOR version of Verdaccio is available. 4.0.0 → 4.5.6
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v4.5.6
",
],
],
@ -47,10 +47,10 @@ exports[`Verdaccio update banner should print patch update banner 1`] = `
"calls": Array [
Array [
"
A new PATCH version of Verdaccio is available. 4.5.0 → 4.5.6 
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v4.5.6
A new PATCH version of Verdaccio is available. 4.5.0 → 4.5.6
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v4.5.6
",
],
],
@ -68,8 +68,8 @@ exports[`Verdaccio update banner when default registry returns with error 1`] =
"calls": Array [
Array [
"
Unable to check verdaccio version on https://registry.npmjs.org
Error: {\\"message\\":\\"internal server error\\",\\"statusCode\\":500}
Unable to check verdaccio version on https://registry.npmjs.org
Error: {\\"message\\":\\"internal server error\\",\\"statusCode\\":500}
",
],
],
@ -84,34 +84,34 @@ exports[`Verdaccio update banner when default registry returns with error 1`] =
exports[`create banner should create a major update banner 1`] = `
"
A new MAJOR version of Verdaccio is available. 1.0.0 → 2.0.0 
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v2.0.0
A new MAJOR version of Verdaccio is available. 1.0.0 → 2.0.0
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v2.0.0
"
`;
exports[`create banner should create a minor update banner 1`] = `
"
A new MINOR version of Verdaccio is available. 1.0.0 → 1.1.0 
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v1.1.0
A new MINOR version of Verdaccio is available. 1.0.0 → 1.1.0
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v1.1.0
"
`;
exports[`create banner should create a patch update banner 1`] = `
"
A new PATCH version of Verdaccio is available. 1.0.0 → 1.0.1 
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v1.0.1
A new PATCH version of Verdaccio is available. 1.0.0 → 1.0.1
Run npm install -g verdaccio to update.
Registry: https://registry.npmjs.org
Changelog: https://github.com/verdaccio/verdaccio/releases/tag/v1.0.1
"
`;
exports[`createErrorBanner should create an error banner 1`] = `
"
Unable to check verdaccio version on https://registry.npmjs.org
Error: message
Unable to check verdaccio version on https://registry.npmjs.org
Error: message
"
`;

BIN
yarn.lock

Binary file not shown.