Skip to content

Commit 8930a58

Browse files
committed
MC-3095: Display TypeScript errors within local build process
- Report on resolved errors
1 parent 746548a commit 8930a58

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

ts-error-stopgap.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ process.stdin.on('end', () => {
5656
}
5757

5858
const newErrors = [];
59+
const resolvedErrors = [];
5960
// Walk each file to do an error comparison
6061
for (const [file, errors] of Object.entries(compilerErrors)) {
6162
let newErrs = errors;
63+
let resolved = [];
6264
// Walk each file to do an error comparison
6365
const oldFileErrors = priorStats[file];
6466
if (oldFileErrors && oldFileErrors.length > 0) {
@@ -68,30 +70,42 @@ process.stdin.on('end', () => {
6870
// error from the states file on disk
6971
return !oldFileErrors.some(err => err.message === e.message);
7072
});
73+
resolved = oldFileErrors.filter(e => {
74+
return !errors.some(err => err.message === e.message);
75+
});
7176
}
7277
// Collect any newly-reported errors
7378
newErrors.push(...newErrs);
79+
resolvedErrors.push(...resolved);
7480
}
7581

76-
if (!newErrors.length) {
77-
process.exit(0);
78-
}
82+
if (newErrors.length > 0) {
83+
console.log(
84+
chalk.red(`${newErrors.length} new TypeScript error(s) were introduced to the code base with your changes. \n`) +
85+
chalk.black.bgRed('You must resolve all new TypeScript errors before merging a PR.')
86+
);
7987

80-
console.log(
81-
chalk.red(`${newErrors.length} new TypeScript error(s) were introduced to the code base with your changes. \n`) +
82-
chalk.white.bgRed('You must resolve all new TypeScript errors before merging a PR.')
83-
);
84-
85-
newErrors.forEach(err => {
86-
console.log(chalk.red(err.rawError + "\n"));
87-
err.rawSnippet.split("\n").forEach(raw => {
88-
console.log(" " + raw);
88+
newErrors.forEach(err => {
89+
console.log(chalk.red(err.rawError + "\n"));
90+
err.rawSnippet.split("\n").forEach(raw => {
91+
console.log(" " + raw);
92+
});
8993
});
90-
});
9194

92-
console.log(
93-
"\n" +
94-
chalk.red(`${newErrors.length} new TypeScript error(s) were introduced to the code base with your changes. \n`) +
95-
chalk.white.bgRed('You must resolve all new TypeScript errors before merging a PR.')
96-
);
95+
console.log(
96+
"\n" +
97+
chalk.red(`${newErrors.length} new TypeScript error(s) were introduced to the code base with your changes. \n`) +
98+
chalk.black.bgRed('You must resolve all new TypeScript errors before merging a PR.')
99+
);
100+
}
101+
102+
if (resolvedErrors.length > 0) {
103+
console.log(
104+
chalk.black.bgGreen(`Looks like you've fixed ~${resolvedErrors.length} of our existing error(s)! Here's a cookie to celebrate 🍪`)
105+
);
106+
}
107+
108+
if (!newErrors.length) {
109+
process.exit(0);
110+
}
97111
});

0 commit comments

Comments
 (0)