-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from vio/exclude-entries
feat: Add support for excludeAssets/excludeModules
- Loading branch information
Showing
6 changed files
with
177 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean); | ||
|
||
export type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>; | ||
|
||
/** | ||
* Check if filepath should be excluded based on patterns | ||
*/ | ||
export function checkExcludeFilepath( | ||
filepath: string, | ||
patterns?: ExcludeFilepathPatterns, | ||
): boolean { | ||
if (!patterns) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(patterns)) { | ||
let res = false; | ||
|
||
for (let i = 0; i <= patterns.length - 1 && res === false; i++) { | ||
res = checkExcludeFilepath(filepath, patterns[i]); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
if (typeof patterns === 'function') { | ||
return patterns(filepath); | ||
} | ||
|
||
if (typeof patterns === 'string') { | ||
return Boolean(filepath.match(patterns)); | ||
} | ||
|
||
if ('test' in patterns) { | ||
return patterns.test(filepath); | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
|
||
import { checkExcludeFilepath } from '../../../src/utils/check-exclude-filepath'; | ||
|
||
describe('utils', () => { | ||
describe('checkExcludeFilepath', () => { | ||
const testCases: Array<{ input: Parameters<typeof checkExcludeFilepath>; output: ReturnType<typeof checkExcludeFilepath>}> = [ | ||
{ | ||
input: ['./assets/vendor.js'], | ||
output: false, | ||
}, | ||
{ | ||
input: ['./assets/vendor.js', 'vendor'], | ||
output: true, | ||
}, | ||
{ | ||
input: ['./assets/vendor.js', 'unknown'], | ||
output: false, | ||
}, | ||
{ | ||
input: ['./assets/vendor.js', /vendor/], | ||
output: true, | ||
}, | ||
{ | ||
input: ['./assets/vendor.js', () => true], | ||
output: true, | ||
}, | ||
{ | ||
input: ['./assets/vendor.js', ['main', /vendor/]], | ||
output: true, | ||
}, | ||
{ | ||
input: ['./assets/vendor.js', ['main', /unknown/, () => false]], | ||
output: false, | ||
}, | ||
]; | ||
|
||
testCases.forEach(({ input, output }) => { | ||
test(`Should return "${output}" when called with: "${input.join('", "')}"`, () => { | ||
expect(checkExcludeFilepath(...input)).toEqual(output); | ||
}); | ||
}); | ||
}); | ||
}); |