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

Remove usage of removed API in rebuildModule #11433

Merged
merged 8 commits into from Jan 15, 2021

Conversation

samcooke98
Copy link
Contributor

This PR is to address the issue raised here: #11269 - The removeReasonsOfDependencyBlock method was calling the removed dependency.module

What kind of change does this PR introduce?

Bugfix.

Did you add tests for your changes?

Yes. I'm not very happy with the method of the testing here, but I'm not familiar enough with webpack to do it in a better way.

The test works by replacing the contents of the other-file, and change the exports. The test then asserts that the exports have changed.

One idea I had was to use a loader to change the other-file.. However I struggled with writing a custom loader.

Very open to suggestions and improvements here.

Does this PR introduce a breaking change?

I don't believe so.

What needs to be documented once your changes are merged?

None, I believe?

@jsf-clabot
Copy link

jsf-clabot commented Sep 6, 2020

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

Comment on lines 23 to 27
const module = Array.from(compilation.modules).find(matcher);
/** @type {any} */
const inputFileSystem = compilation.inputFileSystem;
const cachedFileInput = inputFileSystem._readFileBackend._data.get(src);
cachedFileInput.result = `module.exports = { foo: { foo: 'bar' }, doThings: () => { }}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a fan of the way in which this has to break type-safety, and dive into internal\private methods to achieve this test.

But by doing this I can test that the module has been rebuilt.

As mentioned in the description, one idea was to change the contents of the file in a second run through the use of a loader, but I'm not super comfortable with my ability to write a custom loader.

if (originalModule) {
this.moduleGraph.removeConnection(dep);

if (this.chunkGraph) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed that chunkGraph is only created in the seal phase, and that finishModules is called before that, hence the if.

Not sure if this is entirely right however.

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@webpack-bot
Copy link
Contributor

It looks like this Pull Request doesn't include enough test cases (based on Code Coverage analysis of the PR diff).

A PR need to be covered by tests if you add a new feature (we want to make sure that your feature is working) or if you fix a bug (we want to make sure that we don't run into a regression in future).

@samcooke98 Please check if this is appliable to your PR and if you can add more test cases.

Read the test readme for details how to write test cases.

@samcooke98
Copy link
Contributor Author

Sorry for the ping @sokra , but do you mind please giving me some pointers on how to improve the tests here, and get the coverage up?

@sokra sokra merged commit fa5cc45 into webpack:master Jan 15, 2021
@sokra
Copy link
Member

sokra commented Jan 15, 2021

Thanks

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

Successfully merging this pull request may close these issues.

None yet

4 participants