diff --git a/README.md b/README.md index f63ea7e0..33ebb7e6 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ You will need to exclude them form `babel-loader`. ### Top level function (IIFE) is still arrow (on Webpack 5) -That function is injected by Webpack itself _after_ running `babel-loader`. By default Webpack asumes that your target environment supports some ES2015 features, but you can overwrite this behavior using the `output.environment` Webpack option ([documentation]((https://webpack.js.org/configuration/output/#outputenvironment)). +That function is injected by Webpack itself _after_ running `babel-loader`. By default Webpack asumes that your target environment supports some ES2015 features, but you can overwrite this behavior using the `output.environment` Webpack option ([documentation](https://webpack.js.org/configuration/output/#outputenvironment)). To avoid the top-level arrow function, you can use `output.environment.arrowFunction`: diff --git a/package.json b/package.json index 322338ee..d69155a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-loader", - "version": "8.2.3", + "version": "8.2.4", "description": "babel module loader for webpack", "files": [ "lib" @@ -11,7 +11,7 @@ }, "dependencies": { "find-cache-dir": "^3.3.1", - "loader-utils": "^1.4.0", + "loader-utils": "^2.0.0", "make-dir": "^3.1.0", "schema-utils": "^2.6.5" }, diff --git a/src/cache.js b/src/cache.js index 35e78819..29482924 100644 --- a/src/cache.js +++ b/src/cache.js @@ -19,6 +19,14 @@ const transform = require("./transform"); // Lazily instantiated when needed let defaultCacheDirectory = null; +let hashType = "md4"; +// use md5 hashing if md4 is not available +try { + crypto.createHash(hashType); +} catch (err) { + hashType = "md5"; +} + const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); const gunzip = promisify(zlib.gunzip); @@ -63,13 +71,6 @@ const write = async function (filename, compress, result) { * @return {String} */ 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 }); diff --git a/src/index.js b/src/index.js index 07eec2a1..45f518da 100644 --- a/src/index.js +++ b/src/index.js @@ -55,7 +55,7 @@ function makeLoader(callback) { async function loader(source, inputSourceMap, overrides) { const filename = this.resourcePath; - let loaderOptions = loaderUtils.getOptions(this) || {}; + let loaderOptions = loaderUtils.getOptions(this); validateOptions(schema, loaderOptions, { name: "Babel loader", diff --git a/yarn.lock b/yarn.lock index b10e011e..2ca58f1d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2143,7 +2143,7 @@ __metadata: find-cache-dir: ^3.3.1 husky: ^4.3.0 lint-staged: ^10.5.1 - loader-utils: ^1.4.0 + loader-utils: ^2.0.0 make-dir: ^3.1.0 nyc: ^15.1.0 pnp-webpack-plugin: ^1.6.4 @@ -5070,17 +5070,6 @@ fsevents@~2.1.2: languageName: node linkType: hard -"json5@npm:^1.0.1": - version: 1.0.1 - resolution: "json5@npm:1.0.1" - dependencies: - minimist: ^1.2.0 - bin: - json5: lib/cli.js - checksum: df41624f9f40bfacc546f779eef6d161a3312fbb6ec1dbd69f8c4388e9807af653b753371ab19b6d2bab22af2ca7dde62fe03c791596acf76915e1fc4ee6fd88 - languageName: node - linkType: hard - "json5@npm:^2.1.2": version: 2.1.3 resolution: "json5@npm:2.1.3" @@ -5234,14 +5223,14 @@ fsevents@~2.1.2: languageName: node linkType: hard -"loader-utils@npm:^1.4.0": - version: 1.4.0 - resolution: "loader-utils@npm:1.4.0" +"loader-utils@npm:^2.0.0": + version: 2.0.2 + resolution: "loader-utils@npm:2.0.2" dependencies: big.js: ^5.2.2 emojis-list: ^3.0.0 - json5: ^1.0.1 - checksum: 9fd690e57ad78d32ff2942383b4a7a175eba575280ba5aca3b4d03183fec34aa0db314f49bd3301adf7e60b02471644161bf53149e8f2d18fd6a52627e95a927 + json5: ^2.1.2 + checksum: c1df0ff0fb52787011b8d19b1e38ee1b67e31d8b301703e6f791256377ce71a6180f40c34a597dfafe76fe621139fea0ee4669344d98b939d9042ea1c32f1ba9 languageName: node linkType: hard