From 0b4a86dd50695f8295d13d25ba3c2b5628dd233c Mon Sep 17 00:00:00 2001 From: Nick Excell Date: Tue, 20 Oct 2020 06:14:18 +0100 Subject: [PATCH] Replace afterCompile to stop webpack 5 warning (#1200) * Replace afterCompile to stop webpack 5 warning * Update src/instances.ts * Update src/instances.ts * Updated Changelog and bump version Co-authored-by: John Reilly --- CHANGELOG.md | 3 +++ package.json | 2 +- src/instances.ts | 48 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e9697fa..d803cb168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v8.0.6 +* [Fixed further deprecation warning on webpack@5](https://github.com/TypeStrong/ts-loader/issues/1196) - thanks @appzuka + ## v8.0.5 * [Fixed deprecation warnings on webpack@5](https://github.com/TypeStrong/ts-loader/issues/1194) - thanks @sanex3339 diff --git a/package.json b/package.json index bceb649e4..96cfa1195 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-loader", - "version": "8.0.5", + "version": "8.0.6", "description": "TypeScript loader for webpack", "main": "index.js", "types": "dist", diff --git a/src/instances.ts b/src/instances.ts index 95ac680e2..769e023f3 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -341,10 +341,26 @@ export function initializeInstance( instance.transformers = getCustomTransformers(program); // Setup watch run for solution building if (instance.solutionBuilderHost) { - loader._compiler.hooks.afterCompile.tapAsync( - 'ts-loader', - makeAfterCompile(instance, instance.configFilePath) - ); + if (loader._compilation.hooks.afterProcessAssets) { + // afterProcessAssets does not exist in webpack4 + loader._compilation.hooks.afterProcessAssets.tap( + 'ts-loader', + (_: any) => { + makeAfterCompile(instance, instance.configFilePath)( + loader._compilation, + () => { + return null; + } + ); + } + ); + } else { + // adding assets in afterCompile is deprecated in webpack 5 + loader._compiler.hooks.afterCompile.tapAsync( + 'ts-loader', + makeAfterCompile(instance, instance.configFilePath) + ); + } loader._compiler.hooks.watchRun.tapAsync( 'ts-loader', makeWatchRun(instance, loader) @@ -391,11 +407,27 @@ export function initializeInstance( instance.languageService!.getProgram() ); } + if (loader._compilation.hooks.afterProcessAssets) { + // afterProcessAssets does not exist in webpack4 + loader._compilation.hooks.afterProcessAssets.tap( + 'ts-loader', + (_: any) => { + makeAfterCompile(instance, instance.configFilePath)( + loader._compilation, + () => { + return null; + } + ); + } + ); + } else { + // adding assets in afterCompile is deprecated in webpack 5 + loader._compiler.hooks.afterCompile.tapAsync( + 'ts-loader', + makeAfterCompile(instance, instance.configFilePath) + ); + } - loader._compiler.hooks.afterCompile.tapAsync( - 'ts-loader', - makeAfterCompile(instance, instance.configFilePath) - ); loader._compiler.hooks.watchRun.tapAsync( 'ts-loader', makeWatchRun(instance, loader)