Skip to content

Commit 84a3b2c

Browse files
authored
Merge pull request webpack#6146 from EugeneHlushko/feature-xxhashjs
Feature: Non-crypto hashing algorithm and opt-in through config
2 parents 20678c6 + 62395cf commit 84a3b2c

21 files changed

+54
-4
lines changed

lib/util/createHash.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ class BulkUpdateDecorator {
3333
if(this.buffer.length > 0) {
3434
this.hash.update(this.buffer);
3535
}
36-
return this.hash.digest(encoding);
36+
var digestResult = this.hash.digest(encoding);
37+
return typeof digestResult === "string" ? digestResult : digestResult.toString();
3738
}
3839
}
3940

4041
module.exports = algorithm => {
42+
if(typeof algorithm === "function") {
43+
return new BulkUpdateDecorator(new algorithm());
44+
}
4145
switch(algorithm) {
4246
// TODO add non-cryptographic algorithm here
4347
default: return new BulkUpdateDecorator(require("crypto").createHash(algorithm));

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"vm-browserify": "~0.0.0",
6666
"webpack-cli": "^1.5.2",
6767
"webpack-dev-middleware": "^1.9.0",
68-
"worker-loader": "^0.8.0"
68+
"worker-loader": "^0.8.0",
69+
"xxhashjs": "^0.2.1"
6970
},
7071
"engines": {
7172
"node": ">=6.11.5"

schemas/WebpackOptions.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,15 @@
403403
},
404404
"hashFunction": {
405405
"description": "Algorithm used for generation the hash (see node.js crypto package)",
406-
"minLength": 1,
407-
"type": "string"
406+
"anyOf": [
407+
{
408+
"type": "string",
409+
"minLength": 1
410+
},
411+
{
412+
"instanceof": "Function"
413+
}
414+
]
408415
},
409416
"hashSalt": {
410417
"description": "Any string which is added to the hash to salt it",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = module.id;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
it("should have unique ids", function () {
2+
var ids = [];
3+
for(var i = 1; i <= 15; i++) {
4+
var id = require("./files/file" + i + ".js");
5+
ids.indexOf(id).should.be.eql(-1);
6+
ids.push(id);
7+
}
8+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = [{
2+
output: {
3+
hashFunction: require("xxhashjs").h32
4+
}
5+
}];

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,10 @@ csso@~2.3.1:
16301630
clap "^1.0.9"
16311631
source-map "^0.5.3"
16321632

1633+
cuint@latest:
1634+
version "0.2.2"
1635+
resolved "https://registry.yarnpkg.com/cuint/-/cuint-0.2.2.tgz#408086d409550c2631155619e9fa7bcadc3b991b"
1636+
16331637
cvss@^1.0.0:
16341638
version "1.0.2"
16351639
resolved "https://registry.yarnpkg.com/cvss/-/cvss-1.0.2.tgz#df67e92bf12a796f49e928799c8db3ba74b9fcd6"
@@ -6036,6 +6040,12 @@ xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.0, xtend@~4.0.1:
60366040
version "4.0.1"
60376041
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
60386042

6043+
xxhashjs@^0.2.1:
6044+
version "0.2.1"
6045+
resolved "https://registry.yarnpkg.com/xxhashjs/-/xxhashjs-0.2.1.tgz#9bbe9be896142976dfa34c061b2d068c43d30de0"
6046+
dependencies:
6047+
cuint latest
6048+
60396049
y18n@^3.2.1:
60406050
version "3.2.1"
60416051
resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41"

0 commit comments

Comments
 (0)