Repository navigation
Conversation
Converting an app to SwiftPM with `--deintegrate` now moves the Podfile to Podfile.bak instead of deleting React Native lines from it (that edit left invalid Ruby for multi-line calls). `spm deinit` restores the Podfile, undoes the .gitignore lines the conversion wrote, removes empty ReactNativeSPM folders, and says to run `pod install`. The conversion refuses, before changing anything, when the Podfile has pods that are not React Native or when Podfile.bak already exists.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
SwiftPM is planned to become the default iOS setup, with CocoaPods as the opt-out. To be able to accomplish this, we want to keep the current templates with Cocoapods and do the opt-out through the
npx react-native spm deinitcommand - meaning that the cli will:For that, an app that was converted to SwiftPM must be able to fully go back to CocoaPods. Today it cannot:
spm add --deintegrate, also run by plainnpx react-native spmon a new app) deletes each Podfile line that names a React Native call. A call that spans several lines, such asuse_react_native!(…), loses only its first line. The Podfile is then invalid Ruby.spm deinitremoves SwiftPM from the Xcode project, but it does not touch the Podfile.This PR makes
npx react-native spm deinitthe way back to CocoaPods:pod deintegrate, then movesios/Podfiletoios/Podfile.bakwithout changes. The line editing is removed.Podfile.bakalready exists.spm deinitrestores the Podfile fromPodfile.bakand prints "Next step: runpod install". If both files exist, it stops and changes nothing.spm deinitundoes the.gitignorelines the conversion wrote. The conversion now records those lines in its marker file (.spm-injected.json), sodeinitremoves only them. Without a record,.gitignoreis not touched.spm deinitremoves theReactNativeSPMfolders that are empty after it deletes its files.The docs in
scripts/spm/__docs__describe the way back. They also say:REACT_NATIVE_PATH, anddeinitdoes not restore it.pod installsets it again for the whole project, throughreact_native_post_install. Only a Podfile without that call needs a manual check.@react-native-community/cli21 or newer. Older versions find the iOS project through the Podfile (see feat: detect Swift Package Manager projects react-native-community/cli#2858).Changelog:
[IOS] [CHANGED] -
react-native spmmoves the Podfile toPodfile.bakwhen it converts an app to SwiftPM, andreact-native spm deinitrestores it, so an app can go back to CocoaPods.Test Plan:
Unit tests:
23 suites, 1183 tests pass. ESLint, Prettier and Flow are clean on the changed files.
A new app, outside the monorepo, on React Native 0.89.0-nightly-20261021-c7429b0e9 with CLI 21.0.0-alpha.1. The three changed script files were copied into
node_modules/react-native/scripts.npx react-native spmconverts the app.ios/Podfile.bakis the same as the original Podfile.main.jsbundle.npx react-native spm deinitrestores the Podfile with the same content. It removes the.gitignoreit created, theReactNativeSPMfolder and the marker. No SwiftPM entries remain in the Xcode project.cd ios && pod installsucceeds.main.jsbundle, andREACT_NATIVE_PATHresolves to the app'snode_modules/react-native.private/helloworldin the monorepo: the same round trip passed through the CocoaPods Debug build. A secondspm add --deintegratestopped with "Nothing was changed".Not checked: a CocoaPods Release build of helloworld. My checkout setup made Metro fail while it bundled. The same build works in the new app above.