Skip to content

Commit 328ba01

Browse files
committedNov 10, 2024
Add log util
1 parent fb71a2c commit 328ba01

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎packages/knip/src/cli.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ const run = async () => {
126126
}
127127

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

133132
if (!noExitCode && totalErrorCount > Number(maxIssues)) {
@@ -137,8 +136,7 @@ const run = async () => {
137136
process.exitCode = 2;
138137
if (!isDebug && error instanceof Error && isKnownError(error)) {
139138
const knownError = getKnownError(error);
140-
const prefix = `${picocolors.red('ERROR:')}`;
141-
console.error(`${prefix} ${knownError.message}`);
139+
logError('ERROR', knownError.message);
142140
if (hasCause(knownError)) console.error('Reason:', knownError.cause.message);
143141
if (isConfigurationError(knownError)) console.log('\nRun `knip --help` or visit https://knip.dev for help');
144142
process.exit(2);

‎packages/knip/src/util/log.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import picocolors from 'picocolors';
2+
3+
export const logWarning = (prefix: string, message: string) => {
4+
console.warn(`${picocolors.yellow(prefix)}: ${message}`);
5+
};
6+
7+
export const logError = (prefix: string, message: string) => {
8+
console.error(`${picocolors.red(prefix)}: ${message}`);
9+
};

0 commit comments

Comments
 (0)
Please sign in to comment.