From 701d2a71368974078d4d07bf8f2700dda8edf5c0 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 23 Jan 2025 14:26:54 +0800 Subject: [PATCH] Use `node-text-style` in script files (#17034) --- package.json | 1 + scripts/build/build.js | 12 ++++++------ scripts/check-deps.js | 10 +++++----- yarn.lock | 8 ++++++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 91c287178..9846fb283 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "jest-watch-typeahead": "2.2.2", "knip": "5.42.2", "magic-string": "0.30.17", + "node-style-text": "0.0.6", "npm-run-all2": "7.0.2", "prettier": "3.4.2", "pretty-bytes": "6.1.1", diff --git a/scripts/build/build.js b/scripts/build/build.js index 81da23764..8d38d2a09 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -3,8 +3,8 @@ import fs from "node:fs/promises"; import path from "node:path"; import readline from "node:readline"; -import chalk from "chalk"; import createEsmUtils from "esm-utils"; +import styleText from "node-style-text"; import prettyBytes from "pretty-bytes"; import { DIST_DIR } from "../utils/index.js"; import files from "./config.js"; @@ -26,7 +26,7 @@ const padStatusText = (text) => { }; const status = {}; for (const { color, text } of statusConfig) { - status[text] = chalk[color].black(padStatusText(text)); + status[text] = styleText[color].black(padStatusText(text)); } function fitTerminal(input, suffix = "") { @@ -34,7 +34,7 @@ function fitTerminal(input, suffix = "") { const WIDTH = columns - maxLength + 1; if (input.length < WIDTH) { const repeatCount = Math.max(WIDTH - input.length - 1 - suffix.length, 0); - input += chalk.dim(".").repeat(repeatCount) + suffix; + input += styleText.dim(".").repeat(repeatCount) + suffix; } return input; } @@ -103,13 +103,13 @@ async function buildFile({ file, files, cliOptions, results }) { if (stableSize) { const { size } = await fs.stat(path.join(DIST_DIR, outputFile)); const sizeDiff = size - stableSize; - const message = chalk[sizeDiff > 0 ? "yellow" : "green"]( + const message = styleText[sizeDiff > 0 ? "yellow" : "green"]( prettyBytes(sizeDiff), ); sizeMessages.push(`${message}`); } else { - sizeMessages.push(chalk.blue("[NEW FILE]")); + sizeMessages.push(styleText.blue("[NEW FILE]")); } } @@ -146,7 +146,7 @@ async function run() { } } - console.log(chalk.inverse(" Building packages ")); + console.log(styleText.inverse(" Building packages ")); const results = []; for (const file of files) { diff --git a/scripts/check-deps.js b/scripts/check-deps.js index 097a2867a..aeb655653 100644 --- a/scripts/check-deps.js +++ b/scripts/check-deps.js @@ -1,5 +1,5 @@ import fs from "node:fs/promises"; -import chalk from "chalk"; +import styleText from "node-style-text"; const packageJson = JSON.parse( await fs.readFile(new URL("../package.json", import.meta.url)), @@ -9,11 +9,11 @@ validateDependencyObject(packageJson.dependencies); validateDependencyObject(packageJson.devDependencies); function validateDependencyObject(object) { - for (const key of Object.keys(object)) { - if (object[key][0] === "^" || object[key][0] === "~") { + for (const [name, version] of Object.entries(object)) { + if (version[0] === "^" || version[0] === "~") { console.error( - chalk.red("error"), - `Dependency "${chalk.bold.red(key)}" should be pinned.`, + styleText.bgRed.black(" ERROR "), + `Dependency "${styleText.bold.blue(name)}" should be pinned.`, ); process.exitCode = 1; } diff --git a/yarn.lock b/yarn.lock index 7b821a135..399dfb2fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6882,6 +6882,13 @@ __metadata: languageName: node linkType: hard +"node-style-text@npm:0.0.6": + version: 0.0.6 + resolution: "node-style-text@npm:0.0.6" + checksum: 10/9eeb6a054597ed122f16ec1fc404a687f75c857655cc1478b0f8b6ccd14f8badfbaeacc0b9cd5dcf84b8286986e52c5feffbf070ed4568acb7f4eb2f1cb6a5a3 + languageName: node + linkType: hard + "nopt@npm:^7.0.0": version: 7.2.1 resolution: "nopt@npm:7.2.1" @@ -7564,6 +7571,7 @@ __metadata: micromatch: "npm:4.0.8" minimist: "npm:1.2.8" n-readlines: "npm:1.0.1" + node-style-text: "npm:0.0.6" npm-run-all2: "npm:7.0.2" outdent: "npm:0.8.0" parse-json: "npm:8.1.0"