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

RHCLOUD-24738: Fix bug in ValidateCompilationPlugin #213

Merged

Conversation

vojtechszocs
Copy link
Contributor

@vojtechszocs vojtechszocs commented Mar 22, 2023

Fixes RHCLOUD-24738

Some webpack plugins like html-webpack-plugin use compilation.createChildCompiler API to run a "child" compilation inside the actual "root" compilation.

This function allows you to run another instance of webpack inside of webpack however as a child with different settings and configurations (if desired) applied. It copies all hooks, plugins from parent (or top level compiler) and creates a child Compilation

Since our ValidateCompilationPlugin uses afterCompile hook which is automatically copied to all child compilers, using e.g. html-webpack-plugin (*) caused this hook to be executed within html-webpack-plugin's child compilation which doesn't include any of the expected root compilation's actual chunks.

(*) see here for details

The fix is to use an appropriate webpack compiler hook that isn't automatically copied to all child compilers.

The list of compiler hooks that are not automatically copied to all child compilers is in webpack/lib/Compiler.js

for (const name in this.hooks) {
  if (
    ![
      "make",
      "compile",
      "emit",
      "afterEmit",
      "invalid",
      "done",
      "thisCompilation"
    ].includes(name)
  ) {
    if (childCompiler.hooks[name]) {
      childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
    }
  }
}

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 22, 2023
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2023

@vojtechszocs: This pull request references RHCLOUD-24738 which is a valid jira issue.

In response to this:

Some webpack plugins like html-webpack-plugin use compilation.createChildCompiler API to run a "child" compilation inside the actual "root" compilation.

This function allows you to run another instance of webpack inside of webpack however as a child with different settings and configurations (if desired) applied. It copies all hooks, plugins from parent (or top level compiler) and creates a child Compilation

Since our ValidateCompilationPlugin uses afterCompile hook which is automatically copied to all child compilers, using e.g. html-webpack-plugin (*) caused this hook to be executed within html-webpack-plugin's child compilation which doesn't include any of the expected root compilation's actual chunks.

(*) see here for details

The fix is to use an appropriate webpack compiler hook that isn't automatically copied to all child compilers.

The list of compiler hooks that are not automatically copied to all child compilers is in webpack/lib/Compiler.js

for (const name in this.hooks) {
 if (
   ![
     "make",
     "compile",
     "emit",
     "afterEmit",
     "invalid",
     "done",
     "thisCompilation"
   ].includes(name)
 ) {
   if (childCompiler.hooks[name]) {
     childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
   }
 }
}

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vojtechszocs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 22, 2023
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2023

@vojtechszocs: This pull request references RHCLOUD-24738 which is a valid jira issue.

In response to this:

Fixes https://issues.redhat.com/browse/RHCLOUD-24738

Some webpack plugins like html-webpack-plugin use compilation.createChildCompiler API to run a "child" compilation inside the actual "root" compilation.

This function allows you to run another instance of webpack inside of webpack however as a child with different settings and configurations (if desired) applied. It copies all hooks, plugins from parent (or top level compiler) and creates a child Compilation

Since our ValidateCompilationPlugin uses afterCompile hook which is automatically copied to all child compilers, using e.g. html-webpack-plugin (*) caused this hook to be executed within html-webpack-plugin's child compilation which doesn't include any of the expected root compilation's actual chunks.

(*) see here for details

The fix is to use an appropriate webpack compiler hook that isn't automatically copied to all child compilers.

The list of compiler hooks that are not automatically copied to all child compilers is in webpack/lib/Compiler.js

for (const name in this.hooks) {
 if (
   ![
     "make",
     "compile",
     "emit",
     "afterEmit",
     "invalid",
     "done",
     "thisCompilation"
   ].includes(name)
 ) {
   if (childCompiler.hooks[name]) {
     childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
   }
 }
}

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

1 similar comment
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2023

@vojtechszocs: This pull request references RHCLOUD-24738 which is a valid jira issue.

In response to this:

Fixes https://issues.redhat.com/browse/RHCLOUD-24738

Some webpack plugins like html-webpack-plugin use compilation.createChildCompiler API to run a "child" compilation inside the actual "root" compilation.

This function allows you to run another instance of webpack inside of webpack however as a child with different settings and configurations (if desired) applied. It copies all hooks, plugins from parent (or top level compiler) and creates a child Compilation

Since our ValidateCompilationPlugin uses afterCompile hook which is automatically copied to all child compilers, using e.g. html-webpack-plugin (*) caused this hook to be executed within html-webpack-plugin's child compilation which doesn't include any of the expected root compilation's actual chunks.

(*) see here for details

The fix is to use an appropriate webpack compiler hook that isn't automatically copied to all child compilers.

The list of compiler hooks that are not automatically copied to all child compilers is in webpack/lib/Compiler.js

for (const name in this.hooks) {
 if (
   ![
     "make",
     "compile",
     "emit",
     "afterEmit",
     "invalid",
     "done",
     "thisCompilation"
   ].includes(name)
 ) {
   if (childCompiler.hooks[name]) {
     childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
   }
 }
}

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2023

@vojtechszocs: This pull request references RHCLOUD-24738 which is a valid jira issue.

In response to this:

Fixes RHCLOUD-24738

Some webpack plugins like html-webpack-plugin use compilation.createChildCompiler API to run a "child" compilation inside the actual "root" compilation.

This function allows you to run another instance of webpack inside of webpack however as a child with different settings and configurations (if desired) applied. It copies all hooks, plugins from parent (or top level compiler) and creates a child Compilation

Since our ValidateCompilationPlugin uses afterCompile hook which is automatically copied to all child compilers, using e.g. html-webpack-plugin (*) caused this hook to be executed within html-webpack-plugin's child compilation which doesn't include any of the expected root compilation's actual chunks.

(*) see here for details

The fix is to use an appropriate webpack compiler hook that isn't automatically copied to all child compilers.

The list of compiler hooks that are not automatically copied to all child compilers is in webpack/lib/Compiler.js

for (const name in this.hooks) {
 if (
   ![
     "make",
     "compile",
     "emit",
     "afterEmit",
     "invalid",
     "done",
     "thisCompilation"
   ].includes(name)
 ) {
   if (childCompiler.hooks[name]) {
     childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
   }
 }
}

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@codecov-commenter
Copy link

Codecov Report

Patch and project coverage have no change.

Comparison is base (c79a9a7) 39.69% compared to head (a7f259c) 39.69%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #213   +/-   ##
=======================================
  Coverage   39.69%   39.69%           
=======================================
  Files          68       68           
  Lines        1665     1665           
  Branches      356      356           
=======================================
  Hits          661      661           
  Misses        969      969           
  Partials       35       35           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@florkbr
Copy link
Contributor

florkbr commented Mar 29, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 29, 2023

@vojtechszocs: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit bd36f8a into openshift:main Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants