This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[install-expo-modules] Replace xcode with xcparse (#4554)
# Why `simple-plist@1.3.1` is a transitive dependency of the xcode package. it has [an incompatible issue](wollardj/simple-plist#58) with ncc. the issue is pending for a while without publishing newer version as latest dist-tag. that blocks us from updating install-expo-modules. # How replace xcode with the awesome xcparse. this pr introduces a `withXCParseXcodeProject` config-plugin internally. # Test Plan - ✅ unit test passed - ✅ manual test on a react-native 0.68 project - ✅ manual test on a react-native 0.69 project
- Loading branch information
Showing
6 changed files
with
119 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/install-expo-modules/src/plugins/ios/withXCParseXcodeProject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { BaseMods, ConfigPlugin, IOSConfig, Mod, withMod } from '@expo/config-plugins'; | ||
import fs from 'fs'; | ||
import { ISA, build as xcbuild, parse as xcparse } from 'xcparse'; | ||
import type { BuildSettings, XCBuildConfiguration, XcodeProject } from 'xcparse'; | ||
|
||
export type XCParseXcodeProject = Partial<XcodeProject>; | ||
|
||
export interface BuildSettingsExtended extends BuildSettings { | ||
SWIFT_OBJC_BRIDGING_HEADER?: string; | ||
} | ||
|
||
const MOD_NAME = 'xcparseXcodeproj'; | ||
|
||
export const withXCParseXcodeProjectBaseMod: ConfigPlugin = config => { | ||
return BaseMods.withGeneratedBaseMods(config, { | ||
platform: 'ios', | ||
skipEmptyMod: false, | ||
providers: { | ||
[MOD_NAME]: BaseMods.provider<XCParseXcodeProject>({ | ||
getFilePath({ modRequest: { projectRoot } }) { | ||
return IOSConfig.Paths.getPBXProjectPath(projectRoot); | ||
}, | ||
async read(filePath) { | ||
const content = await fs.promises.readFile(filePath, 'utf8'); | ||
const pbxproj = xcparse(content); | ||
return pbxproj; | ||
}, | ||
async write(filePath: string, { modResults }) { | ||
const content = xcbuild(modResults); | ||
await fs.promises.writeFile(filePath, content); | ||
}, | ||
}), | ||
}, | ||
}); | ||
}; | ||
|
||
export const withXCParseXcodeProject: ConfigPlugin<Mod<XCParseXcodeProject>> = (config, action) => { | ||
return withMod(config, { | ||
platform: 'ios', | ||
mod: MOD_NAME, | ||
action, | ||
}); | ||
}; | ||
|
||
export function getDesignatedSwiftBridgingHeaderFileReference( | ||
pbxproj: XCParseXcodeProject | ||
): string | null { | ||
for (const section of Object.values(pbxproj.objects ?? {})) { | ||
if (section.isa === ISA.XCBuildConfiguration) { | ||
const buildConfigSection = section as XCBuildConfiguration; | ||
const buildSettings = buildConfigSection.buildSettings as BuildSettingsExtended; | ||
if ( | ||
typeof buildSettings.PRODUCT_NAME !== 'undefined' && | ||
typeof buildSettings.SWIFT_OBJC_BRIDGING_HEADER === 'string' && | ||
buildSettings.SWIFT_OBJC_BRIDGING_HEADER | ||
) { | ||
return buildSettings.SWIFT_OBJC_BRIDGING_HEADER; | ||
} | ||
} | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters