"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMatchingFiles = exports.getFilteredFileList = exports.filterIgnoredFiles = exports.getIncludedFiles = void 0;
const logger_1 = require("../../../logger");
const minimatch_1 = require("../../../util/minimatch");
const regex_1 = require("../../../util/regex");
function getIncludedFiles(fileList, includePaths) {
    if (!includePaths?.length) {
        return [...fileList];
    }
    return fileList.filter((file) => includePaths.some((includePath) => file === includePath ||
        (0, minimatch_1.minimatch)(includePath, { dot: true }).match(file)));
}
exports.getIncludedFiles = getIncludedFiles;
function filterIgnoredFiles(fileList, ignorePaths) {
    if (!ignorePaths?.length) {
        return [...fileList];
    }
    return fileList.filter((file) => !ignorePaths.some((ignorePath) => file.includes(ignorePath) ||
        (0, minimatch_1.minimatch)(ignorePath, { dot: true }).match(file)));
}
exports.filterIgnoredFiles = filterIgnoredFiles;
function getFilteredFileList(config, fileList) {
    const { includePaths, ignorePaths } = config;
    // TODO #7154
    let filteredList = getIncludedFiles(fileList, includePaths);
    filteredList = filterIgnoredFiles(filteredList, ignorePaths);
    return filteredList;
}
exports.getFilteredFileList = getFilteredFileList;
function getMatchingFiles(config, allFiles) {
    const fileList = getFilteredFileList(config, allFiles);
    const { fileMatch, manager } = config;
    let matchedFiles = [];
    // TODO: types (#7154)
    for (const match of fileMatch) {
        logger_1.logger.debug(`Using file match: ${match} for manager ${manager}`);
        const re = (0, regex_1.regEx)(match);
        matchedFiles = matchedFiles.concat(fileList.filter((file) => re.test(file)));
    }
    // filter out duplicates
    return [...new Set(matchedFiles)].sort();
}
exports.getMatchingFiles = getMatchingFiles;
//# sourceMappingURL=file-match.js.map