"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
const path_1 = require("path");
async function update(tree) {
    devkit_1.logger.info('🔄 Updating @changesets/cli patch');
    try {
        const patchesPath = 'patches';
        const patchesTemplatePath = (0, path_1.join)(__dirname, 'patches');
        const patchFileName = '@changesets+cli+2.29.7.patch';
        // Delete existing changeset patch if it exists
        if (tree.exists(patchesPath)) {
            const existingFiles = tree.children(patchesPath);
            for (const file of existingFiles) {
                if (file.includes('@changesets+cli')) {
                    devkit_1.logger.info(`🗑️ Removing existing patch: ${file}`);
                    tree.delete((0, path_1.join)(patchesPath, file));
                }
            }
        }
        // Copy the updated patch file
        (0, devkit_1.generateFiles)(tree, patchesTemplatePath, `./${patchesPath}`, {});
        devkit_1.logger.info(`✅ Updated patch: ${patchFileName}`);
        devkit_1.logger.info('ℹ️  This patch filters out unisphere-runtime-* packages from the major bump selection');
    }
    catch (error) {
        devkit_1.logger.error(`❌ Failed to update patch: ${error?.message || 'Unknown error'}`);
        throw error;
    }
}
