-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: Added Expo config plugin #5480
Conversation
This pull request is being automatically deployed with Vercel (learn more). react-native-firebase – ./🔍 Inspect: https://vercel.com/invertase/react-native-firebase/4sgzUQNvJ7TLSq9fyd56kL3NkRFR react-native-firebase-next – ./website_modular🔍 Inspect: https://vercel.com/invertase/react-native-firebase-next/2MZ4wNHK3hbYGd58CvHYJRZv9dXb [Deployment for 964c489 failed] |
From the best practices in Expo's config plugins documentation:
Wouldn't it then make more sense to direct users to fill in the Or if you really want to provide defaults do something like this in your plugin to still leverage the existing functionality somewhat: const DEFAULT_ANDROID_GOOGLE_SERVICES_PATH = './google-services.json';
const DEFAULT_IOS_GOOGLE_SERVICES_PATH = './GoogleService-Info.plist';
const withRnFirebase: ConfigPlugin<PluginProps> = (config) => {
config.android = config.android || {};
config.android.googleServicesFile =
config.android?.googleServicesFile ||
DEFAULT_ANDROID_GOOGLE_SERVICES_PATH;
config.ios = config.ios || {};
config.ios.googleServicesFile =
config.ios?.googleServicesFile ||
DEFAULT_IOS_GOOGLE_SERVICES_PATH;
return withPlugins(config, [
// iOS
withFirebaseAppDelegate,
// Android
withBuildscriptDependency,
withApplyGoogleServicesPlugin,
]);
}; |
Sorry I haven't had time to review yet - however! I built some infrastructure in the past which may help - if you follow the details link on the patches github actions check, you'll find a "patches.zip" artifact that is a full set of patch-package compatible files from last release to current main branch + this PR, so anyone can test it easily. I don't use Expo so I would love to see reports of success from anyone that tries it I'll do a quick scan to make sure you're not a rogue bitcoin miner abusing Github free services (I'm joking) then approve the CI run so it generates the patches |
Codecov Report
@@ Coverage Diff @@
## master #5480 +/- ##
============================================
- Coverage 71.46% 67.53% -3.93%
- Complexity 0 980 +980
============================================
Files 96 199 +103
Lines 4292 9639 +5347
Branches 923 1504 +581
============================================
+ Hits 3067 6509 +3442
- Misses 1128 2717 +1589
- Partials 97 413 +316 |
@mikehardy Thanks, it helped a bit :) In the Test Plan section I prepared an instruction for anyone who wants to test it and prepared ready-to-go patched packages. Regarding other CI tests - i had to add @GertSallaerts yes I considered that. Honestly, most functionality of the Edit: Ok, it is clear now (see Evan's review below). We should rely on the built-in Expo config fields ( And this is also the reason why the copying functionality should be implemented here - the expo-cli built-in one is treats these values as optional and just skips copying if they're absent. |
packages/app/plugin/src/index.ts
Outdated
* Custom location of `google-services.json`, | ||
* relative to project root | ||
*/ | ||
androidGoogleServicesPath?: string; |
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.
For now, maybe just rely on the Expo CLI built-in values since they could be used across Google Sign-in and other packages. This will reduce initial complexity in the config plugin as well.
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.
That's a lot better for the review + fixup, thanks @EvanBacon @barthap
I want to be clear that while I am certainly Expo-curious, and I am really excited that RNFB will now be more easily integrated into Expo, I will need help with user support and fixups in the area.
All of my support is based on knowledge of react-native built from npx react-native init
and going from there 😅 . So, I will really need help in this area with any documentation or user support you can provide when the inevitable user questions arise 🙏 🙏
That actually makes me a bit nervous, but "fear of more users with legitimate questions" is no reason to hold up a PR in my opinion, so I'll merge this and let's go!
In such cases, just ping me or somebody at Expo, we'll try to help 😄 |
Thanks for this @barthap - would you also be able to update https://github.com/invertase/react-native-firebase/blob/master/docs/index.md#expo - it's quite out of date 😅 |
Yeah, that's my plan 😄 I'll open a PR probably on Monday |
Thanks! |
Thanks for the help here @barthap @EvanBacon 👍 |
* Preparations & Added the `app` plugin * Add perf monitoring plugin * Add crashlytics plugin * eslint ignore `plugin/build` dirs * Add tests READMEs
Thanks all for pushing this upstream. For other packages like |
Oops, I just saw the comment regarding packages without native code linking need not a plugin. On a side note: is it necessary to include |
I haven't dug into the issue itself, but if this dependency is needed for FCM / Notifications, the proper place for it would be the If you really need to include that dependency for notifications to work, the easiest workaround would be to write your own plugin (I replied in the forum thread). |
Worth noting, |
Do we have config plugin for messaging? |
No, but if you mean to customize notification icons, please take look at this discussion: barthap/with-rn-firebase#6 - you can "steal" |
Unrelated, looks like the dependency (expo-plugin) has a semver major to adopt. Is there anything we need to do here? Will it transitively cause a semver major here? Hadn't considered that this dependency might cause us to do majors, hopefully avoidable but if not so be it, I have another breaking change in the wings if so |
honestly I don't know, cc @EvanBacon |
when I tried to look (it came out a couple weeks ago) I have to say as an "expo-plugins" consumer, I was completely unable to find any CHANGELOG or commit diff or anything on it (I'm not even sure where the code is? I couldn't find it in the repo?) so it wasn't a smooth-n-easy consumer situation. If the package.json for it could actually point to the real location of expo-plugins (vs the general expo/expo repo) and there was a real changelog, I could have just done the migration... |
the changelog for config-plugins lives inside of the expo-cli repo (where config-plugins lives also): https://github.com/expo/expo-cli/blob/master/CHANGELOG.md the major version bump was due to the "extend base mods" feature landing, which adds to the public api. we bumped the major version because this shifted around the internals in a meaningful way and we are not entirely sure on the extent to which developers may have been depending on undocumented apis. |
Sweet! Thanks for the CHANGELOG pointer, that will help. Thanks also for the change insight, I don't think we were doing anything fancy at all in here, so this is likely safe for us to ingest then. |
@barthap , I am looking for imageUrl in notifications... https://firebase.google.com/docs/cloud-messaging/ios/send-image Can this plugin be extended to include the image in notifications. (not for the icon) |
Description
Expo released development clients and rolled out an interface called config plugins. These allow users to add native modules which aren't included in Expo Go.
This PR adds a config plugin, which allows users for painless setup of RNFB, without touching any native code. Until now, I've been maintaining the plugin as a separate npm package:
with-rn-firebase
and had some positive feedback. Now it's time to integrate it into the upstream library 😄 For more context, see the discussion at #5386.Basically I've copied my code from https://github.com/barthap/with-rn-firebase, but I've split it into separate plugins for each affected package to avoid additional config like setting
enableCrashlytics
etc.RNFB repo related changes:
build:plugin
andlint:plugin
npm scripts for affected packagesbuild:plugin
is run duringnpm prepare
phaseplugin/__tests__
directories with some basic tests, they work when runningnpm run tests:jest
tsconfig.json
to addesModuleInterop: true
- otherwise the plugin tests failed. I haven't seen any regressions and hope it's not breaking - please correct me if it is.@expo/config-plugins
and devDependency with plugin tsconfig base.packages/**/plugin/build
dir to eslint and prettier ignore - it's a generated directorysdkVersions
section inapp/package.json
For the plugin to work, the package should have a
app.plugin.js
file in its root folder - in this case it only delegates to theplugin/build
directory. Thebuild
directory is gitignored and generated duringnpm build:plugin
from TypeScript files insideplugin/src
.The plugins
As for now, to reflect current
with-rn-firebase
functionality, I've added plugins for 3 packages:App:
Its purpose is to copy
google-services.json
andGoogleServices-Info.plist
into correct places, modifyAppDelegate.m
, and add Gradle dependency and plugin - basically the installation steps from the homepage.The Google Services files by default are copied from the paths specified by
expo.ios|android.googleServicesFile
inapp.json
.Crashlytics:
Installs the required Gradle dependencies for Android. It doesn't yet support the optional release NDK installation step.
Performance Monitoring:
Installs the required Gradle dependency for Android.
Usage / How it works
When using Expo, replace the
yarn add
/npm install
withexpo install
:Then in the
app.json
theplugins
section should be updated automatically. When not usingexpo install
, you have to add the plugins on your own`.Remember to configure the
expo.android.googleServicesFile
andexpo.ios.googleServicesFile
inapp.json
. The paths are relative to the project root.The
app.json
file may look like this (non-related parts omitted):Further steps
After this PR is merged:
Expo
section and possibly the installation steps for the packages:app
,perf
,crashlytics
These were not included in my original plugin, they're not implemented yet:
FCM
module (see the discussion in Missing notification icon config in AndroidManifest.xml barthap/with-rn-firebase#6)Podfile
changes, which are not trivial for config plugins.Related issues
Discussion #5386
Release Summary
Checklist
Android
iOS
e2e
tests added or updated inpackages/\*\*/e2e
jest
tests added or updated inpackages/\*\*/__tests__
(added tests for config plugins)Test Plan
Steps that anyone should be able to reproduce:
patched-packages.zip
expo init app_name_here
- selected managed templateexpo prebuild
on this projectgit commit
your changesyarn link
all 3 RNFB packages into Expo app projectplugins
section toapp.json
. If you have Expo Tools VSCode extension, the intellisense should propose them automaticallygoogle-services.json
andGoogleService-Info.plist
(e.g. in app root dir) and specify theexpo.android.googleServicesFile
andexpo.ios.googleServicesFile
fields inapp.json
.git commit
again to have a checkpoint to easy resetexpo prebuild
and observe the git diff. Experiment with different combinations ofplugins
in app.json