Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"webpack": ">=2"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.5",
"@babel/core": "7.0.0-beta.5",
"@babel/preset-env": "7.0.0-beta.5",
"@babel/cli": "^7.0.0-beta.40",
"@babel/core": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"ava": "0.25.0",
"babel-eslint": "^8.0.0",
"babel-plugin-istanbul": "^4.0.0",
Expand Down
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,21 @@ module.exports = function(source, inputSourceMap) {
const loaderOptions = loaderUtils.getOptions(this) || {};
const fileSystem = this.fs ? this.fs : fs;
let babelrcPath = null;
if (loaderOptions.babelrc !== false) {
babelrcPath =
typeof loaderOptions.babelrc === "string" &&
exists(fileSystem, loaderOptions.babelrc)
? loaderOptions.babelrc
: resolveRc(fileSystem, path.dirname(filename));

// Deprecation handling
if (typeof loaderOptions.babelrc === "string") {
console.warn(
"The option `babelrc` should not be set to a string anymore in the babel-loader config. " +
"Please update your configuration and set `babelrc` to true or false.\n" +
"If you want to specify a specific babel config file to inherit config from " +
"please use the `extends` option.\nFor more information about this options see " +
"https://babeljs.io/docs/core-packages/#options",
);
}
if (loaderOptions.babelrc !== false && loaderOptions.extends) {
babelrcPath = exists(fileSystem, loaderOptions.extends)
? loaderOptions.extends
: resolveRc(fileSystem, path.dirname(filename));
}

if (babelrcPath) {
Expand All @@ -134,6 +143,7 @@ module.exports = function(source, inputSourceMap) {
"@babel/loader": pkg.version,
"@babel/core": babel.version,
babelrc: babelrcPath ? read(fileSystem, babelrcPath) : null,
options: loaderOptions,
env:
loaderOptions.forceEnv ||
process.env.BABEL_ENV ||
Expand Down
33 changes: 25 additions & 8 deletions test/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ test.cb("should output files to cache directory", t => {
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.deepEqual(stats.compilation.errors, []);
t.deepEqual(stats.compilation.warnings, []);

fs.readdir(t.context.cacheDirectory, (err, files) => {
t.is(err, null);
Expand Down Expand Up @@ -100,8 +102,10 @@ test.cb.serial(
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.deepEqual(stats.compilation.errors, []);
t.deepEqual(stats.compilation.warnings, []);

fs.readdir(defaultCacheDir, (err, files) => {
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
Expand Down Expand Up @@ -132,8 +136,10 @@ test.cb.serial(
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.deepEqual(stats.compilation.errors, []);
t.deepEqual(stats.compilation.warnings, []);

fs.readdir(defaultCacheDir, (err, files) => {
files = files.filter(file => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file));
Expand Down Expand Up @@ -169,8 +175,10 @@ test.cb.skip("should read from cache directory if cached file exists", t => {

// @TODO Find a way to know if the file as correctly read without relying on
// Istanbul for coverage.
webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.deepEqual(stats.compilation.errors, []);
t.deepEqual(stats.compilation.warnings, []);

webpack(config, err => {
t.is(err, null);
Expand Down Expand Up @@ -203,8 +211,10 @@ test.cb("should have one file per module", t => {
},
});

webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.deepEqual(stats.compilation.errors, []);
t.deepEqual(stats.compilation.warnings, []);

fs.readdir(t.context.cacheDirectory, (err, files) => {
t.is(err, null);
Expand Down Expand Up @@ -258,8 +268,10 @@ test.cb("should generate a new file if the identifier changes", t => {
let counter = configs.length;

configs.forEach(config => {
webpack(config, err => {
webpack(config, (err, stats) => {
t.is(err, null);
t.deepEqual(stats.compilation.errors, []);
t.deepEqual(stats.compilation.warnings, []);
counter -= 1;

if (!counter) {
Expand Down Expand Up @@ -288,7 +300,8 @@ test.cb("should allow to specify the .babelrc file", t => {
exclude: /node_modules/,
query: {
cacheDirectory: t.context.cacheDirectory,
babelrc: path.join(__dirname, "fixtures/babelrc"),
extends: path.join(__dirname, "fixtures/babelrc"),
babelrc: false,
Copy link
Member Author

@danez danez Feb 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the breaking change basically, I couldn't figure out why we used a string value for babelrc in the first place.

presets: ["@babel/preset-env"],
},
},
Expand Down Expand Up @@ -316,8 +329,12 @@ test.cb("should allow to specify the .babelrc file", t => {
}),
];

webpack(config, err => {
webpack(config, (err, multiStats) => {
t.is(err, null);
t.deepEqual(multiStats.stats[0].compilation.errors, []);
t.deepEqual(multiStats.stats[0].compilation.warnings, []);
t.deepEqual(multiStats.stats[1].compilation.errors, []);
t.deepEqual(multiStats.stats[1].compilation.warnings, []);

fs.readdir(t.context.cacheDirectory, (err, files) => {
t.is(err, null);
Expand Down
Loading