"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const supi_1 = require("supi");
const createStoreController_1 = require("../createStoreController");
const findWorkspacePackages_1 = require("../findWorkspacePackages");
const readImporterManifest_1 = require("../readImporterManifest");
const requireHooks_1 = require("../requireHooks");
async function uninstallCmd(input, opts) {
    const store = await createStoreController_1.default(opts);
    const uninstallOpts = Object.assign(opts, {
        store: store.path,
        storeController: store.ctrl,
    });
    if (!opts.ignorePnpmfile) {
        opts.hooks = requireHooks_1.default(opts.lockfileDirectory || opts.prefix, opts);
    }
    uninstallOpts['localPackages'] = opts.linkWorkspacePackages && opts.workspacePrefix
        ? findWorkspacePackages_1.arrayOfLocalPackagesToMap(await findWorkspacePackages_1.default(opts.workspacePrefix, opts))
        : undefined;
    const currentManifest = await readImporterManifest_1.default(opts.prefix, opts);
    const [mutationResult] = await supi_1.mutateModules([
        {
            bin: opts.bin,
            dependencyNames: input,
            manifest: currentManifest.manifest,
            mutation: 'uninstallSome',
            prefix: opts.prefix,
        },
    ], uninstallOpts);
    await currentManifest.writeImporterManifest(mutationResult.manifest);
}
exports.default = uninstallCmd;
