"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const parse_npm_tarball_url_1 = require("parse-npm-tarball-url");
/**
 * Resolves a 'remote' package.
 *
 * @example
 *     pkg = {
 *       raw: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz',
 *       scope: null,
 *       name: null,
 *       rawSpec: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz',
 *       spec: 'http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz',
 *       type: 'remote' }
 *     resolveTarball(pkg)
 */
function resolveTarball(spec, opts) {
    return __awaiter(this, void 0, void 0, function* () {
        const resolution = {
            type: 'tarball',
            tarball: spec.rawSpec,
        };
        if (spec.rawSpec.startsWith('http://registry.npmjs.org/')) {
            const parsed = parse_npm_tarball_url_1.default(spec.rawSpec);
            if (parsed) {
                return {
                    id: `${parsed.host}/${parsed.pkg.name}/${parsed.pkg.version}`,
                    resolution,
                };
            }
        }
        return {
            id: spec.rawSpec
                .replace(/^.*:\/\/(git@)?/, '')
                .replace(/\.tgz$/, ''),
            resolution,
        };
    });
}
exports.default = resolveTarball;
//# sourceMappingURL=tarball.js.map