From 456400ed50694cde5deee3b8050607814a2c57cd Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Tue, 13 Aug 2024 14:49:16 +0300 Subject: [PATCH] fix: handle an empty array for the ignored option --- lib/watchpack.js | 3 +++ test/Watchpack.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/watchpack.js b/lib/watchpack.js index ddc9138..1a7b331 100644 --- a/lib/watchpack.js +++ b/lib/watchpack.js @@ -31,6 +31,9 @@ const stringToRegexp = ignored => { const ignoredToFunction = ignored => { if (Array.isArray(ignored)) { + if (ignored.length === 0) { + return () => false; + } const regexp = new RegExp(ignored.map(i => stringToRegexp(i)).join("|")); return x => regexp.test(x.replace(/\\/g, "/")); } else if (typeof ignored === "string") { diff --git a/test/Watchpack.js b/test/Watchpack.js index 4559c62..f791df5 100644 --- a/test/Watchpack.js +++ b/test/Watchpack.js @@ -269,6 +269,28 @@ describe("Watchpack", function() { }); }); + it("should watch a file in a directory when ignore is empty array", function(done) { + var w = new Watchpack({ + aggregateTimeout: 300, + ignored: [] + }); + var changeEvents = 0; + w.on("change", function(file) { + file.should.be.eql(path.join(fixtures, "a")); + changeEvents++; + }); + w.on("aggregated", function(changes) { + Array.from(changes).should.be.eql([path.join(fixtures, "a")]); + changeEvents.should.be.greaterThan(0); + w.close(); + done(); + }); + w.watch([path.join(fixtures, "a")], []); + testHelper.tick(function() { + testHelper.file("a"); + }); + }); + it("should watch a file then a directory", function(done) { var w = new Watchpack({ aggregateTimeout: 1000