"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_loggers_1 = require("@pnpm/core-loggers");
const types_1 = require("@pnpm/types");
const load_json_file_1 = require("load-json-file");
const writePkg = require("write-pkg");
async function default_1(pkgJsonPath, removedPackages, opts) {
    const packageJson = await load_json_file_1.default(pkgJsonPath);
    if (opts.saveType) {
        packageJson[opts.saveType] = packageJson[opts.saveType];
        if (!packageJson[opts.saveType])
            return packageJson;
        removedPackages.forEach((dependency) => {
            delete packageJson[opts.saveType][dependency];
        });
    }
    else {
        types_1.DEPENDENCIES_FIELDS
            .filter((depField) => packageJson[depField])
            .forEach((depField) => {
            removedPackages.forEach((dependency) => {
                delete packageJson[depField][dependency];
            });
        });
    }
    await writePkg(pkgJsonPath, packageJson);
    core_loggers_1.packageJsonLogger.debug({
        prefix: opts.prefix,
        updated: packageJson,
    });
    return packageJson;
}
exports.default = default_1;
//# sourceMappingURL=removeDeps.js.map