Skip to content

Commit

Permalink
fix(console): inline colors and drop chalk (#3043)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Apr 2, 2024
1 parent 6dd0e03 commit ff4fe4c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-pens-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/console": patch
---

Inline the colors we use and drop `chalk`
3 changes: 0 additions & 3 deletions packages/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
"lint": "rnx-kit-scripts lint",
"test": "rnx-kit-scripts test"
},
"dependencies": {
"chalk": "^4.1.0"
},
"devDependencies": {
"@rnx-kit/eslint-config": "*",
"@rnx-kit/jest-preset": "*",
Expand Down
23 changes: 16 additions & 7 deletions packages/console/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import chalk from "chalk";
import { WriteStream } from "tty";

type Log = typeof console.log;

export const error: Log = (...args) =>
console.error(chalk.red.bold("error"), ...args);
let errorTag: string;
let infoTag: string;
let warnTag: string;

export const info: Log = (...args) =>
console.log(chalk.cyan.bold("info"), ...args);
if (WriteStream.prototype.hasColors() && process.env["NODE_ENV"] !== "test") {
errorTag = "\u001B[31m\u001B[1merror\u001B[22m\u001B[39m";
infoTag = "\u001B[36m\u001B[1minfo\u001B[22m\u001B[39m";
warnTag = "\u001B[33m\u001B[1mwarn\u001B[22m\u001B[39m";
} else {
errorTag = "error";
infoTag = "info";
warnTag = "warn";
}

export const warn: Log = (...args) =>
console.warn(chalk.yellow.bold("warn"), ...args);
export const error: Log = (...args) => console.error(errorTag, ...args);
export const info: Log = (...args) => console.log(infoTag, ...args);
export const warn: Log = (...args) => console.warn(warnTag, ...args);
14 changes: 0 additions & 14 deletions packages/console/test/__mocks__/chalk.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/console/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { error, info, warn } from "../src/index";

jest.mock("chalk");

describe("console", () => {
const consoleErrorSpy = jest.spyOn(global.console, "error");
const consoleLogSpy = jest.spyOn(global.console, "log");
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3758,7 +3758,6 @@ __metadata:
"@rnx-kit/tsconfig": "npm:*"
"@types/jest": "npm:^29.2.1"
"@types/node": "npm:^20.0.0"
chalk: "npm:^4.1.0"
eslint: "npm:^8.56.0"
jest: "npm:^29.2.1"
prettier: "npm:^3.0.0"
Expand Down

0 comments on commit ff4fe4c

Please sign in to comment.