Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
69 changes: 43 additions & 26 deletions test/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const babelLoader = path.join(__dirname, "../lib");
const globalConfig = {
entry: path.join(__dirname, "fixtures/basic.js"),
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: babelLoader,
Expand Down Expand Up @@ -53,12 +53,12 @@ test.cb("should output files to cache directory", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.js$/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["@babel/preset-env"],
},
Expand All @@ -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 All @@ -86,12 +88,12 @@ test.cb.serial(
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: true,
presets: ["@babel/preset-env"],
},
Expand All @@ -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 All @@ -122,7 +126,7 @@ test.cb.serial(
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: `${babelLoader}?cacheDirectory=true&presets[]=@babel/preset-env`,
Expand All @@ -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 All @@ -153,12 +159,12 @@ test.cb.skip("should read from cache directory if cached file exists", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["@babel/preset-env"],
},
Expand All @@ -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 All @@ -189,12 +197,12 @@ test.cb("should have one file per module", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["@babel/preset-env"],
},
Expand All @@ -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 All @@ -221,12 +231,12 @@ test.cb("should generate a new file if the identifier changes", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
cacheIdentifier: "a",
presets: ["@babel/preset-env"],
Expand All @@ -240,12 +250,12 @@ test.cb("should generate a new file if the identifier changes", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
cacheIdentifier: "b",
presets: ["@babel/preset-env"],
Expand All @@ -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 All @@ -281,14 +293,15 @@ test.cb("should allow to specify the .babelrc file", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
babelrc: path.join(__dirname, "fixtures/babelrc"),
extends: path.join(__dirname, "fixtures/babelrc"),
babelrc: false,
presets: ["@babel/preset-env"],
},
},
Expand All @@ -301,12 +314,12 @@ test.cb("should allow to specify the .babelrc file", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
query: {
options: {
cacheDirectory: t.context.cacheDirectory,
presets: ["@babel/preset-env"],
},
Expand All @@ -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
22 changes: 11 additions & 11 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const babelLoader = path.join(__dirname, "../lib");
const globalConfig = {
entry: path.join(__dirname, "fixtures/basic.js"),
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
presets: ["@babel/preset-env"],
},
exclude: /node_modules/,
Expand Down Expand Up @@ -84,11 +84,11 @@ test.cb("should use correct env", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
forceEnv: "testenv",
env: {
testenv: {
Expand Down Expand Up @@ -126,11 +126,11 @@ test.serial.cb("should not polute BABEL_ENV after using forceEnv", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
forceEnv: "testenv",
env: {
testenv: {
Expand Down Expand Up @@ -161,11 +161,11 @@ test.serial.cb(
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
forceEnv: "testenv",
env: {
testenv: {
Expand Down Expand Up @@ -197,11 +197,11 @@ test.serial.cb("should not change BABEL_ENV when using forceEnv", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
forceEnv: "testenv",
env: {
testenv: {
Expand Down Expand Up @@ -245,7 +245,7 @@ test.cb("should not throw without config", t => {
path: t.context.directory,
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
Expand Down
8 changes: 4 additions & 4 deletions test/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const globalConfig = {
},
plugins: [new ReactIntlPlugin()],
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
metadataSubscribers: [ReactIntlPlugin.metadataContextFunctionName],
plugins: [["react-intl", { enforceDescriptions: false }]],
presets: [],
Expand Down Expand Up @@ -114,11 +114,11 @@ test.cb("should pass metadata code snippet ( cache version )", t => {
filename: "[id].metadata.js",
},
module: {
loaders: [
rules: [
{
test: /\.jsx?/,
loader: babelLoader,
query: {
options: {
metadataSubscribers: [ReactIntlPlugin.metadataContextFunctionName],
plugins: [["react-intl", { enforceDescriptions: false }]],
cacheDirectory: cacheDir,
Expand Down
Loading