Skip to content

Commit dae2c23

Browse files
committed
Fix two review findings in spm Podfile reading and deinit output
- A multi-line `pod` call with a blank or comment line in the middle no longer ends early, so a pod sourced from node_modules/react-native is not reported as a non-React Native pod. - `spm deinit` says to run `pod install` only when it removed the SwiftPM setup, and says `cd ios && pod install` when run from the JS root.
1 parent 0640f08 commit dae2c23

2 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎packages/react-native/scripts/setup-apple-spm.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ function podfilePodNames(appRoot /*: string */) /*: Array<string> */ {
779779
for (const line of fs.readFileSync(podfilePath, 'utf8').split('\n')) {
780780
// `#{` is Ruby string interpolation, not a comment. A line that ends in
781781
// `,` continues on the next one.
782-
const code = continued + line.split(/#(?!\{)/)[0].trimEnd();
782+
const code = (continued + line.split(/#(?!\{)/)[0]).trimEnd();
783783
if (code.endsWith(',')) {
784784
continued = code + ' ';
785785
} else {
@@ -1154,10 +1154,10 @@ async function main(argv /*:: ?: Array<string> */) /*: Promise<void> */ {
11541154
// removeSpmInjection drops the marker, and the record with it.
11551155
const gitignoreRecord =
11561156
xcodeprojPath != null ? readMarker(xcodeprojPath)?.gitignore : null;
1157-
if (
1157+
const removed =
11581158
xcodeprojPath != null &&
1159-
removeSpmInjection({appRoot, xcodeprojPath}).status === 'removed'
1160-
) {
1159+
removeSpmInjection({appRoot, xcodeprojPath}).status === 'removed';
1160+
if (removed && xcodeprojPath != null) {
11611161
log(`Removed SPM packages from ${path.basename(xcodeprojPath)}.`);
11621162
} else {
11631163
log('No SPM injection found — nothing to remove.');
@@ -1170,8 +1170,12 @@ async function main(argv /*:: ?: Array<string> */) /*: Promise<void> */ {
11701170
'Remove them by hand.',
11711171
);
11721172
}
1173-
if (fs.existsSync(path.join(appRoot, 'Podfile'))) {
1174-
log('To go back to CocoaPods, run `pod install`.');
1173+
if (removed && fs.existsSync(path.join(appRoot, 'Podfile'))) {
1174+
const podInstall =
1175+
appRoot === process.cwd()
1176+
? 'pod install'
1177+
: `cd ${path.relative(process.cwd(), appRoot)} && pod install`;
1178+
log(`To go back to CocoaPods, run \`${podInstall}\`.`);
11751179
}
11761180
return;
11771181
}

‎packages/react-native/scripts/spm/__tests__/setup-apple-spm-test.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,20 @@ describe('podfilePodNames', () => {
699699
).toEqual(['RNSVG', 'OCMock']);
700700
});
701701

702+
it('reads past blank and comment lines inside a continued pod statement', () => {
703+
expect(
704+
namesIn([
705+
" pod 'React-Core',",
706+
' # comment',
707+
" :path => '../node_modules/react-native/'",
708+
" pod 'React-RCTText',",
709+
'',
710+
" :path => '../node_modules/react-native/Libraries/Text'",
711+
" pod 'OCMock', '~> 3.9.1'",
712+
]),
713+
).toEqual(['OCMock']);
714+
});
715+
702716
it('keeps pods whose names use Ruby interpolation', () => {
703717
expect(
704718
namesIn([
@@ -1027,6 +1041,29 @@ describe('CocoaPods conversion', () => {
10271041
);
10281042
});
10291043

1044+
it('does not mention `pod install` when it removed nothing', async () => {
1045+
fs.writeFileSync(podfilePath, STOCK_PODFILE);
1046+
1047+
await main(['deinit']);
1048+
1049+
expect(output(logSpy)).not.toContain('pod install');
1050+
});
1051+
1052+
it('says where to run `pod install` when run from the JS root', async () => {
1053+
const iosDir = path.join(appRoot, 'ios');
1054+
fs.mkdirSync(iosDir);
1055+
fs.writeFileSync(path.join(appRoot, 'package.json'), '{}');
1056+
mkXcodeproj(iosDir, 'MyApp.xcodeproj');
1057+
mkInjectedXcodeproj(iosDir, 'MyApp.xcodeproj');
1058+
fs.writeFileSync(path.join(iosDir, 'Podfile'), STOCK_PODFILE);
1059+
1060+
await main(['deinit']);
1061+
1062+
expect(output(logSpy)).toContain(
1063+
'To go back to CocoaPods, run `cd ios && pod install`.',
1064+
);
1065+
});
1066+
10301067
it('still says to run `pod install` when removing an empty directory fails', async () => {
10311068
mkInjectedProject();
10321069
fs.mkdirSync(path.join(appRoot, 'ReactNativeSPM', 'Scripts'), {

0 commit comments

Comments
 (0)