From ece1b3d3808cb0a0824b8d146d097980475ee83e Mon Sep 17 00:00:00 2001 From: DarshanaChandel Date: Tue, 20 Oct 2026 23:29:49 +0530 Subject: [PATCH 1/2] fix: reset global regex state in asset filters --- src/utils.js | 5 ++++- test/utils.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index ab3ddf7f..e9ebdad0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -44,7 +44,10 @@ function createAssetsFilter(excludePatterns) { * @param {string} asset asset * @returns {boolean} true when need to exclude, otherwise false */ - (asset) => pattern.test(asset) + (asset) => { + pattern.lastIndex = 0; + return pattern.test(asset); + } ); } diff --git a/test/utils.js b/test/utils.js index 46d56d63..c3da23b8 100644 --- a/test/utils.js +++ b/test/utils.js @@ -25,6 +25,14 @@ describe("createAssetsFilter", () => { expect(filter("bar-foo")).toBe(true); }); + it("should consistently filter assets with global RegExp patterns", () => { + const filter = createAssetsFilter(/\.js/g); + + expect(filter("main.js")).toBe(false); + expect(filter("main.js")).toBe(false); + expect(filter("main.js")).toBe(false); + }); + it("should allow a filter function as a pattern", () => { const filter = createAssetsFilter((asset) => asset.startsWith("foo")); expect(filter("foo")).toBe(false); From bf334da747144d38bdb9ac6f1cd58bca7f7b2f4a Mon Sep 17 00:00:00 2001 From: DarshanaChandel Date: Wed, 21 Oct 2026 00:34:11 +0530 Subject: [PATCH 2/2] test: correct global regex filter expectations --- test/utils.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/utils.js b/test/utils.js index c3da23b8..9ae5ed8e 100644 --- a/test/utils.js +++ b/test/utils.js @@ -24,14 +24,13 @@ describe("createAssetsFilter", () => { expect(filter("bar")).toBe(true); expect(filter("bar-foo")).toBe(true); }); +it("should consistently filter assets with global RegExp patterns", () => { + const filter = createAssetsFilter(/\.js/g); - it("should consistently filter assets with global RegExp patterns", () => { - const filter = createAssetsFilter(/\.js/g); - - expect(filter("main.js")).toBe(false); - expect(filter("main.js")).toBe(false); - expect(filter("main.js")).toBe(false); - }); + expect(filter("main.js")).toBe(false); + expect(filter("main.js")).toBe(false); + expect(filter("main.js")).toBe(false); +}); it("should allow a filter function as a pattern", () => { const filter = createAssetsFilter((asset) => asset.startsWith("foo"));