( swiftInterfaceFilePath: string, spmConfig: SPMConfig )
| 1290 | * @param spmConfig SPM configuration containing product/target mappings |
| 1291 | */ |
| 1292 | const fixSwiftInterfaceModuleReferencesAsync = async ( |
| 1293 | swiftInterfaceFilePath: string, |
| 1294 | spmConfig: SPMConfig |
| 1295 | ): Promise<void> => { |
| 1296 | // Read the swiftinterface file |
| 1297 | let content = await fs.readFile(swiftInterfaceFilePath, 'utf8'); |
| 1298 | let modified = false; |
| 1299 | |
| 1300 | // Remap internal SPM target imports to product names |
| 1301 | // e.g., @_exported import ExpoModulesCore_ios_objc -> @_exported import ExpoModulesCore |
| 1302 | for (const product of spmConfig.products) { |
| 1303 | for (const target of product.targets) { |
| 1304 | if (target.name === product.name) { |
| 1305 | continue; // Skip targets that have same name as product |
| 1306 | } |
| 1307 | |
| 1308 | // Replace @_exported import statements |
| 1309 | const exportedImportPattern = new RegExp(`^@_exported import ${target.name}\\s*$`, 'gm'); |
| 1310 | const exportedReplaced = content.replace( |
| 1311 | exportedImportPattern, |
| 1312 | `@_exported import ${product.name}` |
| 1313 | ); |
| 1314 | if (exportedReplaced !== content) { |
| 1315 | content = exportedReplaced; |
| 1316 | modified = true; |
| 1317 | } |
| 1318 | |
| 1319 | // Replace regular import statements |
| 1320 | const importPattern = new RegExp(`^import ${target.name}\\s*$`, 'gm'); |
| 1321 | const importReplaced = content.replace(importPattern, `import ${product.name}`); |
| 1322 | if (importReplaced !== content) { |
| 1323 | content = importReplaced; |
| 1324 | modified = true; |
| 1325 | } |
| 1326 | |
| 1327 | // Replace module-qualified type references |
| 1328 | // e.g., ExpoModulesCore_ios_objc.TypeName -> ExpoModulesCore.TypeName |
| 1329 | const qualifiedPattern = new RegExp(`\\b${target.name}\\.`, 'g'); |
| 1330 | const qualifiedReplaced = content.replace(qualifiedPattern, `${product.name}.`); |
| 1331 | if (qualifiedReplaced !== content) { |
| 1332 | content = qualifiedReplaced; |
| 1333 | modified = true; |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | // Write back if modified |
| 1339 | if (modified) { |
| 1340 | await fs.writeFile(swiftInterfaceFilePath, content, 'utf8'); |
| 1341 | } |
| 1342 | }; |
| 1343 | |
| 1344 | /** |
| 1345 | * Post-processes a generated ProductName-Swift.h header to remove or fix internal SPM |
no test coverage detected
searching dependent graphs…