Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace afterCompile to stop webpack 5 warning #1200

Merged
merged 5 commits into from
Oct 20, 2020
Merged

Replace afterCompile to stop webpack 5 warning #1200

merged 5 commits into from
Oct 20, 2020

Conversation

appzuka
Copy link
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.

src/instances.ts Outdated Show resolved Hide resolved
src/instances.ts Outdated Show resolved Hide resolved
// afterProcessAssets does not exist in webpack4
loader._compilation.hooks.afterProcessAssets.tap(
'ts-loader',
(_: any) => {
Copy link
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
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
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