Skip to content

Replace afterCompile to stop webpack 5 warning#1200

Merged
johnnyreilly merged 5 commits intoTypeStrong:masterfrom
appzuka:master
Oct 20, 2020
Merged

Replace afterCompile to stop webpack 5 warning#1200
johnnyreilly merged 5 commits intoTypeStrong:masterfrom
appzuka:master

Conversation

@appzuka
Copy link
Copy Markdown
Member

@appzuka appzuka commented Oct 19, 2020

This fixes the deprecation warning in webpack 5 as discussed in issue #1196. Writing assets such as declarations is moved to the afterProcessAssets hook of the compilation from the afterCompile hook of the compiler.

As the afterProcessAssets hook does not exist in webpack 4 to make ts-loader work for both webpack 4 and 5 it is necessary to execute different code depending on whether afterProcessAssets exists. This means that the new code is not tested at all by either the execution or comparison tests, which feels wrong. I'm not sure how to fix this until tests using webpack 5 are introduced, which feels like a major task.

I have tested this build with a small project using webpack 4 and webpack 5. If I introduce a deliberate error into the webpack 5 branch of the new code all the tests still pass although building the project with webpack 5 fails.

Comment thread src/instances.ts Outdated
Comment thread src/instances.ts Outdated
Comment thread src/instances.ts
// afterProcessAssets does not exist in webpack4
loader._compilation.hooks.afterProcessAssets.tap(
'ts-loader',
(_: any) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you happen to know what the type is here? Not that we're using it but I'm curious

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a list of the assets:

https://github.com/webpack/webpack/blob/9342540a1f11b84cd693b186ec4e72d37f5a0aeb/lib/Compilation.js#L299

If I include the parameter there is a warning that it is unused, so I decided to include it as _:any

@johnnyreilly
Copy link
Copy Markdown
Member

This looks great @appzuka ! Thanks for your work 🌻❤️

Would you like to update the package.json and the CHANGELOG.md and we can ship a release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants