"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 removeCmd(input, opts) {
    const store = await createStoreController_1.default(opts);
    const removeOpts = Object.assign(opts, {
        storeController: store.ctrl,
        storeDir: store.dir,
    });
    if (!opts.ignorePnpmfile) {
        opts.hooks = requireHooks_1.default(opts.lockfileDir || opts.dir, opts);
    }
    removeOpts['localPackages'] = opts.linkWorkspacePackages && opts.workspaceDir
        ? findWorkspacePackages_1.arrayOfLocalPackagesToMap(await findWorkspacePackages_1.default(opts.workspaceDir, opts))
        : undefined;
    const currentManifest = await readImporterManifest_1.default(opts.dir, opts);
    const [mutationResult] = await supi_1.mutateModules([
        {
            binsDir: opts.bin,
            dependencyNames: input,
            manifest: currentManifest.manifest,
            mutation: 'uninstallSome',
            rootDir: opts.dir,
        },
    ], removeOpts);
    await currentManifest.writeImporterManifest(mutationResult.manifest);
}
exports.default = removeCmd;
