"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.newArchCompatExpectedVersions = exports.findAndUpdateDependencyVersions = exports.removePackageJSONDependencies = exports.findAndRemoveDependencies = void 0;
var gluegun_1 = require("gluegun");
// This function takes a package.json file as a string and removes the dependencies
// supplied in dependenciesToRemove and returns the updated package.json as a string.
function findAndRemoveDependencies(packageJsonRaw, dependenciesToRemove) {
    var updatedPackageJson = packageJsonRaw;
    dependenciesToRemove.forEach(function (depName) {
        var regex = new RegExp("\"".concat(depName, "\"\\s*:\\s*\"[^\"]+\",?"), "g");
        updatedPackageJson = updatedPackageJson.replace(regex, "");
    });
    return updatedPackageJson;
}
exports.findAndRemoveDependencies = findAndRemoveDependencies;
function removePackageJSONDependencies(packageJsonPath, dependenciesToRemove) {
    var packageJsonRaw = gluegun_1.filesystem.read(packageJsonPath);
    var updatedPackageJson = findAndRemoveDependencies(packageJsonRaw, dependenciesToRemove);
    gluegun_1.filesystem.write(packageJsonPath, updatedPackageJson);
}
exports.removePackageJSONDependencies = removePackageJSONDependencies;
function findAndUpdateDependencyVersions(packageJsonRaw, dependencies) {
    var updatedPackageJson = packageJsonRaw;
    Object.keys(dependencies).forEach(function (depName) {
        var desiredVersion = dependencies[depName];
        var regex = new RegExp("\"".concat(depName, "\"\\s*:\\s*\"[^\"]+\""), "g");
        updatedPackageJson = updatedPackageJson.replace(regex, "\"".concat(depName, "\": \"").concat(desiredVersion, "\""));
    });
    // Make sure `expo-dev-client` is removed
    updatedPackageJson = updatedPackageJson.replace(/"expo-dev-client"\s*:\s*"[^"]+",?/g, "");
    return updatedPackageJson;
}
exports.findAndUpdateDependencyVersions = findAndUpdateDependencyVersions;
exports.newArchCompatExpectedVersions = {
    "react-native-mmkv": "3.1.0",
};
//# sourceMappingURL=dependencies.js.map