fix resolve-rc loading options twice - fixes #1329

This commit is contained in:
Luke Scott 2015-04-23 12:14:02 -07:00
parent 74f04ed6a1
commit 03dbaa3e0e
2 changed files with 23 additions and 2 deletions

View File

@ -17,9 +17,17 @@ function exists(filename) {
export default function (loc, opts = {}) {
var rel = ".babelrc";
if (!opts.babelrc) {
opts.babelrc = [];
}
function find(start, rel) {
var file = path.join(start, rel);
if (opts.babelrc.indexOf(file) >= 0) {
return;
}
if (exists(file)) {
var content = fs.readFileSync(file, "utf8");
var json;
@ -31,10 +39,18 @@ export default function (loc, opts = {}) {
throw err;
}
opts.babelrc.push(file);
if (json.breakConfig) return;
merge(opts, json, function(a, b) {
if (Array.isArray(a)) {
return a.concat(b);
var c = a.slice(0);
for (var v of b) {
if (a.indexOf(v) < 0) {
c.push(v);
}
}
return c;
}
});
}
@ -45,7 +61,7 @@ export default function (loc, opts = {}) {
}
}
if (opts.breakConfig !== true) {
if (opts.babelrc.indexOf(loc) < 0 && opts.breakConfig !== true) {
find(loc, rel);
}

View File

@ -206,6 +206,11 @@
"default": false,
"hidden": true,
"description": "stop trying to load .babelrc files"
},
"babelrc": {
"hidden": true,
"description": "do not load the same .babelrc file twice"
}
}