"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PackagePatternsMatcher = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const logger_1 = require("../../logger");
const regex_1 = require("../regex");
const base_1 = require("./base");
const utils_1 = require("./utils");
class PackagePatternsMatcher extends base_1.Matcher {
    matches({ depName, updateType }, { matchPackagePatterns }) {
        if (is_1.default.undefined(matchPackagePatterns)) {
            return null;
        }
        if (is_1.default.undefined(depName)) {
            return false;
        }
        let isMatch = false;
        for (const packagePattern of matchPackagePatterns) {
            const packageRegex = (0, regex_1.regEx)((0, utils_1.massagePattern)(packagePattern));
            if (packageRegex.test(depName)) {
                logger_1.logger.trace(`${depName} matches against ${String(packageRegex)}`);
                isMatch = true;
            }
        }
        return isMatch;
    }
    excludes({ depName, updateType }, { excludePackagePatterns }) {
        // ignore lockFileMaintenance for backwards compatibility
        if (is_1.default.undefined(excludePackagePatterns)) {
            return null;
        }
        if (is_1.default.undefined(depName)) {
            return false;
        }
        let isMatch = false;
        for (const pattern of excludePackagePatterns) {
            const packageRegex = (0, regex_1.regEx)((0, utils_1.massagePattern)(pattern));
            if (packageRegex.test(depName)) {
                logger_1.logger.trace(`${depName} matches against ${String(packageRegex)}`);
                isMatch = true;
            }
        }
        return isMatch;
    }
}
exports.PackagePatternsMatcher = PackagePatternsMatcher;
//# sourceMappingURL=package-patterns.js.map