From 446cd7423ded4777c01d4774e24ec16a2d780d1b Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Sat, 18 May 2019 15:27:35 -0700 Subject: [PATCH 1/3] Fix missing error output in root project with project references --- src/after-compile.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/after-compile.ts b/src/after-compile.ts index fc88386ba..de5f39801 100644 --- a/src/after-compile.ts +++ b/src/after-compile.ts @@ -1,4 +1,5 @@ import * as path from 'path'; +import * as ts from 'typescript'; import * as webpack from 'webpack'; import * as constants from './constants'; @@ -12,6 +13,7 @@ import { } from './interfaces'; import { collectAllDependants, + ensureProgram, formatErrors, isUsingProjectReferences } from './utils'; @@ -174,8 +176,6 @@ function provideErrorsToWebpack( ) { const { compiler, - program, - languageService, files, loaderOptions, compilerOptions, @@ -187,13 +187,14 @@ function provideErrorsToWebpack( ? constants.dtsTsTsxJsJsxRegex : constants.dtsTsTsxRegex; + // I’m pretty sure this will never be undefined here + const program = ensureProgram(instance); for (const filePath of filesToCheckForErrors.keys()) { if (filePath.match(filePathRegex) === null) { continue; } - const sourceFile = - program === undefined ? undefined : program.getSourceFile(filePath); + const sourceFile = program && program.getSourceFile(filePath); // If the source file is undefined, that probably means it’s actually part of an unbuilt project reference, // which will have already produced a more useful error than the one we would get by proceeding here. @@ -203,16 +204,13 @@ function provideErrorsToWebpack( continue; } - const errors = - program === undefined - ? [ - ...languageService!.getSyntacticDiagnostics(filePath), - ...languageService!.getSemanticDiagnostics(filePath) - ] - : [ - ...program.getSyntacticDiagnostics(sourceFile), - ...program.getSemanticDiagnostics(sourceFile) - ]; + const errors: ts.Diagnostic[] = []; + if (program && sourceFile) { + errors.push( + ...program!.getSyntacticDiagnostics(sourceFile), + ...program!.getSemanticDiagnostics(sourceFile) + ); + } if (errors.length > 0) { const fileWithError = files.get(filePath) || otherFiles.get(filePath); filesWithErrors.set(filePath, fileWithError!); From ccf83e072b549bbc9f43f084f6d93be745ae3476 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Sat, 18 May 2019 15:29:27 -0700 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 955c31481..31948bcb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v6.0.1 * [Fix issue with `resolveTypeReferenceDirective` causing errors like `Cannot find name 'it'` with Jest](https://github.com/TypeStrong/ts-loader/pull/936) (#934) (#919) - thanks @andrewbranch! +* [Fix TypeScript diagnostics not being printed to console when using project references](https://github.com/TypeStrong/ts-loader/pull/937) (#932) - thanks @andrewbranch! ## v6.0.0 From 69dc5e2acfff9fad2664c8ec2ea341c794cd157e Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Sat, 18 May 2019 16:00:25 -0700 Subject: [PATCH 3/3] =?UTF-8?q?Dedupe=20=E2=80=9Coutput=20file=20has=20not?= =?UTF-8?q?=20been=20built=20from=20source=20file=E2=80=9D=20diagnostic=20?= =?UTF-8?q?message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/after-compile.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/after-compile.ts b/src/after-compile.ts index de5f39801..8918d4fd5 100644 --- a/src/after-compile.ts +++ b/src/after-compile.ts @@ -208,7 +208,11 @@ function provideErrorsToWebpack( if (program && sourceFile) { errors.push( ...program!.getSyntacticDiagnostics(sourceFile), - ...program!.getSemanticDiagnostics(sourceFile) + ...program! + .getSemanticDiagnostics(sourceFile) + // Output file has not been built from source file - this message is redundant with + // program.getOptionsDiagnostics() separately added in instances.ts + .filter(({ code }) => code !== 6305) ); } if (errors.length > 0) {