Skip to content

Commit 18151d5

Browse files
authored
Merge pull request #937 from andrewbranch/bug/project-refs-errors
Fix missing error output in root project with project references
2 parents 0399864 + 69dc5e2 commit 18151d5

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v6.0.1
44

55
* [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!
6+
* [Fix TypeScript diagnostics not being printed to console when using project references](https://github.com/TypeStrong/ts-loader/pull/937) (#932) - thanks @andrewbranch!
67

78
## v6.0.0
89

src/after-compile.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'path';
2+
import * as ts from 'typescript';
23
import * as webpack from 'webpack';
34

45
import * as constants from './constants';
@@ -12,6 +13,7 @@ import {
1213
} from './interfaces';
1314
import {
1415
collectAllDependants,
16+
ensureProgram,
1517
formatErrors,
1618
isUsingProjectReferences
1719
} from './utils';
@@ -174,8 +176,6 @@ function provideErrorsToWebpack(
174176
) {
175177
const {
176178
compiler,
177-
program,
178-
languageService,
179179
files,
180180
loaderOptions,
181181
compilerOptions,
@@ -187,13 +187,14 @@ function provideErrorsToWebpack(
187187
? constants.dtsTsTsxJsJsxRegex
188188
: constants.dtsTsTsxRegex;
189189

190+
// I’m pretty sure this will never be undefined here
191+
const program = ensureProgram(instance);
190192
for (const filePath of filesToCheckForErrors.keys()) {
191193
if (filePath.match(filePathRegex) === null) {
192194
continue;
193195
}
194196

195-
const sourceFile =
196-
program === undefined ? undefined : program.getSourceFile(filePath);
197+
const sourceFile = program && program.getSourceFile(filePath);
197198

198199
// If the source file is undefined, that probably means it’s actually part of an unbuilt project reference,
199200
// which will have already produced a more useful error than the one we would get by proceeding here.
@@ -203,16 +204,17 @@ function provideErrorsToWebpack(
203204
continue;
204205
}
205206

206-
const errors =
207-
program === undefined
208-
? [
209-
...languageService!.getSyntacticDiagnostics(filePath),
210-
...languageService!.getSemanticDiagnostics(filePath)
211-
]
212-
: [
213-
...program.getSyntacticDiagnostics(sourceFile),
214-
...program.getSemanticDiagnostics(sourceFile)
215-
];
207+
const errors: ts.Diagnostic[] = [];
208+
if (program && sourceFile) {
209+
errors.push(
210+
...program!.getSyntacticDiagnostics(sourceFile),
211+
...program!
212+
.getSemanticDiagnostics(sourceFile)
213+
// Output file has not been built from source file - this message is redundant with
214+
// program.getOptionsDiagnostics() separately added in instances.ts
215+
.filter(({ code }) => code !== 6305)
216+
);
217+
}
216218
if (errors.length > 0) {
217219
const fileWithError = files.get(filePath) || otherFiles.get(filePath);
218220
filesWithErrors.set(filePath, fileWithError!);

0 commit comments

Comments
 (0)