"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const logger_1 = require("../../../logger");
const extract_1 = require("../pip_requirements/extract");
function matchManager(filename) {
    if (filename.endsWith('setup.py')) {
        return 'pip_setup';
    }
    if (filename.endsWith('setup.cfg')) {
        return 'setup-cfg';
    }
    if (filename.endsWith('pyproject.toml')) {
        return 'pep621';
    }
    // naive, could be improved, maybe use pip_requirements.fileMatch
    if (filename.endsWith('.in')) {
        return 'pip_requirements';
    }
    return 'unknown';
}
function extractPackageFile(content, packageFile, _config) {
    logger_1.logger.trace('pip-compile.extractPackageFile()');
    const manager = matchManager(packageFile);
    // TODO(not7cd): extract based on manager: pep621, setuptools, identify other missing source types
    switch (manager) {
        // TODO(not7cd): enable in the next PR, when this can be properly tested
        // case 'pip_setup':
        //   return extractSetupPyFile(content, _packageFile, _config);
        // case 'setup-cfg':
        //   return await extractSetupCfgFile(content);
        case 'pip_requirements':
            return (0, extract_1.extractPackageFile)(content);
        case 'unknown':
            logger_1.logger.warn({ packageFile }, `pip-compile: could not determine manager for source file, fallback to pip_requirements`);
            return (0, extract_1.extractPackageFile)(content);
        default:
            logger_1.logger.warn({ packageFile, manager }, `pip-compile: support for manager is not yet implemented`);
            return null;
    }
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map