"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());
    });
};
const crossSpawn = require("cross-spawn");
const path = require("path");
const delocalizeDeps = require("delocalize-dependencies");
const readPkgUp = require("read-pkg-up");
const writePkg = require("write-pkg");
function default_1(input, opts) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!opts.linkLocal) {
            runNpmPublish();
        }
        const pkg = yield readPkgUp({ cwd: opts.cwd, normalize: false });
        const newPkg = delocalizeDeps({
            saveExact: opts.saveExact,
            pkgDir: path.dirname(pkg.path),
            pkg: pkg.pkg
        });
        yield writePkg(pkg.path, newPkg);
        try {
            yield runNpmPublish();
        }
        finally {
            yield writePkg(pkg.path, pkg.pkg);
        }
    });
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
function runNpmPublish() {
    crossSpawn.sync('npm', process.argv.slice(2), { stdio: 'inherit' });
}
//# sourceMappingURL=publish.js.map