diff --git a/plugin/__tests__/withAndroidPushNotifications.test.ts b/plugin/__tests__/withAndroidPushNotifications.test.ts index d4d1fdc..b9e50ea 100644 --- a/plugin/__tests__/withAndroidPushNotifications.test.ts +++ b/plugin/__tests__/withAndroidPushNotifications.test.ts @@ -218,64 +218,6 @@ describe('withAndroidPushNotifications', () => { expect(num).toBe(1); }); - it('should warn the user if the google-services.json file is not found', async () => { - const config = { - ...createTestConfig(), - android: { - ...createTestConfig().android, - googleServicesFile: undefined, - }, - }; - const props: ConfigPluginProps = { - autoConfigurePushNotifications: true, - }; - withIterable(config, props); - expect(WarningAggregator.addWarningAndroid).toHaveBeenCalledWith( - '@iterable/expo-plugin', - 'Path to google-services.json is not defined, so push notifications will not be enabled. To enable push notifications, please specify the `expo.android.googleServicesFile` field in app.json.' - ); - }); - - it('should copy google-services.json when path is defined', async () => { - const config = { - ...createTestConfig(), - _internal: { projectRoot }, - android: { - ...createTestConfig().android, - googleServicesFile: '__mocks__/google-services.json', - }, - }; - const props: ConfigPluginProps = { - autoConfigurePushNotifications: true, - }; - // Create the source file in the project root - const srcPath = path.resolve( - projectRoot, - '__mocks__/google-services.json' - ); - fs.mkdirSync(path.dirname(srcPath), { recursive: true }); - fs.writeFileSync(srcPath, '{}'); - const result = withIterable(config, props) as WithIterableResult; - const dangerousMod = result.mods.android.dangerous as Mod; - await dangerousMod({ - ...createMockAndroidDangerousModConfig(), - modRequest: { - projectRoot, - platformProjectRoot: path.resolve(projectRoot, 'android'), - modName: 'dangerous', - platform: 'android', - introspect: true, - }, - android: { - googleServicesFile: '__mocks__/google-services.json', - }, - }); - expect(mockCopyFile).toHaveBeenCalledWith( - srcPath, - path.resolve(projectRoot, 'android/app/google-services.json') - ); - }); - it('should warn when google-services.json path is not defined', async () => { const config = { ...createTestConfig(), @@ -290,28 +232,10 @@ describe('withAndroidPushNotifications', () => { withIterable(config, props); expect(WarningAggregator.addWarningAndroid).toHaveBeenCalledWith( '@iterable/expo-plugin', - 'Path to google-services.json is not defined, so push notifications will not be enabled. To enable push notifications, please specify the `expo.android.googleServicesFile` field in app.json.' + 'The path to your google-services.json file is not defined, so push notifications may not work. Please add the path to your google-services.json file in the `expo.android.googleServicesFile` field in your app.json.' ); expect(mockCopyFile).not.toHaveBeenCalled(); }); - - it('should throw error when google-services.json does not exist', async () => { - const config = createTestConfig(); - const props: ConfigPluginProps = { - autoConfigurePushNotifications: true, - }; - mockCopyFile.mockRejectedValueOnce(new Error('File not found')); - const result = withIterable(config, props) as WithIterableResult; - const dangerousMod = result.mods.android.dangerous as Mod; - await expect( - dangerousMod({ - ...createMockAndroidDangerousModConfig(), - android: { - googleServicesFile: './google-services.json', - }, - }) - ).rejects.toThrow('Cannot copy google-services.json'); - }); }); }); diff --git a/plugin/src/withPushNotifications/withAndroidPushNotifications.constants.ts b/plugin/src/withPushNotifications/withAndroidPushNotifications.constants.ts index 06eadfd..4ef614e 100644 --- a/plugin/src/withPushNotifications/withAndroidPushNotifications.constants.ts +++ b/plugin/src/withPushNotifications/withAndroidPushNotifications.constants.ts @@ -7,5 +7,3 @@ export const FIREBASE_BOM_VERSION = '32.8.1'; export const FIREBASE_MESSAGING_CLASS_PATH = 'com.google.firebase:firebase-messaging'; - -export const DEFAULT_GOOGLE_SERVICES_PATH = 'app/google-services.json'; diff --git a/plugin/src/withPushNotifications/withAndroidPushNotifications.ts b/plugin/src/withPushNotifications/withAndroidPushNotifications.ts index 0e6865d..14e7fb4 100644 --- a/plugin/src/withPushNotifications/withAndroidPushNotifications.ts +++ b/plugin/src/withPushNotifications/withAndroidPushNotifications.ts @@ -3,16 +3,12 @@ import { WarningAggregator, withAndroidManifest, withAppBuildGradle, - withDangerousMod, withPlugins, withProjectBuildGradle, } from 'expo/config-plugins'; -import fs from 'fs'; -import path from 'path'; import { ConfigPluginPropsWithDefaults } from '../withIterable.types'; import { - DEFAULT_GOOGLE_SERVICES_PATH, FIREBASE_BOM_CLASS_PATH, FIREBASE_BOM_VERSION, FIREBASE_MESSAGING_CLASS_PATH, @@ -124,59 +120,19 @@ const withAppPermissions: ConfigPlugin = ( }); }; -/** - * Copy `google-services.json` - * TODO: Add this step to the docs - */ -const withCopyAndroidGoogleServices: ConfigPlugin = (config) => { - return withDangerousMod(config, [ - 'android', - async (newConfig) => { - const srcPath = path.resolve( - newConfig.modRequest.projectRoot, - newConfig.android?.googleServicesFile ?? '' - ); - const destPath = path.resolve( - newConfig.modRequest.platformProjectRoot, - DEFAULT_GOOGLE_SERVICES_PATH - ); - - try { - await fs.promises.copyFile(srcPath, destPath); - } catch { - throw new Error( - `Cannot copy google-services.json, because the file ${srcPath} doesn't exist. Please provide a valid path in \`app.json\`.` - ); - } - return newConfig; - }, - ]); -}; - -const withGoogleServices: ConfigPlugin = ( - config, - props -) => { +export const withAndroidPushNotifications: ConfigPlugin< + ConfigPluginPropsWithDefaults +> = (config, props) => { if (!config.android?.googleServicesFile) { WarningAggregator.addWarningAndroid( '@iterable/expo-plugin', - 'Path to google-services.json is not defined, so push notifications will not be enabled. To enable push notifications, please specify the `expo.android.googleServicesFile` field in app.json.' + 'The path to your google-services.json file is not defined, so push notifications may not work. Please add the path to your google-services.json file in the `expo.android.googleServicesFile` field in your app.json.' ); - return config; } - return withPlugins(config, [ - [withFirebase, props], - [withCopyAndroidGoogleServices, props], - ]); -}; - -export const withAndroidPushNotifications: ConfigPlugin< - ConfigPluginPropsWithDefaults -> = (config, props) => { return withPlugins(config, [ [withAppPermissions, props], - [withGoogleServices, props], + [withFirebase, props], ]); };