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

feat: use webpack hashFunction rather than hard-code MD4 #213

Merged

Conversation

JoshMcCullough
Copy link
Contributor

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Previously, this plugin had hard-coded MD4 as the hash algorithm to use. But Webpack provides a hashFunction in its config which should be used instead. The reason for this is that MD4 is not supported on all systems. For instance, a FIPS-compliant system cannot use MD4 or MD5 because they are not secure algorithms. So any use of this plugin on such a system will fail the build.

Now, if a users' webpack config has set a specific hashFunction to use, this plugin will respect that. If not, it will fall back to the MD4 algorithm by default.

Breaking Changes

This PR is backwards compatible.

Additional Info

Note: I added a compiler constructor parameter to the WebpackXCache classes so the hashFunction can be extracted from the Webpack config. I was not sure if the existing compilation or options parameters might also include the Webpack config. If either does, we can remove the new parameter.

@jsf-clabot
Copy link

jsf-clabot commented Jan 29, 2020

CLA assistant check
All committers have signed the CLA.

src/hash-helper.js Outdated Show resolved Hide resolved
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

One note, tests need to be rewritten too

@alexander-akait
Copy link
Member

Anyway thanks for the PR, good job!

@alexander-akait
Copy link
Member

Please accept CLA too

@codecov
Copy link

codecov bot commented Jan 29, 2020

Codecov Report

Merging #213 into master will increase coverage by 0.29%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #213      +/-   ##
==========================================
+ Coverage   95.67%   95.96%   +0.29%     
==========================================
  Files           7        7              
  Lines         393      397       +4     
  Branches      152      155       +3     
==========================================
+ Hits          376      381       +5     
+ Misses         17       16       -1
Impacted Files Coverage Δ
src/Webpack5Cache.js 88.88% <100%> (+0.42%) ⬆️
src/Webpack4Cache.js 100% <100%> (ø) ⬆️
src/index.js 99.04% <100%> (+0.01%) ⬆️
src/TaskRunner.js 100% <0%> (+1.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b45dbe...49d0251. Read the comment docs.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Hm, i forgot what webpack has utils for creating hashes https://github.com/webpack/webpack/blob/master/lib/index.js#L154, i think will be great to use it instead own implementation

@JoshMcCullough
Copy link
Contributor Author

Okay, using that now instead.

@@ -10,6 +9,7 @@ import {
javascript,
version as webpackVersion,
} from 'webpack';
import createHash from 'webpack/lib/util/createHash';
Copy link
Member

Choose a reason for hiding this comment

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

Please use import { utils: { createHash } } from 'webpack', no need hardcore path to exported utils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't destructure in an import statement.

Copy link
Member

Choose a reason for hiding this comment

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

Just use webpack.utils.createHash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't work.

Copy link
Member

Choose a reason for hiding this comment

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

Strange, I will look at this in near future, anyway thanks for the PR

@alexander-akait
Copy link
Member

Let's merge, I will refactor before release 👍 Thanks!

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.

None yet

3 participants