@@ -30,17 +30,23 @@ const PROPS: RNGoogleMapsPlusExpoPluginProps = {
3030 googleMapsIosApiKey : 'ios-key' ,
3131} ;
3232
33- const LEGACY_APP_DELEGATE = `import UIKit
34- import React
33+ const LEGACY_PODFILE_BLOCK = `# @generated begin react-native-google-maps-svgkit-patch - expo prebuild (DO NOT MODIFY) sync-ed16ec228929e9f6bcce5f8654ab58fb1bdadeea
34+ require File.join(File.dirname(\`node --print "require.resolve('react-native-google-maps-plus/package.json')"\`), 'scripts', 'svgkit_patch')
35+ apply_svgkit_patch(installer)
36+ # @generated end react-native-google-maps-svgkit-patch
37+ ` ;
38+
39+ const LEGACY_APP_DELEGATE_IMPORT = `// @generated begin react-native-google-maps-import - expo prebuild (DO NOT MODIFY) sync-3b9e722debd3c073b9705963208f8121ec9f576c
40+ import GoogleMaps
41+ // @generated end react-native-google-maps-import
42+ ` ;
3543
36- @UIApplicationMain
37- class AppDelegate: UIResponder, UIApplicationDelegate {
38- var window: UIWindow?
44+ const LEGACY_APP_DELEGATE_INIT = `// @generated begin react-native-google-maps-init - expo prebuild (DO NOT MODIFY) sync-ed7def55dfd1b52fb685aa33a269aeb34fc6ab13
3945
40- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
41- return true
42- }
43- }
46+ if let apiKey = Bundle.main.object(forInfoDictionaryKey: "MAPS_API_KEY") as? String {
47+ GMSServices.provideAPIKey(apiKey)
48+ }
49+ // @generated end react-native-google-maps-init
4450` ;
4551
4652type PluginMods = {
@@ -54,7 +60,6 @@ type ApplyOptions = {
5460 infoPlist ?: Record < string , unknown > ;
5561 podfile ?: string ;
5662 appDelegate ?: string ;
57- appDelegateLanguage ?: string ;
5863} ;
5964
6065function readFixture ( name : string ) : string {
@@ -66,7 +71,6 @@ function applyPlugin({
6671 infoPlist = { } ,
6772 podfile = readFixture ( 'Podfile' ) ,
6873 appDelegate = readFixture ( 'AppDelegate.swift' ) ,
69- appDelegateLanguage = 'swift' ,
7074} : ApplyOptions = { } ) : PluginMods {
7175 const config = {
7276 name : 'example' ,
@@ -76,7 +80,7 @@ function applyPlugin({
7680 podfile : { path : 'ios/Podfile' , language : 'rb' , contents : podfile } ,
7781 appDelegate : {
7882 path : 'ios/AppDelegate.swift' ,
79- language : appDelegateLanguage ,
83+ language : 'swift' ,
8084 contents : appDelegate ,
8185 } ,
8286 } ,
@@ -94,7 +98,6 @@ function reapply(mods: PluginMods, props?: ApplyOptions['props']): PluginMods {
9498 infoPlist : mods . infoPlist ,
9599 podfile : mods . podfile . contents ,
96100 appDelegate : mods . appDelegate . contents ,
97- appDelegateLanguage : mods . appDelegate . language ,
98101 } ) ;
99102}
100103
@@ -147,76 +150,28 @@ describe('withIosGoogleMapsPlus', () => {
147150 ) ;
148151 } ) ;
149152
150- it ( 'injects the svgkit patch into the existing post_install block' , ( ) => {
151- const { contents } = applyPlugin ( { props : PROPS } ) . podfile ;
152-
153- expect ( contents ) . toContain (
154- `require File.join(File.dirname(\`node --print "require.resolve('react-native-google-maps-plus/package.json')"\`), 'scripts', 'svgkit_patch')`
155- ) ;
156- expect ( count ( contents , 'post_install do |installer|' ) ) . toBe ( 1 ) ;
157- expect ( contents . indexOf ( 'apply_svgkit_patch(installer)' ) ) . toBeGreaterThan (
158- contents . indexOf ( 'post_install do |installer|' )
159- ) ;
160- } ) ;
161-
162- it ( 'places the patch outside a nested if/end block from another plugin' , ( ) => {
163- const nestedEndPodfile = `platform :ios, '16.0'
164-
165- target 'Example' do
166- post_install do |installer|
167- if ENV['CI'] == 'true'
168- puts 'ci run'
169- end
170- react_native_post_install(installer)
171- end
172- end
173- ` ;
174- const { contents } = applyPlugin ( {
175- props : PROPS ,
176- podfile : nestedEndPodfile ,
177- } ) . podfile ;
178-
179- expect ( count ( contents , 'apply_svgkit_patch(installer)' ) ) . toBe ( 1 ) ;
180- expect ( contents . indexOf ( 'apply_svgkit_patch(installer)' ) ) . toBeLessThan (
181- contents . indexOf ( "if ENV['CI']" )
182- ) ;
183- } ) ;
184-
185- it ( 'appends a post_install block when the Podfile has none' , ( ) => {
186- const minimalPodfile = `platform :ios, '16.0'
187-
188- target 'Example' do
189- end
190- ` ;
191- const { contents } = applyPlugin ( {
192- props : PROPS ,
193- podfile : minimalPodfile ,
194- } ) . podfile ;
195-
196- expect ( count ( contents , 'post_install do |installer|' ) ) . toBe ( 1 ) ;
197- expect ( contents ) . toContain ( 'apply_svgkit_patch(installer)' ) ;
198- } ) ;
199-
200153 it ( 'is idempotent when applied twice' , ( ) => {
201154 const first = applyPlugin ( { props : PROPS } ) ;
202155 const second = reapply ( first , PROPS ) ;
203156
204157 expect ( second . podfile . contents ) . toBe ( first . podfile . contents ) ;
205158 } ) ;
206159
207- it ( 'stays idempotent when the first run had to append the post_install block' , ( ) => {
208- const minimalPodfile = `platform :ios, '16.0'
160+ it ( 'removes the svgkit patch block generated by previous versions' , ( ) => {
161+ const legacy = readFixture ( 'Podfile' ) . replace (
162+ 'post_install do |installer|\n' ,
163+ `post_install do |installer|\n${ LEGACY_PODFILE_BLOCK } `
164+ ) ;
165+ expect ( legacy ) . toContain ( 'apply_svgkit_patch(installer)' ) ;
209166
210- target 'Example' do
211- end
212- ` ;
213- const first = applyPlugin ( { props : PROPS , podfile : minimalPodfile } ) ;
214- const second = reapply ( first , PROPS ) ;
167+ const { contents } = applyPlugin ( {
168+ props : PROPS ,
169+ podfile : legacy ,
170+ } ) . podfile ;
215171
216- expect ( second . podfile . contents ) . toBe ( first . podfile . contents ) ;
217- expect (
218- count ( first . podfile . contents , 'apply_svgkit_patch(installer)' )
219- ) . toBe ( 1 ) ;
172+ expect ( contents ) . not . toContain ( 'svgkit_patch' ) ;
173+ expect ( contents ) . not . toContain ( 'react-native-google-maps-svgkit-patch' ) ;
174+ expect ( contents ) . toBe ( applyPlugin ( { props : PROPS } ) . podfile . contents ) ;
220175 } ) ;
221176
222177 it ( 'matches the snapshot for the current Expo template' , ( ) => {
@@ -226,66 +181,41 @@ end
226181 } ) ;
227182
228183 describe ( 'AppDelegate' , ( ) => {
229- it ( 'adds the GoogleMaps import after import React' , ( ) => {
184+ it ( 'leaves a clean AppDelegate untouched' , ( ) => {
185+ const fixture = readFixture ( 'AppDelegate.swift' ) ;
230186 const { contents } = applyPlugin ( { props : PROPS } ) . appDelegate ;
231187
232- expect ( count ( contents , 'import GoogleMaps' ) ) . toBe ( 1 ) ;
233- expect ( contents . indexOf ( 'import GoogleMaps' ) ) . toBeGreaterThan (
234- contents . indexOf ( 'import React' )
235- ) ;
188+ expect ( contents ) . toBe ( fixture ) ;
236189 } ) ;
237190
238- it ( 'initializes GMSServices inside didFinishLaunchingWithOptions before the super call' , ( ) => {
239- const { contents } = applyPlugin ( { props : PROPS } ) . appDelegate ;
240-
241- const initIndex = contents . indexOf ( 'GMSServices.provideAPIKey' ) ;
242- expect ( initIndex ) . toBeGreaterThan (
243- contents . indexOf ( 'didFinishLaunchingWithOptions' )
244- ) ;
245- expect ( initIndex ) . toBeLessThan (
246- contents . indexOf (
247- 'return super.application(application, didFinishLaunchingWithOptions: launchOptions)'
191+ it ( 'removes the import and init blocks generated by previous versions' , ( ) => {
192+ const legacy = readFixture ( 'AppDelegate.swift' )
193+ . replace (
194+ 'import React\n' ,
195+ `import React\n${ LEGACY_APP_DELEGATE_IMPORT } `
248196 )
249- ) ;
250- } ) ;
251-
252- it ( 'is idempotent when applied twice' , ( ) => {
253- const first = applyPlugin ( { props : PROPS } ) ;
254- const second = reapply ( first , PROPS ) ;
255-
256- expect ( second . appDelegate . contents ) . toBe ( first . appDelegate . contents ) ;
257- } ) ;
197+ . replace (
198+ / ^ ( \s * r e t u r n s u p e r \. a p p l i c a t i o n \( ) / m,
199+ `${ LEGACY_APP_DELEGATE_INIT } $1`
200+ ) ;
201+ expect ( legacy ) . toContain ( 'GMSServices.provideAPIKey' ) ;
258202
259- it ( 'falls back to the didFinishLaunchingWithOptions anchor when there is no super call' , ( ) => {
260203 const { contents } = applyPlugin ( {
261204 props : PROPS ,
262- appDelegate : LEGACY_APP_DELEGATE ,
205+ appDelegate : legacy ,
263206 } ) . appDelegate ;
264207
265- const initIndex = contents . indexOf ( 'GMSServices.provideAPIKey' ) ;
266- expect ( initIndex ) . toBeGreaterThan (
267- contents . indexOf ( 'didFinishLaunchingWithOptions' )
268- ) ;
269- expect ( initIndex ) . toBeLessThan ( contents . indexOf ( 'return true' ) ) ;
208+ expect ( contents ) . not . toContain ( 'import GoogleMaps' ) ;
209+ expect ( contents ) . not . toContain ( 'GMSServices' ) ;
210+ expect ( contents ) . not . toContain ( '@generated' ) ;
211+ expect ( contents ) . toBe ( readFixture ( 'AppDelegate.swift' ) ) ;
270212 } ) ;
271213
272- it ( 'skips injection and warns for a non-swift AppDelegate' , ( ) => {
273- const objcAppDelegate = '#import "AppDelegate.h"\n' ;
274- const { contents } = applyPlugin ( {
275- props : PROPS ,
276- appDelegate : objcAppDelegate ,
277- appDelegateLanguage : 'objcpp' ,
278- } ) . appDelegate ;
279-
280- expect ( contents ) . toBe ( objcAppDelegate ) ;
281- expect ( console . warn ) . toHaveBeenCalledWith (
282- expect . stringContaining ( 'AppDelegate is not Swift' )
283- ) ;
284- } ) ;
214+ it ( 'is idempotent when applied twice' , ( ) => {
215+ const first = applyPlugin ( { props : PROPS } ) ;
216+ const second = reapply ( first , PROPS ) ;
285217
286- it ( 'matches the snapshot for the current Expo template' , ( ) => {
287- const { contents } = applyPlugin ( { props : PROPS } ) . appDelegate ;
288- expect ( contents ) . toMatchSnapshot ( ) ;
218+ expect ( second . appDelegate . contents ) . toBe ( first . appDelegate . contents ) ;
289219 } ) ;
290220 } ) ;
291221} ) ;
0 commit comments