Skip to content

Commit

Permalink
fix: log line and column
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 8, 2021
1 parent a4bb9ce commit 6a0d247
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
12 changes: 8 additions & 4 deletions packages/vite-plugin-checker/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ export function diagnosticToTerminalLog(d: NormalizedDiagnostic): string {

const levelLabel = labelMap[d.level || DiagnosticCategory.Error]
const fileLabel = chalk.green.bold('FILE') + ' '
const position = d.loc
? chalk.yellow(d.loc.start.line) + ':' + chalk.yellow(d.loc.start.column)
: ''

return [
levelLabel + ' ' + d.message,
fileLabel + d.id + os.EOL,
fileLabel + d.id + ':' + position + os.EOL,
d.codeFrame + os.EOL,
d.conclusion,
]
Expand All @@ -70,13 +74,13 @@ export function diagnosticToViteError(d: NormalizedDiagnostic): ErrorPayload['er
if (d.loc) {
loc = {
file: d.id,
line: d.loc.start.line + 1,
column: typeof d.loc.start.column === 'number' ? d.loc.start.column + 1 : 0,
line: d.loc.start.line,
column: typeof d.loc.start.column === 'number' ? d.loc.start.column : 0,
}
}

return {
message: d.message ?? '',
message: d.message + os.EOL + d.stripedCodeFrame,
stack:
typeof d.stack === 'string' ? d.stack : Array.isArray(d.stack) ? d.stack.join(os.EOL) : '',
id: d.id,
Expand Down
21 changes: 11 additions & 10 deletions packages/vite-plugin-checker/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ export function tsDiagnosticToViteError(d: ts.Diagnostic): ErrorPayload['err'] {
// has detail message
if (d.file && typeof d.start === 'number' && typeof d.length === 'number') {
return {
message:
message: strip(
ts.flattenDiagnosticMessageText(d.messageText, formatHost.getNewLine()) +
os.EOL +
os.EOL +
createFrame({
source: d.file!.text,
location: tsLocationToBabelLocation({
start: d.file?.getLineAndCharacterOfPosition(d.start),
end: d.file?.getLineAndCharacterOfPosition(d.start + d.length),
}),
}),
os.EOL +
os.EOL +
createFrame({
source: d.file!.text,
location: tsLocationToBabelLocation({
start: d.file?.getLineAndCharacterOfPosition(d.start),
end: d.file?.getLineAndCharacterOfPosition(d.start + d.length),
}),
})
),
stack: '',
id: d.file?.fileName,
plugin: 'vite-plugin-checker',
Expand Down

0 comments on commit 6a0d247

Please sign in to comment.