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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions 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

Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
48 changes: 40 additions & 8 deletions src/instances.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
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

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)
Expand Down