"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_loggers_1 = require("@pnpm/core-loggers");
const types_1 = require("@pnpm/types");
async function default_1(packageJson, removedPackages, opts) {
    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];
            });
        });
    }
    if (packageJson.peerDependencies) {
        for (const removedDependency of removedPackages) {
            delete packageJson.peerDependencies[removedDependency];
        }
    }
    core_loggers_1.packageJsonLogger.debug({
        prefix: opts.prefix,
        updated: packageJson,
    });
    return packageJson;
}
exports.default = default_1;
