"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const parser_1 = require("./parser");
const rules_1 = require("./rules");
function extractPackageFile(content, packageFile) {
    const deps = [];
    const fragments = (0, parser_1.parse)(content, packageFile);
    if (!fragments) {
        return null;
    }
    for (let idx = 0; idx < fragments.length; idx += 1) {
        const fragment = fragments[idx];
        for (const dep of (0, rules_1.extractDepsFromFragment)(fragment)) {
            dep.managerData = { idx };
            // Selectively provide `replaceString` in order
            // to auto-replace functionality work correctly.
            const replaceString = fragment.value;
            if (replaceString.startsWith('container_pull') ||
                replaceString.startsWith('git_repository') ||
                replaceString.startsWith('go_repository')) {
                if (dep.currentValue && dep.currentDigest) {
                    dep.replaceString = replaceString;
                }
            }
            deps.push(dep);
        }
    }
    return deps.length ? { deps } : null;
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map