import { existsSync } from 'node:fs' import { join } from 'node:path' import { getPlatformDirFromCapacitorConfig } from '../build/platform-paths' /** * Which native dependency manager the Capacitor iOS project uses. * - `cocoapods`: `/App/Podfile` only * - `spm`: `/App/CapApp-SPM/Package.swift` only * - `mixed`: both files exist (half-migrated project) * - `none`: no iOS project, or neither file */ export type IosDependencyManager = 'cocoapods' | 'spm' | 'mixed' | 'none' /** CocoaPods trunk stops accepting new podspecs on this date (blog.cocoapods.org/CocoaPods-Specs-Repo). */ export const COCOAPODS_READ_ONLY_DATE = '2026-12-02' export const COCOAPODS_READ_ONLY_URL = 'https://blog.cocoapods.org/CocoaPods-Specs-Repo/' export const SPM_MIGRATION_DOCS_URL = 'https://capgo.app/blog/how-to-migrate-your-capacitor-app-to-spm/' export function detectIosDependencyManager(projectDir: string, capConfig?: unknown): IosDependencyManager { const appDir = join(projectDir, getPlatformDirFromCapacitorConfig(capConfig, 'ios'), 'App') const hasPodfile = existsSync(join(appDir, 'Podfile')) const hasSpm = existsSync(join(appDir, 'CapApp-SPM', 'Package.swift')) if (hasPodfile && hasSpm) return 'mixed' if (hasPodfile) return 'cocoapods' if (hasSpm) return 'spm' return 'none' } export function usesCocoaPods(manager: IosDependencyManager): boolean { return manager === 'cocoapods' || manager === 'mixed' } /** Human-readable deprecation notice. Wording follows the current date so it stays true before and after the cutoff. */ export function formatCocoaPodsReadOnlyWarning(manager: IosDependencyManager, now: Date = new Date()): string { const readOnly = now.getTime() >= Date.parse(`${COCOAPODS_READ_ONLY_DATE}T00:00:00Z`) const when = readOnly ? 'CocoaPods trunk has been read-only since December 2, 2026' : 'CocoaPods trunk becomes read-only on December 2, 2026' const subject = manager === 'mixed' ? 'Your iOS project has a Podfile next to CapApp-SPM/Package.swift. If that Podfile is still used, part of the app depends on CocoaPods.' : 'Your iOS project uses CocoaPods (App/Podfile) instead of Swift Package Manager.' return [ subject, `${when}: no new versions can be published to it, so pods resolved from public trunk (often the native SDKs used by plugins) stop receiving updates, including security fixes, and vendors are moving new releases to Swift Package Manager. Pods loaded from node_modules (:path) or private spec repos are not affected.`, `Migrate to SPM: ${SPM_MIGRATION_DOCS_URL} (details: ${COCOAPODS_READ_ONLY_URL})`, ].join('\n') }