"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const versionSelectorType = require("version-selector-type");
function getPref(alias, name, version, opts) {
    const prefix = alias !== name ? `npm:${name}@` : '';
    if (opts.rawSpec && opts.rawSpec.startsWith(`${alias}@${prefix}`)) {
        const selector = versionSelectorType(opts.rawSpec.substr(`${alias}@${prefix}`.length));
        if (selector && (selector.type === 'version' || selector.type === 'range')) {
            return opts.rawSpec.substr(alias.length + 1);
        }
    }
    switch (opts.pinnedVersion || 'major') {
        case 'major':
            return `${prefix}^${version}`;
        case 'minor':
            return `${prefix}~${version}`;
        case 'patch':
            return `${prefix}${version}`;
    }
}
exports.default = getPref;
