Skip to content

Commit

Permalink
Merge pull request #937 from andrewbranch/bug/project-refs-errors
Browse files Browse the repository at this point in the history
Fix missing error output in root project with project references
  • Loading branch information
andrewbranch committed May 19, 2019
2 parents 0399864 + 69dc5e2 commit 18151d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
30 changes: 16 additions & 14 deletions 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';
Expand All @@ -12,6 +13,7 @@ import {
} from './interfaces';
import {
collectAllDependants,
ensureProgram,
formatErrors,
isUsingProjectReferences
} from './utils';
Expand Down Expand Up @@ -174,8 +176,6 @@ function provideErrorsToWebpack(
) {
const {
compiler,
program,
languageService,
files,
loaderOptions,
compilerOptions,
Expand All @@ -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.
Expand All @@ -203,16 +204,17 @@ 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)
// 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) {
const fileWithError = files.get(filePath) || otherFiles.get(filePath);
filesWithErrors.set(filePath, fileWithError!);
Expand Down

0 comments on commit 18151d5

Please sign in to comment.