https://github.com/geekbrother/pod-patch
Patching the Cocoa Pod specfiles in ReactNative projects.
https://github.com/geekbrother/pod-patch
cocoapods patch patching podspec react-native
Last synced: 4 months ago
JSON representation
Patching the Cocoa Pod specfiles in ReactNative projects.
- Host: GitHub
- URL: https://github.com/geekbrother/pod-patch
- Owner: geekbrother
- Created: 2021-09-28T22:06:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-20T12:17:57.000Z (about 2 years ago)
- Last Synced: 2025-02-03T21:48:09.726Z (4 months ago)
- Topics: cocoapods, patch, patching, podspec, react-native
- Language: Shell
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 💊 pod-patch [](https://badge.fury.io/js/pod-patch)
Patching the Pods `podspec` files in **React Native** projects with the version tracking and `Podfile` updates.
# Why
When developing something using Cocoapods packages in some cases you need to modify the Pod's `podspec` file. Often these cases are:
- Change the Pod dependency,
- Modify compilation flags, paths, parameters,
- Using the Pod with connected sources or libraries from another Pod.You can do it by hand, download `podspec` file, modify, it and point to the local `podspec` file at the main **Podfile**. But what if I say:
- That you need to patch a few Pods?
- Their versions are changing too?
- What if there are a bunch of the patched Pods with the different versions?How not forget what and where was patched and patch them on the new versions or Podfile changes?
**🎈 This small tool was created to solve this!**
# Configuration
### This tool is created for use in the **React Native** project.
As this tool doesn't require many parameters we are using the **convention over configuration** approach.
By default tool will look into the `native/ios/pod-patch` directory for the `.patch` files. The file name itself tells the tool which Pod and which version you want to patch the Pod's `podspec` and use it in your main Podfile.
The naming convention for the `.patch` files is `[email protected]` where `podName` is the name of the Pod and `version` is the Pod version to use for the patch apply.
For example, `native/ios/pod-patch/[email protected]` will tell that we want to apply patch from this file to the `gRPC-Core` podspec file for the `1.40.0` version.
Also, you can use it without a version. When using `native/ios/pod-patch/gRPC-Core.patch` tool will apply the patch from this file to the `gRPC-Core` pod with the version from your Podfile. When using without a version you need to have a record in the Podfile with the pod and version.
For example:
```ruby
target 'App' do
...
pod 'gRPC-Core', '1.40.0'
```You can have as many `.patch` files as you need, the tool will use all of them.
# Running
The tool can be executed as the `npx pod-patch` command in the `native` directory of your **React Native** project.
When running the tool will iterate through your `.patch` files checks if anything has changed and made some magic:
- Checks if there is no version conflicts in your `Podfile` and `.patch` file,
- Download a `podspec` file for your Pod from the [cocoapods git repo](https://github.com/CocoaPods/Specs/tree/master/Specs) to the `native/ios/pod-patch/.patched/{pod-name}/{pod-version}/` directory,
- Apply the patch from the `.patch` file to it,
- Changes the record for the patched **Pod** in the `Podfile` to point it to the local patched podspec. For example, the record for the `gRPC-Core` will automatically change to:```ruby
target 'App' do
...
pod 'gRPC-Core', :podspec => './pod-patch/.patched/gRPC-Core/1.40.0/gRPC-Core.podspec.json'
```The tool checks if the Pod is already patched.
If nothing changed from the already applied patches - it will do nothing.[](https://asciinema.org/a/t77IAxPy1ZEZ84MAesfE4K2Bv)
## Using with the `yarn` or `npm i`
A good practice is to use it linked with the running of `yarn` or `npm i` in the `native` directory in your install script in the `package.json` before the `pod install` execution.
This will updates/install the packages with the transparent checking if all of the Pod patches are up-to-date or need to be applied if something in the `.patch` file changed or `Podspec` has new changes in the pod dependency or version changes before the `pod install`.
If using this way with the `git` repo you can add `native/ios/pod-patch/.patched` directory to your `.gitignore`. Because when the tool runs it will check the existence of the local patched podspec files and create those that not exists.
# Pod version changing
In case when the Pod version changed but you already have a `.patch` file for the previous version and it is already applied, but you want to upgrade the Pod and patch to the new version there are three simple steps:
**First**, if your `.patch` file in the `native/ios/pod-patch` has a version format i.e. `[email protected]` you need to create a patch file for the new version i.e. `[email protected]`.
If the `.patch` file in the no-version format i.e. `gRPC-Core.patch` you do nothing here as this is an universal patch for all versions.
**Second**, you need to point to the new version of the Pod in your `Podfile`. For example, upgrading to 1.41.0, need to look like:
```ruby
target 'App' do
...
pod 'gRPC-Core', '1.41.0'
```**Third**, you need to run `npx pod-patch` from your `native` directory and the tool will create a new patched Pod and point Podfile to it 🙌.
If you have a version-agnostic `.patch` file, actually you only need to do a second step only (point to the new version at the Podfile) and just run the tool!
# Command line flags
- `-h`: Output the command usage help.
- `-v`: Output the script version.
- `-p`: Path to the directory where the `.patch` files are if it differs from the default `native/ios/pod-patch`.
- `-d`: Path to the `Podfile` if it differs from the default `native/ios/Podfile`.# Todo
- [ ] Resolving conflicts if there are a few patch files for one Pod present.