Skip to content

Commit 2a745f8

Browse files
committed
perf: switch to colorette
1 parent 1c0f94f commit 2a745f8

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@tsconfig/strictest": "^2.0.5",
4040
"@types/babel__code-frame": "^7.0.6",
4141
"@types/node": "^16.18.126",
42-
"chalk": "^4.1.2",
42+
"colorette": "^2.0.20",
4343
"execa": "^5.1.1",
4444
"fast-json-stable-stringify": "^2.1.0",
4545
"lint-staged": "^11.2.6",

packages/vite-plugin-checker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
},
3838
"dependencies": {
3939
"@babel/code-frame": "^7.26.2",
40-
"chalk": "^4.1.2",
4140
"chokidar": "^3.6.0",
41+
"colorette": "^2.0.20",
4242
"npm-run-path": "^4.0.1",
4343
"strip-ansi": "^6.0.1",
4444
"tiny-invariant": "^1.3.3",

packages/vite-plugin-checker/src/checkers/typescript/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'node:os'
22
import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import { parentPort } from 'node:worker_threads'
5-
import chalk from 'chalk'
5+
import * as colors from 'colorette'
66
import invariant from 'tiny-invariant'
77
import ts from 'typescript'
88

@@ -110,7 +110,7 @@ const createDiagnostic: CreateDiagnostic<'typescript'> = (pluginConfig) => {
110110
if (terminal) {
111111
const color = errorCount && errorCount > 0 ? 'red' : 'green'
112112
consoleLog(
113-
chalk[color](
113+
colors[color](
114114
logChunk +
115115
os.EOL +
116116
wrapCheckerSummary(

packages/vite-plugin-checker/src/checkers/vls/diagnostics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import fs from 'node:fs'
22
import os from 'node:os'
33
import path from 'node:path'
44
import { Duplex } from 'node:stream'
5-
import chalk from 'chalk'
65
import chokidar from 'chokidar'
6+
import * as colors from 'colorette'
77
import { globSync } from 'tinyglobby'
88
import { VLS } from 'vls'
99
import type { TextDocument } from 'vscode-languageserver-textdocument'
@@ -79,11 +79,11 @@ export async function diagnostics(
7979

8080
if (workspace) {
8181
const absPath = path.resolve(process.cwd(), workspace)
82-
console.log(`Loading Vetur in workspace path: ${chalk.green(absPath)}`)
82+
console.log(`Loading Vetur in workspace path: ${colors.green(absPath)}`)
8383
workspaceUri = URI.file(absPath)
8484
} else {
8585
console.log(
86-
`Loading Vetur in current directory: ${chalk.green(process.cwd())}`,
86+
`Loading Vetur in current directory: ${colors.green(process.cwd())}`,
8787
)
8888
workspaceUri = URI.file(process.cwd())
8989
}

packages/vite-plugin-checker/src/logger.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs'
22
import { createRequire } from 'node:module'
33
import os from 'node:os'
4-
import chalk from 'chalk'
4+
import * as colors from 'colorette'
55
import strip from 'strip-ansi'
66
import * as _vscodeUri from 'vscode-uri'
77

@@ -95,25 +95,27 @@ export function diagnosticToTerminalLog(
9595
name?: 'TypeScript' | 'vue-tsc' | 'VLS' | 'ESLint' | 'Stylelint' | 'Biome',
9696
): string {
9797
const nameInLabel = name ? `(${name})` : ''
98-
const boldBlack = chalk.bold.rgb(0, 0, 0)
98+
const boldBlack = (str: string) => colors.bold(colors.black(str))
9999

100100
const labelMap: Record<DiagnosticLevel, string> = {
101-
[DiagnosticLevel.Error]: boldBlack.bgRedBright(` ERROR${nameInLabel} `),
102-
[DiagnosticLevel.Warning]: boldBlack.bgYellowBright(
103-
` WARNING${nameInLabel} `,
101+
[DiagnosticLevel.Error]: boldBlack(
102+
colors.bgRedBright(` ERROR${nameInLabel} `),
104103
),
105-
[DiagnosticLevel.Suggestion]: boldBlack.bgBlueBright(
106-
` SUGGESTION${nameInLabel} `,
104+
[DiagnosticLevel.Warning]: boldBlack(
105+
colors.bgYellowBright(` WARNING${nameInLabel} `),
107106
),
108-
[DiagnosticLevel.Message]: boldBlack.bgCyanBright(
109-
` MESSAGE${nameInLabel} `,
107+
[DiagnosticLevel.Suggestion]: boldBlack(
108+
colors.bgBlueBright(` SUGGESTION${nameInLabel} `),
109+
),
110+
[DiagnosticLevel.Message]: boldBlack(
111+
colors.bgCyanBright(` MESSAGE${nameInLabel} `),
110112
),
111113
}
112114

113115
const levelLabel = labelMap[d.level ?? DiagnosticLevel.Error]
114-
const fileLabel = `${boldBlack.bgCyanBright(' FILE ')} `
116+
const fileLabel = `${boldBlack(colors.bgCyanBright(' FILE '))} `
115117
const position = d.loc
116-
? `${chalk.yellow(d.loc.start.line)}:${chalk.yellow(d.loc.start.column)}`
118+
? `${colors.yellow(d.loc.start.line)}:${colors.yellow(d.loc.start.column || '')}`
117119
: ''
118120

119121
return [
@@ -200,7 +202,7 @@ export function composeCheckerSummary(
200202
const hasError = errorCount > 0
201203
const hasWarning = warningCount > 0
202204
const color = hasError ? 'red' : hasWarning ? 'yellow' : 'green'
203-
return chalk[color](wrapCheckerSummary(checkerName, message))
205+
return colors[color](wrapCheckerSummary(checkerName, message))
204206
}
205207

206208
/* ------------------------------- TypeScript ------------------------------- */

packages/vite-plugin-checker/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawn } from 'node:child_process'
2-
import chalk from 'chalk'
2+
import * as colors from 'colorette'
33
import npmRunPath from 'npm-run-path'
44

55
import type { ConfigEnv, Logger, Plugin } from 'vite'
@@ -219,7 +219,7 @@ export function checker(userConfig: UserPluginConfig): Plugin {
219219
} else {
220220
setTimeout(() => {
221221
logger!.warn(
222-
chalk.yellow(
222+
colors.yellow(
223223
'[vite-plugin-checker]: `server.ws.on` is introduced to Vite in 2.6.8, see [PR](https://github.com/vitejs/vite/pull/5273) and [changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#268-2021-10-18). \nvite-plugin-checker relies on `server.ws.on` to send overlay message to client. Support for Vite < 2.6.8 will be removed in the next major version release.',
224224
),
225225
)

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)