Add colors to debug logging
Lauren Tan committed
Jan 25, 2023 at 16:15 UTC
840bb6fec28845e094fb66ead03b0dbfdd2c55d4
3 files changed
+16
-23
compiler/forget/package.json
+1
-1
@@ -29,6 +29,7 @@
29
"@babel/generator": "7.2.0",
30
"@babel/plugin-syntax-jsx": "^7.18.6",
31
"@babel/types": "^7.19.0",
32
+ "chalk": "4",
33
"invariant": "^2.2.4",
34
"prettier": "2.7.1",
35
"pretty-format": "^24"
@@ -50,7 +51,6 @@
51
"@types/jest": "^29.0.3",
52
"@types/node": "^18.7.18",
53
"babel-jest": "^29.0.3",
53
- "chalk": "^3.0.0",
54
"concurrently": "^7.4.0",
55
"eslint": "^8.25.0",
56
"glob": "^7.1.6",
compiler/forget/src/Utils/logger.ts
+7
-6
@@ -5,6 +5,7 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
+import chalk from "chalk";
9
import { HIR, HIRFunction, ReactiveFunction } from "../HIR/HIR";
10
import { printFunction, printHIR } from "../HIR/PrintHIR";
11
import { printReactiveFunction } from "../ReactiveScopes";
@@ -22,9 +23,9 @@ export function logHIR(step: string, ir: HIR): void {
23
const printed = printHIR(ir);
24
if (printed !== lastLogged) {
25
lastLogged = printed;
25
- process.stdout.write(`${step}:\n${printed}\n\n`);
26
+ process.stdout.write(`${chalk.green(step)}:\n${printed}\n\n`);
27
} else {
27
- process.stdout.write(`${step}: (no change)\n\n`);
28
+ process.stdout.write(`${chalk.blue(step)}: (no change)\n\n`);
29
}
30
}
31
}
@@ -34,9 +35,9 @@ export function logHIRFunction(step: string, fn: HIRFunction): void {
35
const printed = printFunction(fn);
36
if (printed !== lastLogged) {
37
lastLogged = printed;
37
- process.stdout.write(`${step}:\n${printed}\n\n`);
38
+ process.stdout.write(`${chalk.green(step)}:\n${printed}\n\n`);
39
} else {
39
- process.stdout.write(`${step}: (no change)\n\n`);
40
+ process.stdout.write(`${chalk.blue(step)}: (no change)\n\n`);
41
}
42
}
43
}
@@ -46,9 +47,9 @@ export function logReactiveFunction(step: string, fn: ReactiveFunction): void {
47
const printed = printReactiveFunction(fn);
48
if (printed !== lastLogged) {
49
lastLogged = printed;
49
- process.stdout.write(`${step}:\n${printed}\n\n`);
50
+ process.stdout.write(`${chalk.green(step)}:\n${printed}\n\n`);
51
} else {
51
- process.stdout.write(`${step}: (no change)\n\n`);
52
+ process.stdout.write(`${chalk.blue(step)}: (no change)\n\n`);
53
}
54
}
55
}
compiler/forget/yarn.lock
+8
-16
@@ -1455,6 +1455,14 @@ caniuse-lite@^1.0.30001400:
1455
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001410.tgz#b5a86366fbbf439d75dd3db1d21137a73e829f44"
1456
integrity sha512-QoblBnuE+rG0lc3Ur9ltP5q47lbguipa/ncNMyyGuqPk44FxbScWAeEO+k5fSQ8WekdAK4mWqNs1rADDAiN5xQ==
1457
1458
+chalk@4, chalk@^4.0.0, chalk@^4.1.0:
1459
+ version "4.1.2"
1460
+ resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
1461
+ integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
1462
+ dependencies:
1463
+ ansi-styles "^4.1.0"
1464
+ supports-color "^7.1.0"
1465
+
1466
chalk@^2.0.0:
1467
version "2.4.2"
1468
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@@ -1464,22 +1472,6 @@ chalk@^2.0.0:
1472
escape-string-regexp "^1.0.5"
1473
supports-color "^5.3.0"
1474
1467
-chalk@^3.0.0:
1468
- version "3.0.0"
1469
- resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
1470
- integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
1471
- dependencies:
1472
- ansi-styles "^4.1.0"
1473
- supports-color "^7.1.0"
1474
-
1475
-chalk@^4.0.0, chalk@^4.1.0:
1476
- version "4.1.2"
1477
- resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
1478
- integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
1479
- dependencies:
1480
- ansi-styles "^4.1.0"
1481
- supports-color "^7.1.0"
1482
-
1475
char-regex@^1.0.2:
1476
version "1.0.2"
1477
resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf"