diff --git a/README.md b/README.md index 5d4a756a..f63ea7e0 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,6 @@ This loader also supports the following loader-specific option: * `metadataSubscribers`: Default `[]`. Takes an array of context function names. E.g. if you passed ['myMetadataPlugin'], you'd assign a subscriber function to `context.myMetadataPlugin` within your webpack plugin's hooks & that function will be called with `metadata`. -* `hashType`: Default `md4`. The hash digest function to use. If you hit an `ERR_OSSL_EVP_UNSUPPORTED` error in your application with Node.js 17, it’s likely that your attempting to use an algorithm which is no longer allowed by default with OpenSSL 3.0. You can specify `md5` here to fix the issue. - ## Troubleshooting ### babel-loader is slow! diff --git a/src/cache.js b/src/cache.js index c1db2164..35e78819 100644 --- a/src/cache.js +++ b/src/cache.js @@ -62,8 +62,15 @@ const write = async function (filename, compress, result) { * * @return {String} */ -const filename = function (source, identifier, options, hashType) { - const hash = crypto.createHash(hashType || "md4"); +const filename = function (source, identifier, options) { + // md4 hashing is not supported starting with node v17.0.0 + const majorNodeVersion = parseInt(process.versions.node.split(".")[0], 10); + let hashType = "md4"; + if (majorNodeVersion >= 17) { + hashType = "md5"; + } + + const hash = crypto.createHash(hashType); const contents = JSON.stringify({ source, options, identifier }); @@ -85,11 +92,9 @@ const handleCache = async function (directory, params) { cacheIdentifier, cacheDirectory, cacheCompression, - hashType, } = params; - const name = filename(source, cacheIdentifier, options, hashType); - const file = path.join(directory, name); + const file = path.join(directory, filename(source, cacheIdentifier, options)); try { // No errors mean that the file was previously cached @@ -137,7 +142,6 @@ const handleCache = async function (directory, params) { * @param {String} params.cacheDirectory Directory to store cached files * @param {String} params.cacheIdentifier Unique identifier to bust cache * @param {Boolean} params.cacheCompression Whether compressing cached files - * @param {Boolean} params.hashType Hash digest to use for file names * @param {String} params.source Original contents of the file to be cached * @param {Object} params.options Options to be given to the transform fn * @@ -147,7 +151,6 @@ const handleCache = async function (directory, params) { * cacheDirectory: '.tmp/cache', * cacheIdentifier: 'babel-loader-cachefile', * cacheCompression: false, - * hashType: 'md4', * source: *source code from file*, * options: { * experimental: true, diff --git a/src/index.js b/src/index.js index c5894a56..07eec2a1 100644 --- a/src/index.js +++ b/src/index.js @@ -150,7 +150,6 @@ async function loader(source, inputSourceMap, overrides) { delete programmaticOptions.cacheIdentifier; delete programmaticOptions.cacheCompression; delete programmaticOptions.metadataSubscribers; - delete programmaticOptions.hashType; if (!babel.loadPartialConfig) { throw new Error( @@ -194,7 +193,6 @@ async function loader(source, inputSourceMap, overrides) { }), cacheCompression = true, metadataSubscribers = [], - hashType = null, } = loaderOptions; let result; @@ -206,7 +204,6 @@ async function loader(source, inputSourceMap, overrides) { cacheDirectory, cacheIdentifier, cacheCompression, - hashType, }); } else { result = await transform(source, options); diff --git a/src/schema.json b/src/schema.json index f845d367..7f933f7c 100644 --- a/src/schema.json +++ b/src/schema.json @@ -23,10 +23,6 @@ "type": "string", "default": null }, - "hashType": { - "type": "string", - "default": null - } }, "additionalProperties": true }