diff --git a/lib/watchpack.js b/lib/watchpack.js index 9f1dca1..a0816b5 100644 --- a/lib/watchpack.js +++ b/lib/watchpack.js @@ -24,18 +24,20 @@ function addWatchersToSet(watchers, set) { } } -const stringToRegexp = ignored => { - const source = globToRegExp(ignored, { globstar: true, extended: true }) - .source; +const stringOrRegexpToRegexp = ignored => { + if (ignored instanceof RegExp) { + return ignored.source; + } + const { source } = globToRegExp(ignored, { globstar: true, extended: true }); const matchingStart = source.slice(0, source.length - 1) + "(?:$|\\/)"; return matchingStart; }; const ignoredToRegexp = ignored => { if (Array.isArray(ignored)) { - return new RegExp(ignored.map(i => stringToRegexp(i)).join("|")); + return new RegExp(ignored.map(i => stringOrRegexpToRegexp(i)).join("|")); } else if (typeof ignored === "string") { - return new RegExp(stringToRegexp(ignored)); + return new RegExp(stringOrRegexpToRegexp(ignored)); } else if (ignored instanceof RegExp) { return ignored; } else if (ignored) { diff --git a/test/Watchpack.js b/test/Watchpack.js index ade8021..d30f743 100644 --- a/test/Watchpack.js +++ b/test/Watchpack.js @@ -118,6 +118,32 @@ describe("Watchpack", function() { }); }); + it("should not watch a single ignored file (array with regexp and glob)", function(done) { + var w = new Watchpack({ + aggregateTimeout: 300, + ignored: [/\/a$/, "**/b"] + }); + var changeEvents = 0; + var aggregatedEvents = 0; + w.on("change", () => { + changeEvents++; + }); + w.on("aggregated", () => { + aggregatedEvents++; + }); + w.watch([path.join(fixtures, "a")], []); + testHelper.tick(() => { + testHelper.file("a"); + testHelper.tick(1000, () => { + changeEvents.should.be.eql(0); + aggregatedEvents.should.be.eql(0); + testHelper.getNumberOfWatchers().should.be.eql(0); + w.close(); + done(); + }); + }); + }); + it("should watch multiple files", function(done) { var w = new Watchpack({ aggregateTimeout: 1000