Skip to content

Commit

Permalink
fix: compatibility with Node.js@18 (#608)
Browse files Browse the repository at this point in the history
* fix: compatibility with Node.js@18

* Reset the webpack version in package.json.

* fix: use internalCreateHash instead of crypto.createHash directly.
  • Loading branch information
Fitz6 authored Jul 23, 2024
1 parent f9c543a commit c47d231
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable
no-param-reassign
*/
import crypto from 'crypto';
import path from 'path';

import { SourceMapConsumer } from 'source-map';
Expand All @@ -16,6 +15,19 @@ import schema from './options.json';
import TaskRunner from './TaskRunner';

const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/;
const internalCreateHash = (algorithm) => {
try {
// eslint-disable-next-line global-require
const createHash = require('webpack/lib/util/createHash');

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

// eslint-disable-next-line global-require
return require('crypto').createHash(algorithm);
};

class TerserPlugin {
constructor(options = {}) {
Expand Down Expand Up @@ -236,8 +248,7 @@ class TerserPlugin {
// eslint-disable-next-line global-require
'terser-webpack-plugin': require('../package.json').version,
'terser-webpack-plugin-options': this.options,
hash: crypto
.createHash('md4')
hash: internalCreateHash('md4')
.update(input)
.digest('hex'),
};
Expand Down

0 comments on commit c47d231

Please sign in to comment.