Skip to content

Commit

Permalink
fix(@ngtools/webpack): show TS error message when there is no file
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Aug 9, 2017
1 parent 349aae8 commit c475cf4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
15 changes: 9 additions & 6 deletions packages/@ngtools/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,16 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
let message = '';

diagnostics.forEach(diagnostic => {
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);

const fileName = diagnostic.file.fileName;
const {line, character} = position;

const messageText = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
message += `${fileName} (${line + 1},${character + 1}): ${messageText}\n`;

if (diagnostic.file) {
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const fileName = diagnostic.file.fileName;
const {line, character} = position;
message += `${fileName} (${line + 1},${character + 1}): ${messageText}\n`;
} else {
message += `${messageText}\n`;
}
});
throw new Error(message);
}
Expand Down
38 changes: 27 additions & 11 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ export class AotPlugin implements Tapable {
const configResult = ts.readConfigFile(this._tsConfigPath, ts.sys.readFile);
if (configResult.error) {
const diagnostic = configResult.error;
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
throw new Error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`);

if (diagnostic.file) {
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
throw new Error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`);
} else {
throw new Error(message);
}
}

const tsConfigJson = configResult.config;
Expand Down Expand Up @@ -422,14 +427,20 @@ export class AotPlugin implements Tapable {

if (diagnostics.length > 0) {
diagnostics.forEach(diagnostic => {
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const messageText = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
let message;

const sourceText = diagnostic.file.getFullText();
let {line, character, fileName} = this._translateSourceMap(sourceText,
diagnostic.file.fileName, position);
if (diagnostic.file) {
const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);

const messageText = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
const message = `${fileName} (${line + 1},${character + 1}): ${messageText}`;
const sourceText = diagnostic.file.getFullText();
let {line, character, fileName} = this._translateSourceMap(sourceText,
diagnostic.file.fileName, position);

message = `${fileName} (${line + 1},${character + 1}): ${messageText}`;
} else {
message = messageText;
}

switch (diagnostic.category) {
case ts.DiagnosticCategory.Error:
Expand Down Expand Up @@ -501,10 +512,15 @@ export class AotPlugin implements Tapable {
if (diagnostics.length > 0) {
const message = diagnostics
.map(diagnostic => {
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(
diagnostic.start);
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`;

if (diagnostic.file) {
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(
diagnostic.start);
return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`;
} else {
return message;
}
})
.join('\n');

Expand Down

0 comments on commit c475cf4

Please sign in to comment.