Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);
}

Expand Down
7 changes: 7 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
expect(filter("bar")).toBe(true);
expect(filter("bar-foo")).toBe(true);
});
it("should consistently filter assets with global RegExp patterns", () => {

Check failure on line 27 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Expected blank line before this statement

Check failure on line 27 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
const filter = createAssetsFilter(/\.js/g);

Check failure on line 28 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`

expect(filter("main.js")).toBe(false);

Check failure on line 30 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
expect(filter("main.js")).toBe(false);

Check failure on line 31 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
expect(filter("main.js")).toBe(false);

Check failure on line 32 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Replace `··` with `····`
});

Check failure on line 33 in test/utils.js

View workflow job for this annotation

GitHub Actions / lint

Insert `··`

it("should allow a filter function as a pattern", () => {
const filter = createAssetsFilter((asset) => asset.startsWith("foo"));
Expand Down
Loading