// NOTICE: This file is generated by Rollup. To modify it,
// please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
'use strict';

const ignore = require('ignore');

const { isPathValid } = ignore.default;

/**
 * @param {import('ignore').Ignore} ignorer
 * @param {string[]} filePaths
 * @returns {string[]}
 */
function filterFilePaths(ignorer, filePaths) {
	const validForIgnore = filePaths.filter(isPathValid);
	// Paths which starts with `..` are not valid for `ignore`, e. g. `../style.css`
	const notValidForIgnore = new Set(filePaths.filter((p) => !validForIgnore.includes(p)));

	const filteredByIgnore = new Set(ignorer.filter(validForIgnore));

	// Preserving files order, while removing paths which were filtered by `ignore`
	return filePaths.filter((p) => notValidForIgnore.has(p) || filteredByIgnore.has(p));
}

module.exports = filterFilePaths;
