Skip to content

Commit

Permalink
Add log util
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 10, 2024
1 parent fb71a2c commit 328ba01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/knip/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ const run = async () => {
}

if (experimentalTags.length > 0) {
const prefix = `${picocolors.yellow('DEPRECATION WARNING:')}`;
console.warn(`\n${prefix} --experimental-tags is deprecated, please start using --tags instead`);
logWarning('DEPRECATION WARNING', '--experimental-tags is deprecated, please start using --tags instead');
}

if (!noExitCode && totalErrorCount > Number(maxIssues)) {
Expand All @@ -137,8 +136,7 @@ const run = async () => {
process.exitCode = 2;
if (!isDebug && error instanceof Error && isKnownError(error)) {
const knownError = getKnownError(error);
const prefix = `${picocolors.red('ERROR:')}`;
console.error(`${prefix} ${knownError.message}`);
logError('ERROR', knownError.message);
if (hasCause(knownError)) console.error('Reason:', knownError.cause.message);
if (isConfigurationError(knownError)) console.log('\nRun `knip --help` or visit https://knip.dev for help');
process.exit(2);
Expand Down
9 changes: 9 additions & 0 deletions packages/knip/src/util/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import picocolors from 'picocolors';

export const logWarning = (prefix: string, message: string) => {
console.warn(`${picocolors.yellow(prefix)}: ${message}`);
};

export const logError = (prefix: string, message: string) => {
console.error(`${picocolors.red(prefix)}: ${message}`);
};

0 comments on commit 328ba01

Please sign in to comment.