Skip to content

Commit 20af0c7

Browse files
fix: compatibility with Node.js 17
1 parent fcab69b commit 20af0c7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
strategy:
5757
matrix:
5858
os: [ubuntu-latest, windows-latest, macos-latest]
59-
node-version: [12.x, 14.x, 16.x]
59+
node-version: [12.x, 14.x, 16.x, 17.x]
6060
webpack-version: [latest]
6161

6262
runs-on: ${{ matrix.os }}

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from "path";
2-
import crypto from "crypto";
32

43
import { validate } from "schema-utils";
54
import pLimit from "p-limit";
@@ -476,14 +475,20 @@ class CopyPlugin {
476475
const buffer = result.source.buffer();
477476

478477
if (transform.cache) {
478+
// TODO: remove in the next major release
479+
const hasher =
480+
compiler.webpack &&
481+
compiler.webpack.util &&
482+
compiler.webpack.util.createHash
483+
? compiler.webpack.util.createHash("xxhash64")
484+
: // eslint-disable-next-line global-require
485+
require("crypto").createHash("md4");
486+
479487
const defaultCacheKeys = {
480488
version,
481489
sourceFilename,
482490
transform: transform.transformer,
483-
contentHash: crypto
484-
.createHash("md4")
485-
.update(buffer)
486-
.digest("hex"),
491+
contentHash: hasher.update(buffer).digest("hex"),
487492
index,
488493
};
489494
const cacheKeys = `transform|${serialize(

0 commit comments

Comments
 (0)