diff --git a/.changeset/crisp-dots-like.md b/.changeset/crisp-dots-like.md new file mode 100644 index 00000000000..63ed10a29e3 --- /dev/null +++ b/.changeset/crisp-dots-like.md @@ -0,0 +1,5 @@ +--- +'@react-docgen/cli': patch +--- + +Remove chalk dependency and replace with builtin Node.js `styleText` diff --git a/packages/react-docgen-cli/package.json b/packages/react-docgen-cli/package.json index 7c8f07fae8d..8be16546f70 100644 --- a/packages/react-docgen-cli/package.json +++ b/packages/react-docgen-cli/package.json @@ -35,7 +35,6 @@ }, "license": "MIT", "dependencies": { - "chalk": "5.6.2", "commander": "15.0.0", "debug": "4.4.3", "fast-glob": "3.3.3", diff --git a/packages/react-docgen-cli/src/commands/parse/output/outputError.ts b/packages/react-docgen-cli/src/commands/parse/output/outputError.ts index 708ec76a78f..0989cbde96a 100644 --- a/packages/react-docgen-cli/src/commands/parse/output/outputError.ts +++ b/packages/react-docgen-cli/src/commands/parse/output/outputError.ts @@ -1,5 +1,5 @@ -import { relative } from 'path'; -import chalk from 'chalk'; +import { relative } from 'node:path'; +import { styleText } from 'node:util'; function isReactDocgenError(error: NodeJS.ErrnoException): boolean { return Boolean( @@ -13,7 +13,7 @@ function outputReactDocgenError( { failOnWarning }: { failOnWarning: boolean }, ): boolean { let label = 'WARNING'; - let color = chalk.yellow; + let format: 'red' | 'yellow' = 'yellow'; let log = console.warn; let isError = false; @@ -21,15 +21,21 @@ function outputReactDocgenError( process.exitCode = 2; isError = true; label = 'ERROR'; - color = chalk.red; + format = 'red'; log = console.error; } + const relativePath = styleText( + 'underline', + relative(process.cwd(), filePath), + { stream: process.stderr }, + ); + log( - color( - `▶ ${label}: ${error.message} 👀\n in ${chalk.underline( - relative(process.cwd(), filePath), - )}\n`, + styleText( + format, + `▶ ${label}: ${error.message} 👀\n in ${relativePath}\n`, + { stream: process.stderr }, ), ); @@ -43,10 +49,10 @@ export default function outputError( ): boolean { if (isReactDocgenError(error)) { return outputReactDocgenError(error, filePath, options); - } else { - process.exitCode = 1; - console.error(error); - - return true; } + + process.exitCode = 1; + console.error(error); + + return true; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79911d387a0..7397869b6f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -134,9 +134,6 @@ importers: packages/react-docgen-cli: dependencies: - chalk: - specifier: 5.6.2 - version: 5.6.2 commander: specifier: 15.0.0 version: 15.0.0