Skip to content

Commit 4a6953a

Browse files
wChenonlyyifancong
andauthored
chore: use picocolors instead of chalk and fix docs links (#1060)
Co-authored-by: yifancong <[email protected]>
1 parent 5f9ff5c commit 4a6953a

File tree

7 files changed

+32
-24
lines changed

7 files changed

+32
-24
lines changed

examples/webpack-minimal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"license": "MIT",
1818
"dependencies": {
1919
"@babel/highlight": "7.18.6",
20-
"chalk": "4.1.2",
20+
"chalk": "^5.4.1",
2121
"css-loader": "^6.9.0",
2222
"htmlparser2": "7.2.0",
2323
"mini-svg-data-uri": "^1.4.4"

examples/webpack-minimal/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Instance } from 'chalk';
1+
import { Chalk } from 'chalk';
22
import { highlight } from './utils';
33
import { getHtmlText } from './html';
44
import { key6 } from './utils2';
5-
import "./style.css";
5+
import './style.css';
66

7-
const print = new Instance();
7+
const print = new Chalk();
88

99
print(key6);
1010
print(getHtmlText('<div>Test Text</div>'));

packages/document/docs/zh/config/options/options.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Rsdoctor 报告输出目录,默认是构建产物输出目录。
263263

264264
<Badge text="Deprecated" type="warning" />
265265

266-
请看 [output.reportDir](#reportDir)
266+
请看 [output.reportDir](#reportdir)
267267

268268
### supports
269269

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"acorn": "^8.10.0",
8080
"acorn-import-attributes": "^1.9.5",
8181
"acorn-walk": "8.3.4",
82-
"chalk": "^4.1.2",
82+
"picocolors": "^1.1.1",
8383
"connect": "3.7.0",
8484
"deep-eql": "4.1.4",
8585
"envinfo": "7.14.0",

packages/utils/src/error/error.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { codeFrameColumns } from '@babel/code-frame';
22
import { Err, Rule } from '@rsdoctor/types';
3-
import { Chalk, Instance } from 'chalk';
3+
import { createColors } from 'picocolors';
44
import deepEql from 'deep-eql';
55
import stripAnsi from 'strip-ansi';
66
import { transform } from './transform';
@@ -87,7 +87,7 @@ export class DevToolError extends Error implements Err.DevToolErrorInstance {
8787
return this._codeFrame;
8888
}
8989

90-
private printCodeFrame(print: Chalk) {
90+
private printCodeFrame(print: ReturnType<typeof createColors>) {
9191
const msgs: string[] = [];
9292
const { _codeFrame: codeFrameOpt, _controller: controller } = this;
9393

@@ -179,17 +179,19 @@ export class DevToolError extends Error implements Err.DevToolErrorInstance {
179179
referenceUrl,
180180
_controller: controller,
181181
} = this;
182-
const print = controller.noColor
183-
? new Instance({ level: 0 })
184-
: new Instance({ level: 3 });
182+
183+
const print = createColors(!controller.noColor);
184+
185185
const mainColorPrint =
186186
this._level === Err.ErrorLevel.Error ? print.red : print.yellow;
187-
const codeText = code ? `${mainColorPrint.blue(code)}:` : '';
187+
188+
const codeText = code ? `${mainColorPrint(print.blue(code))}:` : '';
188189

189190
msgs.push(
190-
mainColorPrint.bold(
191-
`[${codeText}${this.level}:${title.toUpperCase()}] `,
192-
) + message,
191+
mainColorPrint(
192+
print.bold(`[${codeText}${this.level}:${title.toUpperCase()}] `) +
193+
message,
194+
),
193195
);
194196
msgs.push(...this.printCodeFrame(print));
195197

@@ -202,11 +204,11 @@ export class DevToolError extends Error implements Err.DevToolErrorInstance {
202204
}
203205

204206
if (referenceUrl) {
205-
msgs.push(print.magenta.bold(` See: ${referenceUrl}`));
207+
msgs.push(print.magenta(print.bold(` See: ${referenceUrl}`)));
206208
}
207209

208210
if (!controller.noStack && this.stack) {
209-
msgs.push(print.red.bold(` Error Stack:\n${this.stack}\n`));
211+
msgs.push(print.red(print.bold(` Error Stack:\n${this.stack}\n`)));
210212
}
211213

212214
return msgs.join('\n');

packages/utils/src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from 'chalk';
1+
import c from 'picocolors';
22
import { logger } from 'rslog';
33
import { Constants } from '@rsdoctor/types';
44

@@ -14,7 +14,7 @@ export function debug(getMsg: () => string, prefix = '') {
1414
logger.debug(`${prefix} ${getMsg()}`);
1515
}
1616

17-
export { chalk, logger };
17+
export { c as chalk, logger };
1818

1919
logger.override({
2020
log: (message) => {

pnpm-lock.yaml

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)