From 20af0c7f1b06a7e597e6b498dbc2b432a4a6d0de Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 11 Nov 2021 22:18:00 +0300 Subject: [PATCH] fix: compatibility with Node.js 17 --- .github/workflows/nodejs.yml | 2 +- src/index.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 74eb872..365c1f0 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -56,7 +56,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 17.x] webpack-version: [latest] runs-on: ${{ matrix.os }} diff --git a/src/index.js b/src/index.js index 248477e..78e9aa9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,4 @@ import path from "path"; -import crypto from "crypto"; import { validate } from "schema-utils"; import pLimit from "p-limit"; @@ -476,14 +475,20 @@ class CopyPlugin { const buffer = result.source.buffer(); if (transform.cache) { + // TODO: remove in the next major release + const hasher = + compiler.webpack && + compiler.webpack.util && + compiler.webpack.util.createHash + ? compiler.webpack.util.createHash("xxhash64") + : // eslint-disable-next-line global-require + require("crypto").createHash("md4"); + const defaultCacheKeys = { version, sourceFilename, transform: transform.transformer, - contentHash: crypto - .createHash("md4") - .update(buffer) - .digest("hex"), + contentHash: hasher.update(buffer).digest("hex"), index, }; const cacheKeys = `transform|${serialize(