|
| 1 | +# Swift Package Manager Migration Plan |
| 2 | + |
| 3 | +## Overview |
| 4 | +Migrate `workmanager_apple` plugin to support Swift Package Manager (SPM) while maintaining full CocoaPods backward compatibility. |
| 5 | + |
| 6 | +## Current Structure Analysis |
| 7 | +``` |
| 8 | +workmanager_apple/ios/ |
| 9 | +├── Assets/ |
| 10 | +├── Classes/ |
| 11 | +│ ├── BackgroundTaskOperation.swift |
| 12 | +│ ├── BackgroundWorker.swift |
| 13 | +│ ├── Extensions.swift |
| 14 | +│ ├── LoggingDebugHandler.swift |
| 15 | +│ ├── NotificationDebugHandler.swift |
| 16 | +│ ├── SimpleLogger.swift |
| 17 | +│ ├── ThumbnailGenerator.swift |
| 18 | +│ ├── UserDefaultsHelper.swift |
| 19 | +│ ├── WMPError.swift |
| 20 | +│ ├── WorkmanagerDebugHandler.swift |
| 21 | +│ ├── WorkmanagerPlugin.swift |
| 22 | +│ └── pigeon/ |
| 23 | +│ └── WorkmanagerApi.g.swift |
| 24 | +├── Resources/ |
| 25 | +│ └── PrivacyInfo.xcprivacy |
| 26 | +└── workmanager_apple.podspec |
| 27 | +``` |
| 28 | + |
| 29 | +## Migration Strategy |
| 30 | + |
| 31 | +### Phase 1: SPM Structure Setup |
| 32 | +1. Create `workmanager_apple/ios/Package.swift` |
| 33 | +2. Create new directory structure: |
| 34 | + ``` |
| 35 | + workmanager_apple/ios/ |
| 36 | + ├── Sources/ |
| 37 | + │ └── workmanager_apple/ |
| 38 | + │ ├── include/ |
| 39 | + │ │ └── workmanager_apple-umbrella.h (if needed) |
| 40 | + │ └── [all .swift files moved here] |
| 41 | + └── Resources/ |
| 42 | + └── PrivacyInfo.xcprivacy |
| 43 | + ``` |
| 44 | + |
| 45 | +### Phase 2: File Migration |
| 46 | +- **Move Swift files** from `Classes/` to `Sources/workmanager_apple/` |
| 47 | +- **Preserve pigeon structure** as `Sources/workmanager_apple/pigeon/` |
| 48 | +- **Update import statements** if needed |
| 49 | +- **Handle resources** - PrivacyInfo.xcprivacy |
| 50 | + |
| 51 | +### Phase 3: Configuration Files |
| 52 | +- **Create Package.swift** with proper target definitions |
| 53 | +- **Update podspec** to reference new file locations |
| 54 | +- **Maintain backward compatibility** for CocoaPods users |
| 55 | + |
| 56 | +### Phase 4: Testing Strategy |
| 57 | +- **Dual build testing** in GitHub Actions |
| 58 | +- **CocoaPods build**: Test existing workflow |
| 59 | +- **SPM build**: New workflow for SPM validation |
| 60 | +- **Example app testing**: Both dependency managers |
| 61 | + |
| 62 | +## Implementation Details |
| 63 | + |
| 64 | +### Package.swift Configuration |
| 65 | +```swift |
| 66 | +// swift-tools-version: 5.9 |
| 67 | +import PackageDescription |
| 68 | + |
| 69 | +let package = Package( |
| 70 | + name: "workmanager_apple", |
| 71 | + platforms: [ |
| 72 | + .iOS(.v14) |
| 73 | + ], |
| 74 | + products: [ |
| 75 | + .library(name: "workmanager_apple", targets: ["workmanager_apple"]) |
| 76 | + ], |
| 77 | + targets: [ |
| 78 | + .target( |
| 79 | + name: "workmanager_apple", |
| 80 | + resources: [.process("Resources")] |
| 81 | + ) |
| 82 | + ] |
| 83 | +) |
| 84 | +``` |
| 85 | + |
| 86 | +### GitHub Actions Strategy |
| 87 | + |
| 88 | +**Matrix Strategy using Flutter SPM configuration:** |
| 89 | +- **CocoaPods Build**: `flutter config --no-enable-swift-package-manager` + build |
| 90 | +- **SPM Build**: `flutter config --enable-swift-package-manager` + build |
| 91 | + |
| 92 | +**Key Features:** |
| 93 | +1. **Flutter-native approach**: Use `flutter config` flags to switch dependency managers |
| 94 | +2. **Simple validation**: Does example app build and run with both configurations? |
| 95 | +3. **Matrix builds**: Test both `--enable-swift-package-manager` and `--no-enable-swift-package-manager` |
| 96 | + |
| 97 | +**GitHub Actions Matrix:** |
| 98 | +```yaml |
| 99 | +strategy: |
| 100 | + matrix: |
| 101 | + spm_enabled: [true, false] |
| 102 | + include: |
| 103 | + - spm_enabled: true |
| 104 | + config_cmd: "flutter config --enable-swift-package-manager" |
| 105 | + name: "SPM" |
| 106 | + - spm_enabled: false |
| 107 | + config_cmd: "flutter config --no-enable-swift-package-manager" |
| 108 | + name: "CocoaPods" |
| 109 | +``` |
| 110 | +
|
| 111 | +## Risk Mitigation |
| 112 | +
|
| 113 | +### Backward Compatibility |
| 114 | +- **Keep CocoaPods support** indefinitely |
| 115 | +- **Update podspec paths** to point to new locations |
| 116 | +- **Test both build systems** in CI |
| 117 | +
|
| 118 | +### File Organization |
| 119 | +- **Maintain logical grouping** of Swift files |
| 120 | +- **Preserve pigeon integration** with generated files |
| 121 | +- **Handle resources properly** in both systems |
| 122 | +
|
| 123 | +### Dependencies |
| 124 | +- **No external Swift dependencies** currently - simplifies migration |
| 125 | +- **Flutter framework dependency** handled by both systems |
| 126 | +
|
| 127 | +## Testing Requirements |
| 128 | +
|
| 129 | +### Pre-Migration Tests |
| 130 | +- [ ] Current CocoaPods build works |
| 131 | +- [ ] Example app builds and runs |
| 132 | +- [ ] All functionality works on physical device |
| 133 | +
|
| 134 | +### Verification Strategy |
| 135 | +**Simple test**: Does the example app build and run with both dependency managers? |
| 136 | +
|
| 137 | +**CocoaPods Build:** |
| 138 | +```bash |
| 139 | +flutter config --no-enable-swift-package-manager |
| 140 | +cd example && flutter build ios --debug --no-codesign |
| 141 | +``` |
| 142 | + |
| 143 | +**SPM Build:** |
| 144 | +```bash |
| 145 | +flutter config --enable-swift-package-manager |
| 146 | +cd example && flutter build ios --debug --no-codesign |
| 147 | +``` |
| 148 | + |
| 149 | +**Flutter Requirements:** |
| 150 | +- Flutter 3.24+ required for SPM support |
| 151 | +- SPM is off by default, must be explicitly enabled |
| 152 | + |
| 153 | +### CI/CD Integration |
| 154 | +- Use Flutter's built-in SPM configuration flags |
| 155 | +- Test both dependency managers via matrix builds |
| 156 | +- No separate long-lived branches needed |
| 157 | + |
| 158 | +## Implementation Phases |
| 159 | + |
| 160 | +### Phase 1: Directory Restructure (First Commit) |
| 161 | +1. Create SPM-compliant directory structure |
| 162 | +2. Move all Swift files to `Sources/workmanager_apple/` |
| 163 | +3. Update podspec to reference new locations |
| 164 | +4. Ensure CocoaPods + Pigeon still work |
| 165 | +5. **Verification**: Example app builds and runs with CocoaPods |
| 166 | + |
| 167 | +### Phase 2: SPM Configuration (Second Commit) |
| 168 | +1. Add `Package.swift` with proper configuration |
| 169 | +2. Handle resources (PrivacyInfo.xcprivacy) |
| 170 | +3. **Verification**: Example app builds and runs with SPM |
| 171 | + |
| 172 | +### Phase 3: CI Integration (Third Commit) |
| 173 | +1. Update GitHub Actions to test both dependency managers |
| 174 | +2. Use Flutter config flags for SPM/CocoaPods selection |
| 175 | + |
| 176 | +## Success Criteria |
| 177 | +- ✅ SPM support working in Flutter projects |
| 178 | +- ✅ Full CocoaPods backward compatibility maintained |
| 179 | +- ✅ All existing functionality preserved |
| 180 | +- ✅ CI/CD tests both dependency managers |
| 181 | +- ✅ No breaking changes for existing users |
| 182 | +- ✅ Proper resource and privacy manifest handling |
0 commit comments