1 | ;
|
2 |
|
3 | const { isPathValid } = require('ignore').default;
|
4 |
|
5 | /**
|
6 | * @param {import('ignore').Ignore} ignorer
|
7 | * @param {string[]} filePaths
|
8 | * @returns {string[]}
|
9 | */
|
10 | module.exports = function filterFilePaths(ignorer, filePaths) {
|
11 | const validForIgnore = filePaths.filter(isPathValid);
|
12 | // Paths which starts with `..` are not valid for `ignore`, e. g. `../style.css`
|
13 | const notValidForIgnore = filePaths.filter((p) => !validForIgnore.includes(p));
|
14 |
|
15 | const filteredByIgnore = ignorer.filter(validForIgnore);
|
16 |
|
17 | // Preserving files order, while removing paths which were filtered by `ignore`
|
18 | return filePaths.filter((p) => notValidForIgnore.includes(p) || filteredByIgnore.includes(p));
|
19 | };
|