"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getVerSelType = require("version-selector-type");
function depsFromPackage(pkg) {
    return Object.assign({}, pkg.devDependencies, pkg.dependencies, pkg.optionalDependencies);
}
exports.default = depsFromPackage;
function getPreferredVersionsFromPackage(pkg) {
    return getVersionSpecsByRealNames(depsFromPackage(pkg));
}
exports.getPreferredVersionsFromPackage = getPreferredVersionsFromPackage;
function getVersionSpecsByRealNames(deps) {
    return Object.keys(deps)
        .reduce((acc, depName) => {
        if (deps[depName].startsWith('npm:')) {
            const pref = deps[depName].substr(4);
            const index = pref.lastIndexOf('@');
            const spec = pref.substr(index + 1);
            const selector = getVerSelType(spec);
            if (selector) {
                acc[pref.substr(0, index)] = {
                    selector: selector.normalized,
                    type: selector.type,
                };
            }
        }
        else if (deps[depName].indexOf(':') === -1) {
            const selector = getVerSelType(deps[depName]);
            if (selector) {
                acc[depName] = {
                    selector: selector.normalized,
                    type: selector.type,
                };
            }
        }
        return acc;
    }, {});
}
//# sourceMappingURL=depsFromPackage.js.map