"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeBinsOfDependency = exports.removeBin = void 0;
const core_loggers_1 = require("@pnpm/core-loggers");
const package_bins_1 = require("@pnpm/package-bins");
const read_package_json_1 = require("@pnpm/read-package-json");
const rimraf = require("@zkochan/rimraf");
const isWindows = require("is-windows");
const path = require("path");
async function removeOnWin(cmd) {
    core_loggers_1.removalLogger.debug(cmd);
    await Promise.all([
        rimraf(cmd),
        rimraf(`${cmd}.ps1`),
        rimraf(`${cmd}.cmd`),
    ]);
}
function removeOnNonWin(p) {
    core_loggers_1.removalLogger.debug(p);
    return rimraf(p);
}
exports.removeBin = isWindows() ? removeOnWin : removeOnNonWin;
async function removeBinsOfDependency(dependencyDir, opts) {
    const uninstalledPkgJson = await read_package_json_1.safeReadPackageFromDir(dependencyDir);
    if (!uninstalledPkgJson)
        return;
    const cmds = await package_bins_1.default(uninstalledPkgJson, dependencyDir);
    if (!opts.dryRun) {
        await Promise.all(cmds
            .map((cmd) => path.join(opts.binsDir, cmd.name))
            .map(exports.removeBin));
    }
    return uninstalledPkgJson;
}
exports.removeBinsOfDependency = removeBinsOfDependency;
//# sourceMappingURL=removeBins.js.map