Skip to content

Commit

Permalink
Merge pull request #16950 from ahabhgk/fix-debug-hash
Browse files Browse the repository at this point in the history
fix: failed with debug hash
  • Loading branch information
TheLarkInn committed May 8, 2023
2 parents 282ed8d + b938ba2 commit 7fc5abf
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/util/createHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ class DebugHash extends Hash {
*/
update(data, inputEncoding) {
if (typeof data !== "string") data = data.toString("utf-8");
if (data.startsWith("debug-digest-")) {
data = Buffer.from(data.slice("debug-digest-".length), "hex").toString();
const prefix = Buffer.from("@webpack-debug-digest@").toString("hex");
if (data.startsWith(prefix)) {
data = Buffer.from(data.slice(prefix.length), "hex").toString();
}
this.string += `[${data}](${new Error().stack.split("\n", 3)[2]})\n`;
return this;
Expand All @@ -120,7 +121,7 @@ class DebugHash extends Hash {
* @returns {string|Buffer} digest
*/
digest(encoding) {
return "debug-digest-" + Buffer.from(this.string).toString("hex");
return Buffer.from("@webpack-debug-digest@" + this.string).toString("hex");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = module.id;
8 changes: 8 additions & 0 deletions test/configCases/custom-hash-function/debug-hash/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
it("debug hash should works", function () {
var ids = [];
for(var i = 1; i <= 15; i++) {
var id = require("./files/file" + i + ".js");
expect(ids.indexOf(id)).toBe(-1);
ids.push(id);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import("../../../../").Configuration[]} */
module.exports = [
{
output: {
hashFunction: "debug"
}
}
];

0 comments on commit 7fc5abf

Please sign in to comment.