Fix a regression from adding negation support in #5625. (#5641)

This commit is contained in:
Logan Smyth
2017-04-17 18:13:37 -07:00
committed by GitHub
parent 25ae8c8554
commit d1d812edff
2 changed files with 45 additions and 19 deletions

View File

@@ -74,35 +74,42 @@ class ConfigChainBuilder {
else res.push(pattern);
});
// Lazy-init so we don't initialize this for files that have no glob patterns.
if (strings.length > 0 && !this.possibleDirs) {
this.possibleDirs = [];
if (res.some((re) => re.test(this.filename))) return true;
if (fns.some((fn) => fn(this.filename))) return true;
if (this.filename) {
this.possibleDirs.push(this.filename);
if (strings.length > 0) {
// Lazy-init so we don't initialize this for files that have no glob patterns.
if (!this.possibleDirs) {
this.possibleDirs = [];
let current = this.filename;
while (true) {
const previous = current;
current = path.dirname(current);
if (previous === current) break;
if (this.filename) {
this.possibleDirs.push(this.filename);
this.possibleDirs.push(current);
let current = this.filename;
while (true) {
const previous = current;
current = path.dirname(current);
if (previous === current) break;
this.possibleDirs.push(current);
}
}
}
}
return res.some((re) => re.test(this.filename)) ||
fns.some((fn) => fn(this.filename)) ||
(strings.length > 0 && this.possibleDirs.some(micromatch.filter(strings.map((pattern) => {
const absolutePatterns = strings.map((pattern) => {
// Preserve the "!" prefix so that micromatch can use it for negation.
const negate = pattern[0] === "!";
if (negate) pattern = pattern.slice(1);
return (negate ? "!" : "") + path.resolve(dirname, pattern);
}, {
nocase: true,
}))));
});
if (micromatch(this.possibleDirs, absolutePatterns, { nocase: true }).length > 0) {
return true;
}
}
return false;
}
findConfigs(loc: string) {

View File

@@ -31,7 +31,26 @@ describe("buildConfigChain", function () {
process.env.NODE_ENV = oldNodeEnv;
});
// TODO: Tests for ignore and only
describe("ignore/only", () => {
// TODO: More tests for ignore and only
it("should ignore files that match", () => {
const chain = buildConfigChain({
filename: fixture("nonexistant-fake", "src.js"),
babelrc: false,
ignore: [
fixture("nonexistant-fake", "src.js"),
// We had a regression where multiple ignore patterns broke things, so
// we keep some extra random items in here.
fixture("nonexistant-fake", "other.js"),
fixture("nonexistant-fake", "misc.js"),
],
});
assert.equal(chain, null);
});
});
it("dir1", function () {
const chain = buildConfigChain({