import { rm } from 'node:fs/promises';
import { resolveFirstPartyVersionInstallPath } from './installLayout.js';
import { resolveRetainedVersionIds } from './retentionPolicy.js';
export async function pruneRetainedVersions(params) {
    const { keep, prune } = resolveRetainedVersionIds({
        orderedVersionIdsNewestFirst: params.orderedVersionIdsNewestFirst,
        currentVersionId: params.currentVersionId,
        previousVersionId: params.previousVersionId,
        retainCount: params.retainCount,
    });
    await Promise.all(prune.map(async (versionId) => {
        const versionPath = resolveFirstPartyVersionInstallPath({
            componentId: params.componentId,
            versionId,
            channel: params.channel,
            releaseRing: params.releaseRing,
            processEnv: params.processEnv,
        });
        await rm(versionPath, { recursive: true, force: true });
    }));
    return {
        keptVersionIds: keep,
        prunedVersionIds: prune,
    };
}
//# sourceMappingURL=pruneRetainedVersions.js.map