"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const tslib_1 = require("tslib");
const toml_1 = tslib_1.__importDefault(require("@iarna/toml"));
const logger_1 = require("../../../logger");
const processors_1 = require("./processors");
const schema_1 = require("./schema");
const utils_1 = require("./utils");
function extractPackageFile(content, packageFile, _config) {
    logger_1.logger.trace(`pep621.extractPackageFile(${packageFile})`);
    const deps = [];
    let def;
    try {
        const jsonMap = toml_1.default.parse(content);
        def = schema_1.PyProjectSchema.parse(jsonMap);
    }
    catch (err) {
        logger_1.logger.debug({ packageFile, err }, `Failed to parse and validate pyproject file`);
        return null;
    }
    // pyProject standard definitions
    deps.push(...(0, utils_1.parseDependencyList)('project.dependencies', def.project?.dependencies));
    deps.push(...(0, utils_1.parseDependencyGroupRecord)('project.optional-dependencies', def.project?.['optional-dependencies']));
    // process specific tool sets
    let processedDeps = deps;
    for (const processor of processors_1.processors) {
        processedDeps = processor.process(def, processedDeps);
    }
    return processedDeps.length ? { deps: processedDeps } : null;
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map