Skip to content

Commit

Permalink
fix: compatibility with Node.js@18 (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Dec 26, 2023
1 parent 4a10f07 commit c2e40dc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Author Tobias Koppers @sokra
*/

import crypto from "crypto";
import path from "path";

import webpack, {
Expand All @@ -15,6 +14,20 @@ import serialize from "serialize-javascript";

import schema from "./options.json";

const internalCreateHash = (algorithm) => {
try {
// eslint-disable-next-line global-require import/no-unresolved
const createHash = require("webpack/lib/util/createHash");

return createHash(algorithm);
} catch (err) {
// Ignore
}

return require("crypto").createHash(algorithm);
};


const { RawSource } =
// eslint-disable-next-line global-require
webpack.sources || require("webpack-sources");
Expand Down Expand Up @@ -229,7 +242,7 @@ class CompressionPlugin {
originalAlgorithm: this.options.algorithm,
compressionOptions: this.options.compressionOptions,
name,
contentHash: crypto.createHash("md4").update(input).digest("hex"),
contentHash: internalCreateHash("md4").update(input).digest("hex"),
};
} else {
cacheData.name = serialize({
Expand Down

0 comments on commit c2e40dc

Please sign in to comment.