Skip to content

Commit

Permalink
Print friendly error
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Oct 23, 2018
1 parent 1feaa5c commit 38bd634
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ function verifyTypeScriptSetup() {
},
};

const formatDiagnosticHost = {
getCanonicalFileName: fileName => fileName,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => os.EOL,
};

const messages = [];
let appTsConfig;
let parsedTsConfig;
Expand All @@ -114,7 +120,7 @@ function verifyTypeScriptSetup() {
);

if (error) {
throw error;
throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
}

appTsConfig = readTsConfig;
Expand All @@ -132,18 +138,21 @@ function verifyTypeScriptSetup() {
});

if (result.errors && result.errors.length) {
throw result.errors[0];
throw new Error(
ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
);
}

parsedCompilerOptions = result.options;
} catch (_) {
} catch (e) {
console.error(
chalk.red.bold(
'Could not parse',
chalk.cyan('tsconfig.json') + '.',
'Please make sure it contains syntactically correct JSON.'
)
);
console.error(e && e.message ? `Details: ${e.message}` : '');
process.exit(1);
}

Expand Down

0 comments on commit 38bd634

Please sign in to comment.