Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): emit success false in compileTypeScriptFiles if typescript diagnostic contains errors #10068

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/js/src/utils/typescript/compile-typescript-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import { createAsyncIterable } from '../create-async-iterable/create-async-itera
import { NormalizedExecutorOptions } from '../schema';
import { loadTsTransformers } from './load-ts-transformers';

const TYPESCRIPT_FOUND_N_ERRORS_WATCHING_FOR_FILE_CHANGES = 6194;
// Typescript diagnostic message for 6194: Found {0} errors. Watching for file changes.
// https://github.com/microsoft/TypeScript/blob/d45012c5e2ab122919ee4777a7887307c5f4a1e0/src/compiler/diagnosticMessages.json#L4763-L4766
const ERROR_COUNT_REGEX = /Found (\d+) errors/;

function getErrorCountFromMessage(messageText: string) {
return Number.parseInt(ERROR_COUNT_REGEX.exec(messageText)[1]);
}

export async function* compileTypeScriptFiles(
normalizedOptions: NormalizedExecutorOptions,
context: ExecutorContext,
Expand Down Expand Up @@ -53,9 +62,11 @@ export async function* compileTypeScriptFiles(
async ({ next, done }) => {
if (normalizedOptions.watch) {
compileTypeScriptWatcher(tscOptions, async (d: Diagnostic) => {
if (d.code === 6194) {
if (d.code === TYPESCRIPT_FOUND_N_ERRORS_WATCHING_FOR_FILE_CHANGES) {
await postCompilationCallback();
next(getResult(true));
next(
getResult(getErrorCountFromMessage(d.messageText as string) === 0)
);
}
});
} else {
Expand Down