"use strict";
const npm_1 = require("./npm");
const tarball_1 = require("./tarball");
const github_1 = require("./github");
const local_1 = require("./local");
const git_1 = require("./git");
/**
 * Resolves a package in the NPM registry. Done as part of `install()`.
 *
 * @example
 *     var npa = require('npm-package-arg')
 *     resolve(npa('rimraf@2'))
 *       .then((res) => {
 *         res.id == 'rimraf@2.5.1'
 *         res.dist == {
 *           shasum: '0a1b2c...'
 *           tarball: 'http://...'
 *         }
 *       })
 */
function default_1(spec, opts) {
    switch (spec.type) {
        case 'range':
        case 'version':
        case 'tag':
            return npm_1.default(spec, opts);
        case 'remote':
            return tarball_1.default(spec, opts);
        case 'local':
            return local_1.default(spec, opts);
        case 'hosted':
            const hspec = spec;
            if (hspec.hosted.type === 'github' && !isSsh(hspec.spec)) {
                return github_1.default(hspec, opts);
            }
            return git_1.default(spec, opts);
        case 'git':
            return git_1.default(spec, opts);
        default:
            throw new Error(`${spec.rawSpec}: ${spec.type} packages not supported`);
    }
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
function isSsh(gitSpec) {
    return gitSpec.substr(0, 10) === 'git+ssh://'
        || gitSpec.substr(0, 4) === 'git@';
}
//# sourceMappingURL=index.js.map