Skip to content

Commit

Permalink
fix(tsc): show all errors in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 8, 2021
1 parent 4976ddc commit a4bb9ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/vite-plugin-checker/src/checkers/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const createDiagnostic: CreateDiagnostic<Pick<PluginConfig, 'typescript'>> = (ch
currErr = diagnosticToViteError(formattedDiagnostics)
}

logChunk = diagnosticToTerminalLog(formattedDiagnostics)
logChunk += os.EOL + diagnosticToTerminalLog(formattedDiagnostics)
}

const reportWatchStatusChanged: ts.WatchStatusReporter = (
Expand Down
36 changes: 26 additions & 10 deletions packages/vite-plugin-checker/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,33 @@ interface NormalizedDiagnostic {
/** error code location */
loc?: SourceLocation
/** error level */
level?: 'error' | 'warning'
level?: DiagnosticCategory
}

// copied from TypeScript because we used `import type`.
export enum DiagnosticCategory {
Warning = 0,
Error = 1,
Suggestion = 2,
Message = 3,
}

export function diagnosticToTerminalLog(d: NormalizedDiagnostic): string {
const levelLabel =
d.level === 'error'
? chalk.red.bold('ERROR') + ' '
: d.level === 'warning'
? chalk.yellow.bold('WARNING') + ' '
: ''
const fileLabel = chalk.green.bold('FILE') + ' '
return [levelLabel + d.message, fileLabel + d.id + os.EOL, d.codeFrame + os.EOL, d.conclusion]
const labelMap: Record<DiagnosticCategory, string> = {
[DiagnosticCategory.Error]: chalk.bold.red('ERROR'),
[DiagnosticCategory.Warning]: chalk.bold.yellow('WARNING'),
[DiagnosticCategory.Suggestion]: chalk.bold.blue('SUGGESTION'),
[DiagnosticCategory.Message]: chalk.bold.cyan('MESSAGE'),
}

const levelLabel = labelMap[d.level || DiagnosticCategory.Error]
const fileLabel = chalk.green.bold('FILE') + ' '
return [
levelLabel + ' ' + d.message,
fileLabel + d.id + os.EOL,
d.codeFrame + os.EOL,
d.conclusion,
]
.filter(Boolean)
.join(os.EOL)
}
Expand Down Expand Up @@ -118,6 +133,7 @@ export function isTsDiagnostic(d: any): d is TsDiagnostic {
}

export function normalizeTsDiagnostic(d: TsDiagnostic): NormalizedDiagnostic {
// console.log(d.category)
const fileName = d.file?.fileName
const {
flattenDiagnosticMessageText,
Expand Down Expand Up @@ -152,7 +168,7 @@ export function normalizeTsDiagnostic(d: TsDiagnostic): NormalizedDiagnostic {
id: fileName,
checker: 'TypeScript',
loc,
level: 'error',
level: d.category,
}
}

Expand Down

0 comments on commit a4bb9ce

Please sign in to comment.