Skip to content

Commit

Permalink
Merge branch 'babel:main' into inputSourceMap
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 authored Apr 14, 2022
2 parents 9b6f5b5 + f7982c1 commit 8fd049e
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 209 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ For this, you can either use a combination of `test` and `not`, or [pass a funct
{
test: /\.m?js$/,
exclude: {
test: /node_modules/, // Exclude libraries in node_modules ...
and: [/node_modules/], // Exclude libraries in node_modules ...
not: [
// Except for a few of them that needs to be transpiled because they use modern syntax
/unfetch/,
Expand Down Expand Up @@ -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`:

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-loader",
"version": "8.2.2",
"version": "8.2.4",
"description": "babel module loader for webpack",
"files": [
"lib"
Expand All @@ -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"
},
Expand Down Expand Up @@ -44,7 +44,7 @@
"react-intl-webpack-plugin": "^0.3.0",
"rimraf": "^3.0.0",
"semver": "7.3.2",
"webpack": "^5.4.0"
"webpack": "^5.34.0"
},
"scripts": {
"clean": "rimraf lib/",
Expand Down
10 changes: 9 additions & 1 deletion src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -63,7 +71,7 @@ const write = async function (filename, compress, result) {
* @return {String}
*/
const filename = function (source, identifier, options) {
const hash = crypto.createHash("md4");
const hash = crypto.createHash(hashType);

const contents = JSON.stringify({ source, options, identifier });

Expand Down
19 changes: 14 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -209,10 +209,19 @@ async function loader(source, inputSourceMap, overrides) {
result = await transform(source, options);
}

// TODO: Babel should really provide the full list of config files that
// were used so that this can also handle files loaded with 'extends'.
if (typeof config.babelrc === "string") {
this.addDependency(config.babelrc);
// Availabe since Babel 7.12
// https://github.com/babel/babel/pull/11907
if (config.files) {
config.files.forEach(configFile => this.addDependency(configFile));
} else {
// .babelrc.json
if (typeof config.babelrc === "string") {
this.addDependency(config.babelrc);
}
// babel.config.js
if (config.config) {
this.addDependency(config.config);
}
}

if (result) {
Expand Down
12 changes: 6 additions & 6 deletions test/sourcemaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ test.cb("should output webpack's sourcemap properly when set 'inline'", t => {

if (isWebpack5) {
t.is(
mapObj.sources[0],
mapObj.sources[3],
"webpack://babel-loader/./test/fixtures/basic.js",
);

// Ensure that the map contains the original code, not the compiled src.
t.falsy(mapObj.sourcesContent[2].includes("__esModule"));
t.falsy(mapObj.sourcesContent[3].includes("__esModule"));
} else {
t.is(mapObj.sources[1], "webpack:///./test/fixtures/basic.js");

Expand Down Expand Up @@ -232,13 +232,13 @@ test.cb("should disable sourcemap output with 'sourceMaps:false'", t => {

if (isWebpack5) {
t.is(
mapObj.sources[0],
mapObj.sources[3],
"webpack://babel-loader/./test/fixtures/basic.js",
);

// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[2].includes("__esModule"));
t.truthy(mapObj.sourcesContent[3].includes("__esModule"));
} else {
t.is(mapObj.sources[1], "webpack:///./test/fixtures/basic.js");

Expand Down Expand Up @@ -295,13 +295,13 @@ test.cb("should disable sourcemap output with 'sourceMap:false'", t => {

if (isWebpack5) {
t.is(
mapObj.sources[0],
mapObj.sources[3],
"webpack://babel-loader/./test/fixtures/basic.js",
);

// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[2].includes("__esModule"));
t.truthy(mapObj.sourcesContent[3].includes("__esModule"));
} else {
t.is(mapObj.sources[1], "webpack:///./test/fixtures/basic.js");

Expand Down
Loading

0 comments on commit 8fd049e

Please sign in to comment.