Skip to content

Commit

Permalink
fix: make typescriptformatter support 0.5 of fork checker (#5879)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and Timer committed Nov 23, 2018
1 parent 1164f6b commit 3a14e8f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/react-dev-utils/typescriptFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ const chalk = require('chalk');
const fs = require('fs');

function formatter(message, useColors) {
const hasGetters = typeof message.getFile === 'function';
const colors = new chalk.constructor({ enabled: useColors });
const messageColor = message.isWarningSeverity() ? colors.yellow : colors.red;

const source =
message.getFile() &&
fs.existsSync(message.getFile()) &&
fs.readFileSync(message.getFile(), 'utf-8');
let source;

if (hasGetters) {
source =
message.getFile() &&
fs.existsSync(message.getFile()) &&
fs.readFileSync(message.getFile(), 'utf-8');
} else {
source =
message.file &&
fs.existsSync(message.file) &&
fs.readFileSync(message.file, 'utf-8');
}

let frame = '';

if (source) {
Expand All @@ -33,9 +44,11 @@ function formatter(message, useColors) {
.join(os.EOL);
}

const severity = hasGetters ? message.getSeverity() : message.severity;

return [
messageColor.bold(`Type ${message.getSeverity().toLowerCase()}: `) +
message.getContent() +
messageColor.bold(`Type ${severity.toLowerCase()}: `) +
(hasGetters ? message.getContent() : message.content) +
' ' +
messageColor.underline(`TS${message.code}`),
'',
Expand Down

0 comments on commit 3a14e8f

Please sign in to comment.