Skip to content

Commit b9941c3

Browse files
authored
refactor(deps): migrate chalk to picocolors (#1822)
1 parent dd84260 commit b9941c3

File tree

10 files changed

+24
-37
lines changed

10 files changed

+24
-37
lines changed

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"@rspress/core": "workspace:*",
4747
"@rspress/shared": "workspace:*",
4848
"cac": "^6.7.14",
49-
"chokidar": "^3.6.0"
49+
"chokidar": "^3.6.0",
50+
"picocolors": "^1.1.1"
5051
},
5152
"devDependencies": {
5253
"@microsoft/api-extractor": "^7.49.2",

packages/cli/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createRequire } from 'node:module';
22
import path from 'node:path';
33
import { build, dev, serve } from '@rspress/core';
4-
import chalk from '@rspress/shared/chalk';
54
import { logger } from '@rspress/shared/logger';
65
import { cac } from 'cac';
76
import chokidar from 'chokidar';
7+
import picocolors from 'picocolors';
88
import { loadConfigFile, resolveDocRoot } from './config/loadConfigFile';
99
import update from './update';
1010

@@ -78,7 +78,7 @@ cli
7878
}
7979
isRestarting = true;
8080
console.log(
81-
`\n✨ ${eventName} ${chalk.green(
81+
`\n✨ ${eventName} ${picocolors.green(
8282
path.relative(cwd, filepath),
8383
)}, dev server will restart...\n`,
8484
);

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"lodash-es": "^4.17.21",
7878
"mdast-util-mdxjs-esm": "^1.3.1",
7979
"memfs": "^4.17.0",
80+
"picocolors": "^1.1.1",
8081
"react": "^18.3.1",
8182
"react-dom": "^18.3.1",
8283
"react-helmet-async": "^1.3.0",

packages/core/src/node/build.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
normalizeSlash,
1212
withBase,
1313
} from '@rspress/shared';
14-
import chalk from '@rspress/shared/chalk';
1514
import { logger } from '@rspress/shared/logger';
15+
import picocolors from 'picocolors';
1616
import type { HelmetData } from 'react-helmet-async';
1717
import { PluginDriver } from './PluginDriver';
1818
import {
@@ -100,15 +100,15 @@ export async function renderPages(
100100
// see: https://github.com/web-infra-dev/rspress/issues/1317
101101
if (typeof ssgConfig === 'object' && ssgConfig.strict) {
102102
logger.error(
103-
`Failed to load SSG bundle: ${chalk.yellow(ssrBundlePath)}.`,
103+
`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}.`,
104104
);
105105
throw e;
106106
}
107107

108108
// fallback to CSR
109109
logger.error(e);
110110
logger.warn(
111-
`Failed to load SSG bundle: ${chalk.yellow(ssrBundlePath)}, fallback to CSR.`,
111+
`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}, fallback to CSR.`,
112112
);
113113
}
114114
}
@@ -149,14 +149,14 @@ export async function renderPages(
149149
} catch (e) {
150150
if (typeof ssgConfig === 'object' && ssgConfig.strict) {
151151
logger.error(
152-
`Page "${chalk.yellow(routePath)}" SSG rendering failed.`,
152+
`Page "${picocolors.yellow(routePath)}" SSG rendering failed.`,
153153
);
154154
throw e;
155155
}
156156

157157
// fallback to CSR
158158
logger.warn(
159-
`Page "${chalk.yellow(routePath)}" SSG rendering error: ${e.message}, fallback to CSR.`,
159+
`Page "${picocolors.yellow(routePath)}" SSG rendering error: ${e.message}, fallback to CSR.`,
160160
);
161161
}
162162
}
@@ -221,7 +221,7 @@ export async function renderPages(
221221
await emptyDir(join(outputPath, 'html'));
222222

223223
const totalTime = Date.now() - startTime;
224-
logger.success(`Pages rendered in ${chalk.yellow(totalTime)} ms.`);
224+
logger.success(`Pages rendered in ${picocolors.yellow(totalTime)} ms.`);
225225
} catch (e) {
226226
logger.error(`Pages render error: ${e.stack}`);
227227
throw e;

packages/core/src/node/runtimeModule/siteData/highlightLanguages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_HIGHLIGHT_LANGUAGES } from '@rspress/shared';
2-
import chalk from '@rspress/shared/chalk';
2+
import picocolors from 'picocolors';
33

44
let supportedLanguages: Set<string>;
55

@@ -26,7 +26,7 @@ export function handleHighlightLanguages(
2626
} else if (useDeprecatedTypeWarning) {
2727
// Deprecated warning
2828
console.log(
29-
`${chalk.yellowBright(
29+
`${picocolors.yellowBright(
3030
'warning',
3131
)} Automatic import is supported. \`highlightLanguages\` is now used only as alias, and string types will be ignored. \n`,
3232
);

packages/core/src/node/searchIndex.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import fs from 'node:fs/promises';
33
import type { IncomingMessage, ServerResponse } from 'node:http';
44
import path, { join } from 'node:path';
55
import { SEARCH_INDEX_NAME, type UserConfig, isSCM } from '@rspress/shared';
6-
import chalk from '@rspress/shared/chalk';
76
import { logger } from '@rspress/shared/logger';
7+
import picocolors from 'picocolors';
88
import { OUTPUT_DIR, TEMP_DIR, isProduction } from './constants';
99

1010
export async function writeSearchIndex(config: UserConfig) {
@@ -54,13 +54,13 @@ export async function writeSearchIndex(config: UserConfig) {
5454
});
5555

5656
logger.info(
57-
chalk.green(
57+
picocolors.green(
5858
`[doc-tools] Search index uploaded to ${apiUrl}, indexName: ${indexName}`,
5959
),
6060
);
6161
} catch (e) {
6262
logger.info(
63-
chalk.red(
63+
picocolors.red(
6464
`[doc-tools] Upload search index \`${indexName}\` failed:\n ${e}`,
6565
),
6666
);

packages/shared/modern.config.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ const config: ReturnType<typeof defineConfig> = defineConfig({
44
plugins: [moduleTools()],
55
buildConfig: [
66
{
7-
input: [
8-
'src/index.ts',
9-
'src/logger.ts',
10-
'src/chalk.ts',
11-
'src/node-utils.ts',
12-
],
7+
input: ['src/index.ts', 'src/logger.ts', 'src/node-utils.ts'],
138
target: 'esnext',
149
format: 'esm',
1510
buildType: 'bundle',
1611
dts: false,
1712
autoExtension: true,
1813
},
1914
{
20-
input: [
21-
'src/index.ts',
22-
'src/logger.ts',
23-
'src/chalk.ts',
24-
'src/node-utils.ts',
25-
],
15+
input: ['src/index.ts', 'src/logger.ts', 'src/node-utils.ts'],
2616
target: 'esnext',
2717
format: 'cjs',
2818
buildType: 'bundle',

packages/shared/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
"import": "./dist/index.mjs",
1414
"require": "./dist/index.js"
1515
},
16-
"./chalk": {
17-
"types": "./dist/chalk.d.ts",
18-
"import": "./dist/chalk.mjs",
19-
"require": "./dist/chalk.js"
20-
},
2116
"./logger": {
2217
"types": "./dist/logger.d.ts",
2318
"import": "./dist/logger.mjs",
@@ -46,7 +41,6 @@
4641
},
4742
"dependencies": {
4843
"@rsbuild/core": "1.2.3",
49-
"chalk": "5.4.1",
5044
"gray-matter": "4.0.3",
5145
"lodash-es": "^4.17.21",
5246
"unified": "^10.1.2"

packages/shared/src/chalk.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)