Repository: webpack/webpack (JavaScript)

Issue:
ProfilingPlugin with HtmlWebpackPlugin produce an error
# Bug report

**What is the current behavior?**

```
C:\project\node_modules\html-webpack-plugin\lib\cached-child-compiler.js:296
      throw new Error(
            ^

[  Error: The child compiler is not done compiling. Please access the result after the compiler 'make' phase has started or after the compilation is done.

  - cached-child-compiler.js:296 PersistentChildCompilerSingletonPlugin.getLatestResult
    [project]/[html-webpack-plugin]/lib/cached-child-compiler.js:296:13

  - cached-child-compiler.js:92 CachedChildCompilation.getCompilationResult
    [project]/[html-webpack-plugin]/lib/cached-child-compiler.js:92:51

  - cached-child-compiler.js:104 CachedChildCompilation.getCompilationEntryResult   
    [project]/[html-webpack-plugin]/lib/cached-child-compiler.js:104:31

  - index.js:237 
    [project]/[html-webpack-plugin]/index.js:237:35

  - Compilation.js:507 fn
    [project]/[webpack]/lib/Compilation.js:507:9

  - ProfilingPlugin.js:406 id
    [project]/[webpack]/lib/debug/ProfilingPlugin.js:406:5

  - ProfilingPlugin.js:406 id
    [project]/[webpack]/lib/debug/ProfilingPlugin.js:406:5

  - ProfilingPlugin.js:412 
    [project]/[webpack]/lib/debug/ProfilingPlugin.js:412:6
```

Relevant `html-webpack-plugin` code can be seen here:

https://github.com/jantimon/html-webpack-plugin/blob/0a6568d587a82d88fd3a0617234ca98d26a1e0a6/lib/cached-child-compiler.js#L294

**If the current behavior is a bug, please provide the steps to reproduce.**

It is a Quasar project building for production in PWA mode. Two compilations in one go: one for SW and one for main codebase. After enabling caching (`options.cache = { type: 'filesystem' }`) this error triggers on SW compilation. Turning off caching makes the error trigger during main codebase compilation.

Plugin is added using:

```js
chain.plugin('profiling-webpack-plugin')
  .use(new webpack.debug.ProfilingPlugin())
```

The "stage" when the error happens is: `sealing asset processing HtmlWebpackPlugin`

**What is the expected behavior?**

This may be an HtmlWebpackPlugin issue, but it does seem like ProfilingPlugin is requesting data too early (time-wise, the build process crashes with that error about halfway through).

**Other relevant information:**
webpack version:  5.68.0
Node.js version: v16.13.1
Operating System: Windows 10
Additional tools: NA



Hints:
bug - will have fix in a few min
@thexeos attached PR you will find a fix which you can try patching in until PR is complete.

Patch:
diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js
--- a/lib/debug/ProfilingPlugin.js
+++ b/lib/debug/ProfilingPlugin.js
@@ -343,7 +343,8 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
 };
 
 const makeInterceptorFor = (instance, tracer) => hookName => ({
-	register: ({ name, type, context, fn }) => {
+	register: tapInfo => {
+		const { name, type, fn } = tapInfo;
 		const newFn =
 			// Don't tap our own hooks to ensure stream can close cleanly
 			name === pluginName
@@ -354,9 +355,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
 						fn
 				  });
 		return {
-			name,
-			type,
-			context,
+			...tapInfo,
 			fn: newFn
 		};
 	}


Test patch:
diff --git a/test/ProfilingPlugin.test.js b/test/ProfilingPlugin.test.js
--- a/test/ProfilingPlugin.test.js
+++ b/test/ProfilingPlugin.test.js
@@ -13,6 +13,7 @@ describe("Profiling Plugin", function () {
 		const webpack = require("../");
 		const outputPath = path.join(__dirname, "js/profilingPath");
 		const finalPath = path.join(outputPath, "events.json");
+		let counter = 0;
 		rimraf(outputPath, () => {
 			const startTime = process.hrtime();
 			const compiler = webpack({
@@ -24,7 +25,27 @@ describe("Profiling Plugin", function () {
 				plugins: [
 					new webpack.debug.ProfilingPlugin({
 						outputPath: finalPath
-					})
+					}),
+					{
+						apply(compiler) {
+							const hook = compiler.hooks.make;
+							[
+								{ stage: 0, order: 1 },
+								{ stage: 1, order: 2 },
+								{ stage: -1, order: 0 }
+							].forEach(({ stage, order }) => {
+								hook.tap(
+									{
+										name: "RespectStageCheckerPlugin",
+										stage
+									},
+									() => {
+										expect(counter++).toBe(order);
+									}
+								);
+							});
+						}
+					}
 				],
 				experiments: {
 					backCompat: false