Skip to content

Commit 11e811a

Browse files
author
Micha Reiser
committed
Emit errors of multiple typescript instances correctly
If multipe typescript instances are used, then the errors of only one instance are outputted to the console. The error has been caused by the removeTSLoaderErrors function that removes the errors for all instances, therefore, only the errors of the last instance are left in the errors array. This is fixed by including the instance name in the loaderSource and refining removeTSLoaderErrors to only remove errors of the same instance. Fixes TypeStrong#268
1 parent aff605e commit 11e811a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function hasOwnProperty(obj, property) {
2727

2828
interface LoaderOptions {
2929
silent: boolean;
30+
/** instance name that is unique for this typescript and webpack instance */
3031
instance: string;
32+
/** The name of the typescript instance, not unique per webpack instance */
33+
instanceName: string;
3134
compiler: string;
3235
configFileName: string;
3336
transpileOnly: boolean;
@@ -52,6 +55,7 @@ interface TSInstance {
5255
languageService?: typescript.LanguageService;
5356
version?: number;
5457
dependencyGraph: any;
58+
name: string;
5559
}
5660

5761
interface TSInstances {
@@ -110,14 +114,14 @@ function formatErrors(diagnostics: typescript.Diagnostic[], instance: TSInstance
110114
message: `${'('.white}${(lineChar.line+1).toString().cyan},${(lineChar.character+1).toString().cyan}): ${messageText.red}`,
111115
rawMessage: messageText,
112116
location: {line: lineChar.line+1, character: lineChar.character+1},
113-
loaderSource: 'ts-loader'
117+
loaderSource: `ts-loader@${instance.name}`
114118
};
115119
}
116120
else {
117121
return {
118122
message:`${messageText.red}`,
119123
rawMessage: messageText,
120-
loaderSource: 'ts-loader'
124+
loaderSource: `ts-loader@${instance.name}`
121125
};
122126
}
123127
})
@@ -195,7 +199,8 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
195199
files,
196200
languageService: null,
197201
version: 0,
198-
dependencyGraph: {}
202+
dependencyGraph: {},
203+
name: loaderOptions.instanceName
199204
};
200205

201206
var compilerOptions: typescript.CompilerOptions = {
@@ -295,7 +300,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
295300
loader._module.errors,
296301
formatErrors(diagnostics, instance, {file: configFilePath || 'tsconfig.json'}));
297302

298-
return { instance: instances[loaderOptions.instance] = { compiler, compilerOptions, loaderOptions, files, dependencyGraph: {} }};
303+
return { instance: instances[loaderOptions.instance] = { compiler, compilerOptions, loaderOptions, files, dependencyGraph: {}, name: loaderOptions.instanceName }};
299304
}
300305

301306
// Load initial files (core lib files, any files specified in tsconfig.json)
@@ -426,7 +431,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
426431
function removeTSLoaderErrors(errors: WebpackError[]) {
427432
let index = -1, length = errors.length;
428433
while (++index < length) {
429-
if (errors[index].loaderSource == 'ts-loader') {
434+
if (errors[index].loaderSource == `ts-loader@${instance.name}`) {
430435
errors.splice(index--, 1);
431436
length--;
432437
}
@@ -550,6 +555,8 @@ function loader(contents) {
550555
if (webpackIndex == -1) {
551556
webpackIndex = webpackInstances.push(this._compiler)-1;
552557
}
558+
559+
options.instanceName = options.instance;
553560
options.instance = webpackIndex + '_' + options.instance;
554561

555562
var { instance, error } = ensureTypeScriptInstance(options, this);

0 commit comments

Comments
 (0)