"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const logger_1 = require("../../../logger");
const processors_1 = require("./processors");
const utils_1 = require("./utils");
function extractPackageFile(content, packageFile, _config) {
    logger_1.logger.trace(`pep621.extractPackageFile(${packageFile})`);
    const deps = [];
    const def = (0, utils_1.parsePyProject)(packageFile, content);
    if (is_1.default.nullOrUndefined(def)) {
        return null;
    }
    const packageFileVersion = def.project?.version;
    const pythonConstraint = def.project?.['requires-python'];
    const extractedConstraints = is_1.default.nonEmptyString(pythonConstraint)
        ? { extractedConstraints: { python: pythonConstraint } }
        : {};
    // pyProject standard definitions
    deps.push(...(0, utils_1.parseDependencyList)(utils_1.depTypes.dependencies, def.project?.dependencies));
    deps.push(...(0, utils_1.parseDependencyGroupRecord)(utils_1.depTypes.optionalDependencies, def.project?.['optional-dependencies']));
    deps.push(...(0, utils_1.parseDependencyList)(utils_1.depTypes.buildSystemRequires, def['build-system']?.requires));
    // process specific tool sets
    let processedDeps = deps;
    for (const processor of processors_1.processors) {
        processedDeps = processor.process(def, processedDeps);
    }
    return processedDeps.length
        ? { ...extractedConstraints, deps: processedDeps, packageFileVersion }
        : null;
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map