"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const logger_1 = require("../../../logger");
const parser_1 = require("./parser");
const rules_1 = require("./rules");
function extractPackageFile(content, packageFile) {
    const deps = [];
    let parsed = null;
    try {
        parsed = (0, parser_1.parse)(content);
    }
    catch (err) /* istanbul ignore next */ {
        logger_1.logger.debug({ err, packageFile }, 'Bazel parsing error');
    }
    if (!parsed) {
        return null;
    }
    for (let idx = 0; idx < parsed.children.length; idx += 1) {
        const fragment = parsed.children[idx];
        const dep = (0, rules_1.extractDepFromFragment)(fragment);
        if (!dep) {
            continue;
        }
        dep.managerData = { def: fragment.value };
        deps.push(dep);
    }
    return deps.length ? { deps } : null;
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map