-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make react-native link
play nicely with CocoaPods-based iOS projects.
#15460
Conversation
@facebook-github-bot label Documentation Attention: @hramos, @grabbou, @Kureev Generated by 🚫 dangerJS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me! I'd even say very good. Documentation, test coverage - everything is there. I only need some time in order to test it before I give my approval.
@mironiasty once again, great job 🙌 Really enjoy reviewing high-quality PRs |
@Kureev Thanks :) Also another way to test it, is to create Expo project, and then use |
This looks really solid. Let me get back to you on that tomorrow latest. Pretty sure will be flawless :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, sorry for taking that much time for review.
I've made a quick test an it works flawless.
After @grabbou double-check this, we're confident to merge it in
* Unregister native module IOS with CocoaPods | ||
*/ | ||
module.exports = function unregisterNativeModule(dependencyConfig, iOSProject) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe empty line here and on line 14 is not intended? (nitpick)
module.exports = function unregisterNativeModule(dependencyConfig, iOSProject) { | ||
|
||
const podContent = fs.readFileSync(iOSProject.podfile, 'utf8'); | ||
const removed = removePodEntry(podContent, dependencyConfig.podspec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removing, shall we also call pod install
to sync the project? What happens right now after you unlink?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't call pod install
anywhere. It is up to user to call it later on (it could be also run automatically in build process/Xcode). Right now link/unlink processes only modify configuration files (and with this change only modify Podfile
file).
const nextTarget = /target (\'|\")\w+(\'|\") do/g; | ||
// match line that has only 'end' (if we don't catch new target or function, this would mean this is end of current target) | ||
const endOfCurrentTarget = /^\s*end\s*$/g; | ||
// match function defeinition, like: post_install do |installer| (some Podfiles have function defined inside main target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo in definition
|
||
module.exports = function findLineToAddPod(podLines, firstTargetLine){ | ||
|
||
// match line with new targe: target 'project_name' do (most likely target inside podfile main target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo in target
'use strict'; | ||
|
||
module.exports = function findLineToAddPod(podLines, firstTargetLine){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: no need to include an empty line :)
local-cli/link/pods/addPodEntry.js
Outdated
const newEntry = `pod '${podName}', :path => '../node_modules/${nodePath}'\n`; | ||
|
||
if (!linesToAddEntry) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has wrong indentation. Try running prettier
for all the files in your PR (not sure if you have it integrated already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think this is a good start - in the future ,we might want to handle multiple targets in CocoaPods as well.
Last thing to improve here is to run prettier
on all files. Some of the files use tabs
for indentation.
Check if your editor has well configured prettier and editor-config.
Sorry for these tabs, I hope it is fixed now. (I've been working on other project with tabs, and priettier used that config on react-native files) |
@facebook-github-bot shipit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: The core React Native codebase already has full support for CocoaPods. However, `react-native link` doesn’t play nicely with CocoaPods, so installing third-party libs from the RN ecosystem is really hard. This change will allow to link projects that contains its own `.podspec` file to CocoaPods-based projects. In case `link` detect `Podfile` in `iOS` directory, it will look for related `.podspec` file in linked project directory, and add it to `Podfile`. If `Podfile` and `.podspec` files are not present, it will fall back to previous implementation. **Test Plan** 1. Build a React Native project where the iOS part uses CocoaPods to manage its dependencies. The most common scenario here is to have React Native be a Pod dependency, among others. 2. Install a RN-related library, that contains `.podspec` file, with `react-native link` (as an example it could be: [react-native-maps](https://github.com/airbnb/react-native-maps) 3. Building the resulting iOS workspace should succeed (and there should be new entry in `Podfile`) Closes #15460 Differential Revision: D6078649 Pulled By: hramos fbshipit-source-id: 9651085875892fd66299563ca0e42fb2bcc00825
Summary: The core React Native codebase already has full support for CocoaPods. However, `react-native link` doesn’t play nicely with CocoaPods, so installing third-party libs from the RN ecosystem is really hard. This change will allow to link projects that contains its own `.podspec` file to CocoaPods-based projects. In case `link` detect `Podfile` in `iOS` directory, it will look for related `.podspec` file in linked project directory, and add it to `Podfile`. If `Podfile` and `.podspec` files are not present, it will fall back to previous implementation. **Test Plan** 1. Build a React Native project where the iOS part uses CocoaPods to manage its dependencies. The most common scenario here is to have React Native be a Pod dependency, among others. 2. Install a RN-related library, that contains `.podspec` file, with `react-native link` (as an example it could be: [react-native-maps](https://github.com/airbnb/react-native-maps) 3. Building the resulting iOS workspace should succeed (and there should be new entry in `Podfile`) Closes #15460 Differential Revision: D6078649 Pulled By: hramos fbshipit-source-id: 9651085875892fd66299563ca0e42fb2bcc00825
One of the core maintainers of https://github.com/invertase/react-native-firebase here. We've spent the last year battling with RN's lack of integration with Cocoapods and the pain this causes our users. Having given up on the Cocoapods approach and switching to usage of Since this change, our
As such, this has fundamentally broken our on-boarding flow for new users and leaves us with only two options:
Neither of these are particularly viable alternatives and both involve compromises. As somebody that has tried to submit PRs to improve the build process customisability in the past (on the Android side), only for the PR to be completely ignored, it's incredibly frustrating to now be affected by a change that hasn't taken into consideration what this might mean for some libraries. |
One thing that might be worth to mention here: this change would only work for users that have Pods configured for their iOS project (so users without I don't know what is exact problem with linking your project using CocoaPods. If problem is related to missing react entries in Podfile, maybe you can recommend creating project with As for adding option to opt-out from linking podspecs: I can think of two ways of doing it:
I'm not sure which one would be better. Also adding any of them, would again increase complexity of linking process. |
@mironiasty thanks for your response. Our users need to configure pods in order to use the Firebase dependencies, as this is the approach that Google recommend and we don't want to deviate from it. We also categorically don't want to recommend people creating projects using Expo as a way of getting started. This has also caused us numerous problems down the line and is not a viable alternative given the large dependency that Regarding your options above:
A much better option (and one that keeps in sync with the rest of the rnpm settings) would be to allow this to be overridden as part of the package.json. For example, setting an
|
Summary: The core React Native codebase already has full support for CocoaPods. However, `react-native link` doesn’t play nicely with CocoaPods, so installing third-party libs from the RN ecosystem is really hard. This change will allow to link projects that contains its own `.podspec` file to CocoaPods-based projects. In case `link` detect `Podfile` in `iOS` directory, it will look for related `.podspec` file in linked project directory, and add it to `Podfile`. If `Podfile` and `.podspec` files are not present, it will fall back to previous implementation. **Test Plan** 1. Build a React Native project where the iOS part uses CocoaPods to manage its dependencies. The most common scenario here is to have React Native be a Pod dependency, among others. 2. Install a RN-related library, that contains `.podspec` file, with `react-native link` (as an example it could be: [react-native-maps](https://github.com/airbnb/react-native-maps) 3. Building the resulting iOS workspace should succeed (and there should be new entry in `Podfile`) Closes facebook/react-native#15460 Differential Revision: D6078649 Pulled By: hramos fbshipit-source-id: 9651085875892fd66299563ca0e42fb2bcc00825
The core React Native codebase already has full support for CocoaPods. However,
react-native link
doesn’t play nicely with CocoaPods, so installing third-party libs from the RN ecosystem is really hard.This change will allow to link projects that contains its own
.podspec
file to CocoaPods-based projects. In caselink
detectPodfile
iniOS
directory, it will look for related.podspec
file in linked project directory, and add it toPodfile
. IfPodfile
and.podspec
files are not present, it will fall back to previous implementation.Test Plan
.podspec
file, withreact-native link
(as an example it could be: react-native-mapsPodfile
)