"use strict";
const requireJson_1 = require('./fs/requireJson');
const writeJson_1 = require('./fs/writeJson');
const sortedObject = require('sorted-object');
function save(pkgJsonPath, installedPackages, saveType, useExactVersion) {
    // Read the latest version of package.json to avoid accidental overwriting
    const packageJson = requireJson_1.default(pkgJsonPath, { ignoreCache: true });
    packageJson[saveType] = packageJson[saveType] || {};
    installedPackages.forEach(dependency => {
        const semverCharacter = useExactVersion ? '' : '^';
        packageJson[saveType][dependency.pkg.name] = semverCharacter + dependency.pkg.version;
    });
    packageJson[saveType] = sortedObject(packageJson[saveType]);
    return writeJson_1.default(pkgJsonPath, packageJson);
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = save;
//# sourceMappingURL=save.js.map