Skip to content

Commit 91206c4

Browse files
authored
Re-fix Webpack 5 watch not failing on error (#1254)
* Add afterDeclarations to getCustomTransformers in README.md * Emit d.ts file in subsequent runs in watch mode * Update package.json and changelog.md * Re-fixed missing errors in watch mode * Correct merge error
1 parent b8a70f9 commit 91206c4

File tree

4 files changed

+27
-43
lines changed

4 files changed

+27
-43
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v8.0.16
4+
* [Re-Fixed missing errors in watch mode in webpack5](https://github.com/TypeStrong/ts-loader/issues/1204) - thanks @appzuka
5+
36
## v8.0.15
47
* [Update definition files in watch mode in webpack@5](https://github.com/TypeStrong/ts-loader/pull/1249) - thanks @appzuka,@JonWallsten,@alexander-akait
58
* [Add afterDeclarations to getCustomTransformers in README.md](https://github.com/TypeStrong/ts-loader/pull/1248) - thanks @appzuka

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.0.15",
3+
"version": "8.0.16",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/after-compile.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import {
2929
*/
3030
export function makeAfterCompile(
3131
instance: TSInstance,
32-
addAssets: boolean,
33-
provideErrors: boolean,
3432
configFilePath: string | undefined
3533
) {
3634
let getCompilerOptionDiagnostics = true;
@@ -47,22 +45,18 @@ export function makeAfterCompile(
4745
}
4846

4947
if (instance.loaderOptions.transpileOnly) {
50-
if (addAssets) {
51-
provideAssetsFromSolutionBuilderHost(instance, compilation);
52-
}
48+
provideAssetsFromSolutionBuilderHost(instance, compilation);
5349
callback();
5450
return;
5551
}
5652
removeCompilationTSLoaderErrors(compilation, instance.loaderOptions);
5753

58-
if (provideErrors) {
59-
provideCompilerOptionDiagnosticErrorsToWebpack(
60-
getCompilerOptionDiagnostics,
61-
compilation,
62-
instance,
63-
configFilePath
64-
);
65-
}
54+
provideCompilerOptionDiagnosticErrorsToWebpack(
55+
getCompilerOptionDiagnostics,
56+
compilation,
57+
instance,
58+
configFilePath
59+
);
6660
getCompilerOptionDiagnostics = false;
6761

6862
const modules = determineModules(compilation, instance);
@@ -74,25 +68,21 @@ export function makeAfterCompile(
7468
checkAllFilesForErrors = false;
7569

7670
const filesWithErrors: TSFiles = new Map();
77-
if (provideErrors) {
78-
provideErrorsToWebpack(
79-
filesToCheckForErrors,
80-
filesWithErrors,
81-
compilation,
82-
modules,
83-
instance
84-
);
85-
provideSolutionErrorsToWebpack(compilation, modules, instance);
86-
}
87-
if (addAssets) {
88-
provideDeclarationFilesToWebpack(
89-
filesToCheckForErrors,
90-
instance,
91-
compilation
92-
);
93-
provideTsBuildInfoFilesToWebpack(instance, compilation);
94-
provideAssetsFromSolutionBuilderHost(instance, compilation);
95-
}
71+
provideErrorsToWebpack(
72+
filesToCheckForErrors,
73+
filesWithErrors,
74+
compilation,
75+
modules,
76+
instance
77+
);
78+
provideSolutionErrorsToWebpack(compilation, modules, instance);
79+
provideDeclarationFilesToWebpack(
80+
filesToCheckForErrors,
81+
instance,
82+
compilation
83+
);
84+
provideTsBuildInfoFilesToWebpack(instance, compilation);
85+
provideAssetsFromSolutionBuilderHost(instance, compilation);
9686

9787
instance.filesWithErrors = filesWithErrors;
9888
instance.modifiedFiles = undefined;

src/instances.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,26 +323,17 @@ const addAssetHooks = !!webpack.version!.match(/^4.*/)
323323
// add makeAfterCompile with addAssets = true to emit assets and report errors
324324
loader._compiler.hooks.afterCompile.tapAsync(
325325
'ts-loader',
326-
makeAfterCompile(instance, true, true, instance.configFilePath)
326+
makeAfterCompile(instance, instance.configFilePath)
327327
);
328328
}
329329
: (loader: webpack.loader.LoaderContext, instance: TSInstance) => {
330330
// We must be running under webpack 5+
331331

332-
// Add makeAfterCompile with addAssets = false to suppress emitting assets
333-
// during the afterCompile stage. Errors will be still be reported to webpack
334-
loader._compiler.hooks.afterCompile.tapAsync(
335-
'ts-loader',
336-
makeAfterCompile(instance, false, true, instance.configFilePath)
337-
);
338-
339332
// makeAfterCompile is a closure. It returns a function which closes over the variable checkAllFilesForErrors
340333
// We need to get the function once and then reuse it, otherwise it will be recreated each time
341334
// and all files will always be checked.
342335
const cachedMakeAfterCompile = makeAfterCompile(
343336
instance,
344-
true,
345-
false,
346337
instance.configFilePath
347338
);
348339

0 commit comments

Comments
 (0)