Skip to content

Commit

Permalink
Replace chalk by picocolors (vercel/turborepo#8390)
Browse files Browse the repository at this point in the history
We replaced chalk with picocolors as it is much more optimal and
smaller.

Discussions: vercel/turborepo#8341

In this PR has been the replacement in all the packages inside
/packages/, I will make another one for the update of the examples, but
I can also include in this same PR.

I have deleted in 2 package.json the dependency on:
@types/chalk-animation as I checked and it was not being used.

Picocolors does not have the function to pass a hexadecimal colour to
ASCII, to keep the colours, I have created the function and here 2
things to comment.

I have created this function in the most used place in the turbo-utils /
logger, but it is also used in 1 specific place, that's why I have used
the export.

1. The implementation does not use the ‘bits’ because typescript gives
error, if you see it necessary I can change the implementation.
2. I don't know if this is the right place to put this function, do you
think it's necessary to create a test?

---------

Co-authored-by: torresgol10.itd <torresgol10.itd@gmail.com>
Co-authored-by: Anthony Shew <anthony.shew@vercel.com>
  • Loading branch information
3 people committed Jul 12, 2024
1 parent e821515 commit feb65c1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/devlow-bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"dependencies": {
"@datadog/datadog-api-client": "^1.13.0",
"chalk": "2.4.2",
"inquirer": "^9.2.7",
"minimist": "^1.2.8",
"picocolors": "1.0.1",
"pidusage-tree": "^2.0.5",
"playwright-chromium": "^1.39.0",
"split2": "^4.2.0",
Expand Down
28 changes: 17 additions & 11 deletions packages/devlow-bench/src/interfaces/console.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
import { Interface, Scenario, ScenarioVariant } from "../index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { bgCyan, bold, magenta, red, underline } from "picocolors";
import { formatUnit } from "../units.js";
import { formatVariant } from "../utils.js";

export default function createInterface(): Interface {
const iface: Interface = {
start: async (scenario, props) => {
console.log(
chalk.bold.underline(`Running ${formatVariant(scenario, props)}...`)
bold(underline(`Running ${formatVariant(scenario, props)}...`))
);
},
measurement: async (scenario, props, name, value, unit, relativeTo) => {
console.log(
chalk.bgCyan.bold.magenta(
`${formatVariant(scenario, props)}: ${name} = ${formatUnit(
value,
unit
)}${relativeTo ? ` (from ${relativeTo})` : ""}`
bgCyan(
bold(
magenta(
`${formatVariant(scenario, props)}: ${name} = ${formatUnit(
value,
unit
)}${relativeTo ? ` (from ${relativeTo})` : ""}`
)
)
)
);
},
error: async (scenario, props, error) => {
console.log(
chalk.bold.red(
`${formatVariant(scenario, props)}: ${
(error && (error as any).stack) || error
}`
bold(
red(
`${formatVariant(scenario, props)}: ${
(error && (error as any).stack) || error
}`
)
)
);
},
Expand Down
1 change: 0 additions & 1 deletion packages/devlow-bench/src/interfaces/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Interface, Scenario, ScenarioVariant } from "../index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { formatUnit } from "../units.js";
import { formatVariant } from "../utils.js";

Expand Down
1 change: 0 additions & 1 deletion packages/devlow-bench/src/interfaces/json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Interface, Scenario, ScenarioVariant } from "../index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { formatUnit } from "../units.js";
import { formatVariant } from "../utils.js";
import { writeFile } from "fs/promises";
Expand Down
1 change: 0 additions & 1 deletion packages/devlow-bench/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare module "chalk";
declare module "pidusage-tree";

0 comments on commit feb65c1

Please sign in to comment.