refactor: replace chalk with smaller alternative

This commit is contained in:
biodiscus 2025-05-08 23:25:06 +02:00
parent 341c6d46d7
commit ffb3ec453b
No known key found for this signature in database
GPG Key ID: 7A7E275431E71F2D
26 changed files with 41 additions and 39 deletions

View File

@ -8,9 +8,9 @@
"@pm2/io": "~6.1.0",
"@pm2/js-api": "~0.8.0",
"@pm2/pm2-version-check": "latest",
"ansis": "4.0.0",
"async": "~3.2.6",
"blessed": "0.1.81",
"chalk": "3.0.0",
"chokidar": "^3.5.3",
"cli-tableau": "^2.0.0",
"commander": "2.15.1",
@ -66,6 +66,8 @@
"ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, ""],
"ansis": ["ansis@4.0.0", "", {}, "sha512-P8nrHI1EyW9OfBt1X7hMSwGN2vwRuqHSKJAT1gbLWZRzDa24oHjYwGHvEgHeBepupzk878yS/HBZ0NMPYtbolw=="],
"anymatch": ["anymatch@3.1.3", "", { "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" } }, ""],
"argparse": ["argparse@2.0.1", "", {}, ""],

View File

@ -7,7 +7,7 @@
var debug = require('debug')('pm2:conf');
var p = require('path');
var util = require('util');
var chalk = require('chalk');
var chalk = require('ansis');
/**
* Get PM2 path structure

View File

@ -11,7 +11,7 @@ var eachLimit = require('async/eachLimit');
var series = require('async/series');
var debug = require('debug')('pm2:cli');
var util = require('util');
var chalk = require('chalk');
var chalk = require('ansis');
var fclone = require('fclone');
var IMMUTABLE_MSG = chalk.bold.blue('Use --update-env to update environment variables');

View File

@ -12,7 +12,7 @@ const eachLimit = require('async/eachLimit');
const series = require('async/series');
const debug = require('debug')('pm2:cli');
const util = require('util');
const chalk = require('chalk');
const chalk = require('ansis');
const fclone = require('fclone');
var DockerMgmt = require('./API/ExtraMgmt/Docker.js')

View File

@ -2,7 +2,7 @@
var Common = require('../Common.js');
var cst = require('../../constants.js');
var UX = require('./UX');
var chalk = require('chalk');
var chalk = require('ansis');
var Configuration = require('../Configuration.js');
module.exports = function(CLI) {

View File

@ -1,7 +1,7 @@
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var chalk = require('chalk');
var chalk = require('ansis');
var util = require('util');
var fmt = require('../tools/fmt.js');
var fs = require('fs');
@ -322,7 +322,7 @@ module.exports = function(CLI) {
})
.catch(function(err) {
console.log();
console.log(chalk.grey('Raw error=', err.message));
console.log(chalk.gray('Raw error=', err.message));
self.disconnect();
});

View File

@ -8,7 +8,7 @@
var cst = require('../../constants.js');
var Common = require('../Common.js');
var UX = require('./UX');
var chalk = require('chalk');
var chalk = require('ansis');
var path = require('path');
var fs = require('fs');
var fmt = require('../tools/fmt.js');
@ -258,10 +258,10 @@ module.exports = function(CLI) {
isInner = false
else if (isInner == false)
isInner = true
console.log(chalk.grey(l))
console.log(chalk.gray(l))
}
else if (l.startsWith('`'))
console.log(chalk.grey(l))
console.log(chalk.gray(l))
else
console.log(l)
})

View File

@ -5,7 +5,7 @@
*/
var fs = require('fs'),
util = require('util'),
chalk = require('chalk'),
chalk = require('ansis'),
forEachLimit = require('async/forEachLimit'),
dayjs = require('dayjs');
@ -53,7 +53,7 @@ Log.tail = function(apps_list, lines, raw, callback) {
return next();
getLastLines(app.path, lines, function(output) {
console.log(chalk.grey('%s last %d lines:'), app.path, lines);
console.log(chalk.gray('%s last %d lines:'), app.path, lines);
output.forEach(function(out) {
if (raw)
return app.type === 'err' ? console.error(out) : console.log(out);
@ -89,7 +89,7 @@ Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
socket.on('reconnect attempt', function() {
if (global._auto_exit === true) {
if (timestamp)
process.stdout.write(chalk['dim'](chalk.grey(dayjs().format(timestamp) + ' ')));
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
process.stdout.write(chalk.blue(pad(DEFAULT_PADDING, 'PM2') + ' | ') + '[[[ Target PM2 killed. ]]]');
process.exit(0);
}
@ -125,7 +125,7 @@ Log.stream = function(Client, id, raw, timestamp, exclusive, highlight) {
return type === 'err' ? process.stderr.write(util.format(line) + '\n') : process.stdout.write(util.format(line) + '\n');
if (timestamp)
process.stdout.write(chalk['dim'](chalk.grey(dayjs().format(timestamp) + ' ')));
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
var name = packet.process.pm_id + '|' + packet.process.name;
@ -191,7 +191,7 @@ Log.devStream = function(Client, id, raw, timestamp, exclusive) {
return process.stdout.write(util.format(line) + '\n');
if (timestamp)
process.stdout.write(chalk['dim'](chalk.grey(dayjs().format(timestamp) + ' ')));
process.stdout.write(chalk['dim'](chalk.gray(dayjs().format(timestamp) + ' ')));
var name = packet.process.name + '-' + packet.process.pm_id;

View File

@ -1,4 +1,4 @@
var chalk = require('chalk');
var chalk = require('ansis');
var util = require('util');
var fs = require('fs');
var exec = require('child_process').exec;
@ -72,7 +72,7 @@ module.exports = function(CLI) {
if (process.getuid() != 0) {
return exec('whoami', function(err, stdout, stderr) {
Common.printError(cst.PREFIX_MSG + 'You have to run this command as root. Execute the following command:');
Common.printError(cst.PREFIX_MSG + chalk.grey(' sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' pm2 logrotate -u ' + stdout.trim()));
Common.printError(cst.PREFIX_MSG + chalk.gray(' sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' pm2 logrotate -u ' + stdout.trim()));
cb ? cb(Common.retErr('You have to run this with elevated rights')) : that.exitCli(cst.ERROR_EXIT);
});
@ -171,7 +171,7 @@ module.exports = function(CLI) {
if (lines === 0)
return Log.stream(that.Client, id, raw, timestamp, exclusive, highlight);
Common.printOut(chalk.bold.grey(util.format.call(this, '[TAILING] Tailing last %d lines for [%s] process%s (change the value with --lines option)', lines, id, id === 'all' ? 'es' : '')));
Common.printOut(chalk.bold.gray(util.format.call(this, '[TAILING] Tailing last %d lines for [%s] process%s (change the value with --lines option)', lines, id, id === 'all' ? 'es' : '')));
// Populate the array `files_list` with the paths of all files we need to tail
list.forEach(function(proc) {
@ -312,7 +312,7 @@ module.exports = function(CLI) {
return that.exitCli(cst.SUCCESS_EXIT)
}
Common.printOut(chalk.bold.grey(util.format.call(this, '[TAILING] Tailing last %d lines for [%s] process%s (change the value with --lines option)', lines, id, id === 'all' ? 'es' : '')));
Common.printOut(chalk.bold.gray(util.format.call(this, '[TAILING] Tailing last %d lines for [%s] process%s (change the value with --lines option)', lines, id, id === 'all' ? 'es' : '')));
// Populate the array `files_list` with the paths of all files we need to tail
list.forEach(function(proc) {

View File

@ -3,7 +3,7 @@ var path = require('path');
var fs = require('fs');
var os = require('os');
var spawn = require('child_process').spawn;
var chalk = require('chalk');
var chalk = require('ansis');
var parallel = require('async/parallel');
var Configuration = require('../../Configuration.js');

View File

@ -2,7 +2,7 @@ const path = require('path');
const fs = require('fs');
const os = require('os');
const spawn = require('child_process').spawn;
const chalk = require('chalk');
const chalk = require('ansis');
const readline = require('readline')
const which = require('../../tools/which.js')

View File

@ -7,7 +7,7 @@
var cst = require('../../../constants.js');
var Common = require('../../Common.js');
var chalk = require('chalk');
var chalk = require('ansis');
var forEachLimit = require('async/forEachLimit');
var Modularizer = require('./Modularizer.js');

View File

@ -10,7 +10,7 @@
var multimeter = require('pm2-multimeter');
var os = require('os');
var p = require('path');
var chalk = require('chalk');
var chalk = require('ansis');
var UX = require('./UX');

View File

@ -3,7 +3,7 @@
* Use of this source code is governed by a license that
* can be found in the LICENSE file.
*/
var chalk = require('chalk');
var chalk = require('ansis');
var path = require('path');
var fs = require('fs');
var forEachLimit = require('async/forEachLimit');

View File

@ -1,4 +1,4 @@
const chalk = require('chalk')
const chalk = require('ansis')
const Helpers = {}
/**

View File

@ -1,5 +1,5 @@
const Table = require('cli-tableau')
const chalk = require('chalk')
const chalk = require('ansis')
const UxHelpers = require('./helpers.js')
const Common = require('../../Common.js')

View File

@ -3,7 +3,7 @@ const cst = require('../../../constants')
const Common = require('../../Common')
const Configuration = require('../../Configuration')
const UxHelpers = require('./helpers.js')
const chalk = require('chalk')
const chalk = require('ansis')
const Table = require('cli-tableau')
const Passwd = require('../../tools/passwd.js')
@ -280,7 +280,7 @@ function listModulesAndAppsManaged(list, commander) {
// Watch status
if (!CONDENSED_MODE)
obj[key].push(l.pm2_env.watch ? chalk.green.bold('enabled') : chalk.grey('disabled'))
obj[key].push(l.pm2_env.watch ? chalk.green.bold('enabled') : chalk.gray('disabled'))
UxHelpers.safe_push(app_table, obj)
}
@ -452,7 +452,7 @@ function miniMonitBar(sys_infos) {
disks.forEach(fs => {
let use = sys_metrics[`fs:use:${fs}`].value
if (use > 60)
sys_summary_line += `${chalk.grey(fs)} ${UxHelpers.colorizedMetric(use, 80, 90, '%')} `
sys_summary_line += `${chalk.gray(fs)} ${UxHelpers.colorizedMetric(use, 80, 90, '%')} `
})
}

View File

@ -1,7 +1,7 @@
'use strict'
var cst = require('../../../constants.js');
const chalk = require('chalk');
const chalk = require('ansis');
const path = require('path');
const fs = require('fs');
const Table = require('cli-tableau');

View File

@ -11,7 +11,7 @@ const tryEach = require('async/tryEach')
const path = require('path')
const os = require('os')
const needle = require('needle')
const chalk = require('chalk')
const chalk = require('ansis')
const cst = require('../../../../constants.js')
const promptly = require('promptly')

View File

@ -2,7 +2,7 @@
var cst = require('../../../constants.js');
var Common = require('../../Common.js');
const chalk = require('chalk');
const chalk = require('ansis');
const forEach = require('async/forEach');
const open = require('../../tools/open.js');
const Modules = require('../Modules');

View File

@ -1,7 +1,7 @@
var cst = require('../../../constants.js');
var Common = require('../../Common.js');
var chalk = require('chalk');
var chalk = require('ansis');
var fs = require('fs');
var KMDaemon = require('@pm2/agent/src/InteractorClient');
var pkg = require('../../../package.json')

View File

@ -12,7 +12,7 @@ var fs = require('fs');
var path = require('path');
var os = require('os');
var util = require('util');
var chalk = require('chalk');
var chalk = require('ansis');
var fclone = require('fclone');
var semver = require('semver');
var dayjs = require('dayjs');

View File

@ -5,7 +5,7 @@ process.env.PM2_USAGE = 'CLI';
var cst = require('../../constants.js');
var commander = require('commander');
var chalk = require('chalk');
var chalk = require('ansis');
var forEachLimit = require('async/forEachLimit');
var debug = require('debug')('pm2:cli');
@ -1013,7 +1013,7 @@ commander.command('autoinstall')
commander.command('examples')
.description('display pm2 usage examples')
.action(() => {
console.log(cst.PREFIX_MSG + chalk.grey('pm2 usage examples:\n'));
console.log(cst.PREFIX_MSG + chalk.gray('pm2 usage examples:\n'));
displayExamples();
process.exit(cst.SUCCESS_EXIT);
})

View File

@ -11,7 +11,7 @@ var PM2 = require('../..');
var Log = require('../API/Log');
var cst = require('../../constants.js');
var pkg = require('../../package.json');
var chalk = require('chalk');
var chalk = require('ansis');
var path = require('path');
var fmt = require('../tools/fmt.js');
var exec = require('child_process').exec;

View File

@ -172,9 +172,9 @@
"@pm2/js-api": "~0.8.0",
"@pm2/io": "~6.1.0",
"@pm2/pm2-version-check": "latest",
"ansis": "4.0.0",
"async": "~3.2.6",
"blessed": "0.1.81",
"chalk": "3.0.0",
"chokidar": "^3.5.3",
"cli-tableau": "^2.0.0",
"commander": "2.15.1",

View File

@ -3,7 +3,7 @@ const forEachLimit = require('async/forEachLimit')
const fs = require('fs')
const exec = require('child_process').exec
const path = require('path')
const chalk = require('chalk')
const chalk = require('ansis')
const Table = require('cli-table-redemption');
const testFolder = './test/e2e/'