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

Lines changed: 54 additions & 4 deletions

File tree

‎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;

0 commit comments

Comments
 (0)