"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 path_1 = require("path");
const readPkg_1 = require("../fs/readPkg");
/**
 * Resolves a package hosted on the local filesystem
 */
function resolveLocal(spec, opts) {
    return __awaiter(this, void 0, void 0, function* () {
        const dependencyPath = path_1.resolve(opts.root, spec.spec);
        if (dependencyPath.slice(-4) === '.tgz' || dependencyPath.slice(-7) === '.tar.gz') {
            const resolution = {
                type: 'tarball',
                tarball: `file:${dependencyPath}`,
            };
            return {
                id: createLocalPkgId(dependencyPath),
                resolution,
            };
        }
        const localPkg = yield readPkg_1.default(dependencyPath);
        const resolution = {
            type: 'directory',
            root: dependencyPath,
        };
        return {
            id: createLocalPkgId(dependencyPath),
            resolution,
        };
    });
}
exports.default = resolveLocal;
function createLocalPkgId(dependencyPath) {
    return 'local/' + encodeURIComponent(dependencyPath);
}
//# sourceMappingURL=local.js.map