Skip to content

Commit

Permalink
fix: compatibility with Node.js 17
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Nov 11, 2021
1 parent fcab69b commit 20af0c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "path";
import crypto from "crypto";

import { validate } from "schema-utils";
import pLimit from "p-limit";
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 20af0c7

Please sign in to comment.