"use strict";
/**
 * Migration: Remove @swc/cli
 *
 * Removes @swc/cli from package.json (all dependency sections)
 * and removes it from package-lock.json if present.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
    devkit_1.logger.info('🔄 Removing @swc/cli from package.json and package-lock.json...');
    const targetPackage = '@swc/cli';
    let removedFromPackageJson = false;
    // Remove from package.json
    const packageJsonPath = 'package.json';
    if (!tree.exists(packageJsonPath)) {
        devkit_1.logger.warn('⚠️ No package.json found, skipping');
        return;
    }
    (0, devkit_1.updateJson)(tree, packageJsonPath, (packageJson) => {
        if (packageJson.dependencies?.[targetPackage]) {
            delete packageJson.dependencies[targetPackage];
            removedFromPackageJson = true;
            devkit_1.logger.info(`📦 Removed ${targetPackage} from dependencies`);
        }
        if (packageJson.devDependencies?.[targetPackage]) {
            delete packageJson.devDependencies[targetPackage];
            removedFromPackageJson = true;
            devkit_1.logger.info(`📦 Removed ${targetPackage} from devDependencies`);
        }
        if (packageJson.optionalDependencies?.[targetPackage]) {
            delete packageJson.optionalDependencies[targetPackage];
            removedFromPackageJson = true;
            devkit_1.logger.info(`📦 Removed ${targetPackage} from optionalDependencies`);
        }
        return packageJson;
    });
    if (removedFromPackageJson) {
        devkit_1.logger.info('✅ Successfully removed @swc/cli');
    }
    else {
        devkit_1.logger.info('ℹ️ @swc/cli not found in package.json, skipping');
    }
}
