[refactor] Replace ansis with built-in function util.styleText (#3793)

> What does the pull request accomplish?

One external dependency less.
This commit is contained in:
Kristjan ESPERANTO 2025-05-27 22:36:02 +02:00 committed by GitHub
parent 85b4ece767
commit e26aed927d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 13 deletions

View File

@ -31,6 +31,7 @@ planned for 2025-07-01
- Switch Stylelint config to flat format and simplify Stylelint scripts - Switch Stylelint config to flat format and simplify Stylelint scripts
- [workflow] Replace Node.js version v23 with v24 (#3770) - [workflow] Replace Node.js version v23 with v24 (#3770)
- [refactor] Replace deprecated constants `fs.F_OK` and `fs.R_OK` (#3789) - [refactor] Replace deprecated constants `fs.F_OK` and `fs.R_OK` (#3789)
- [refactor] Replace `ansis` with built-in function `util.styleText`
### Fixed ### Fixed

View File

@ -1,7 +1,7 @@
const path = require("node:path"); const path = require("node:path");
const fs = require("node:fs"); const fs = require("node:fs");
const { styleText } = require("node:util");
const Ajv = require("ajv"); const Ajv = require("ajv");
const colors = require("ansis");
const globals = require("globals"); const globals = require("globals");
const { Linter } = require("eslint"); const { Linter } = require("eslint");
@ -61,7 +61,7 @@ function checkConfigFile () {
); );
if (errors.length === 0) { if (errors.length === 0) {
Log.info(colors.green("Your configuration file doesn't contain syntax errors :)")); Log.info(styleText("green", "Your configuration file doesn't contain syntax errors :)"));
validateModulePositions(configFileName); validateModulePositions(configFileName);
} else { } else {
let errorMessage = "Your configuration file contains syntax errors :("; let errorMessage = "Your configuration file contains syntax errors :(";
@ -112,7 +112,7 @@ function validateModulePositions (configFileName) {
const valid = validate(data); const valid = validate(data);
if (valid) { if (valid) {
Log.info(colors.green("Your modules structure configuration doesn't contain errors :)")); Log.info(styleText("green", "Your modules structure configuration doesn't contain errors :)"));
} else { } else {
const module = validate.errors[0].instancePath.split("/")[2]; const module = validate.errors[0].instancePath.split("/")[2];
const position = validate.errors[0].instancePath.split("/")[3]; const position = validate.errors[0].instancePath.split("/")[3];

View File

@ -2,7 +2,7 @@
(function (root, factory) { (function (root, factory) {
if (typeof exports === "object") { if (typeof exports === "object") {
if (process.env.JEST_WORKER_ID === undefined) { if (process.env.JEST_WORKER_ID === undefined) {
const colors = require("ansis"); const { styleText } = require("node:util");
// add timestamps in front of log messages // add timestamps in front of log messages
require("console-stamp")(console, { require("console-stamp")(console, {
@ -12,13 +12,13 @@
const { method, defaultTokens } = arg; const { method, defaultTokens } = arg;
let label = defaultTokens.label(arg); let label = defaultTokens.label(arg);
if (method === "error") { if (method === "error") {
label = colors.red(label); label = styleText("red", label);
} else if (method === "warn") { } else if (method === "warn") {
label = colors.yellow(label); label = styleText("yellow", label);
} else if (method === "debug") { } else if (method === "debug") {
label = colors.bgBlue(label); label = styleText("bgBlue", label);
} else if (method === "info") { } else if (method === "info") {
label = colors.blue(label); label = styleText("blue", label);
} }
return label; return label;
}, },
@ -26,11 +26,11 @@
const { method, defaultTokens } = arg; const { method, defaultTokens } = arg;
let msg = defaultTokens.msg(arg); let msg = defaultTokens.msg(arg);
if (method === "error") { if (method === "error") {
msg = colors.red(msg); msg = styleText("red", msg);
} else if (method === "warn") { } else if (method === "warn") {
msg = colors.yellow(msg); msg = styleText("yellow", msg);
} else if (method === "info") { } else if (method === "info") {
msg = colors.blue(msg); msg = styleText("blue", msg);
} }
return msg; return msg;
} }

1
package-lock.json generated
View File

@ -11,7 +11,6 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"ajv": "^8.17.1", "ajv": "^8.17.1",
"ansis": "^4.0.0",
"console-stamp": "^3.1.2", "console-stamp": "^3.1.2",
"envsub": "^4.1.0", "envsub": "^4.1.0",
"eslint": "^9.27.0", "eslint": "^9.27.0",

View File

@ -63,7 +63,6 @@
}, },
"dependencies": { "dependencies": {
"ajv": "^8.17.1", "ajv": "^8.17.1",
"ansis": "^4.0.0",
"console-stamp": "^3.1.2", "console-stamp": "^3.1.2",
"envsub": "^4.1.0", "envsub": "^4.1.0",
"eslint": "^9.27.0", "eslint": "^9.27.0",