@expo/config-plugins 4.0.12 → 4.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/android/Manifest.d.ts +2 -0
- package/build/android/Manifest.js.map +1 -1
- package/build/android/Permissions.d.ts +2 -0
- package/build/android/Permissions.js +88 -3
- package/build/android/Permissions.js.map +1 -1
- package/build/ios/Maps.js +2 -2
- package/build/ios/Maps.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ declare type ManifestMetaDataAttributes = AndroidManifestAttributes & {
|
|
|
5
5
|
};
|
|
6
6
|
declare type AndroidManifestAttributes = {
|
|
7
7
|
'android:name': string | 'android.intent.action.VIEW';
|
|
8
|
+
'tools:node'?: string | 'remove';
|
|
8
9
|
};
|
|
9
10
|
declare type ManifestAction = {
|
|
10
11
|
$: AndroidManifestAttributes;
|
|
@@ -99,6 +100,7 @@ export declare type AndroidManifest = {
|
|
|
99
100
|
manifest: {
|
|
100
101
|
$: {
|
|
101
102
|
'xmlns:android': string;
|
|
103
|
+
'xmlns:tools'?: string;
|
|
102
104
|
package?: string;
|
|
103
105
|
[key: string]: string | undefined;
|
|
104
106
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/Manifest.ts"],"names":["writeAndroidManifestAsync","manifestPath","androidManifest","manifestXml","XML","format","fs","ensureDir","path","dirname","writeFile","readAndroidManifestAsync","xml","readXMLAsync","isManifest","Error","manifest","getMainApplication","application","filter","e","$","getMainApplicationOrThrow","mainApplication","getMainActivityOrThrow","mainActivity","getMainActivity","getRunnableActivity","enabledActivities","activity","Array","isArray","intentFilter","action","find","category","addMetaDataItemToMainApplication","itemName","itemValue","itemType","existingMetaDataItem","newItem","prefixAndroidKeys","name","length","push","removeMetaDataItemFromMainApplication","index","findMetaDataItem","splice","findApplicationSubItem","parent","findIndex","findUsesLibraryItem","getMainApplicationMetaDataValue","hasOwnProperty","item","addUsesLibraryItemToMainApplication","removeUsesLibraryItemFromMainApplication","head","Object","entries","reduce","prev","key","curr"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;AA8IO,eAAeA,yBAAf,CACLC,YADK,EAELC,eAFK,EAGU;AACf,QAAMC,WAAW,GAAGC,GAAG,GAACC,MAAJ,CAAWH,eAAX,CAApB;AACA,QAAMI,mBAAGC,SAAH,CAAaC,gBAAKC,OAAL,CAAaR,YAAb,CAAb,CAAN;AACA,QAAMK,mBAAGI,SAAH,CAAaT,YAAb,EAA2BE,WAA3B,CAAN;AACD;;AAEM,eAAeQ,wBAAf,CAAwCV,YAAxC,EAAwF;AAC7F,QAAMW,GAAG,GAAG,MAAMR,GAAG,GAACS,YAAJ,CAAiB;AAAEL,IAAAA,IAAI,EAAEP;AAAR,GAAjB,CAAlB;;AACA,MAAI,CAACa,UAAU,CAACF,GAAD,CAAf,EAAsB;AACpB,UAAM,IAAIG,KAAJ,CAAU,gCAAgCd,YAA1C,CAAN;AACD;;AACD,SAAOW,GAAP;AACD;;AAED,SAASE,UAAT,CAAoBF,GAApB,EAAgE;AAC9D;AACA,SAAO,CAAC,CAACA,GAAG,CAACI,QAAb;AACD;;AAEM,SAASC,kBAAT,CAA4Bf,eAA5B,EAA0F;AAAA;;AAC/F,kCACEA,eADF,aACEA,eADF,iDACEA,eAAe,CAAEc,QADnB,qFACE,uBAA2BE,WAD7B,2DACE,uBAAwCC,MAAxC,CACEC,CAAC;AAAA;;AAAA,WAAI,CAAAA,CAAC,SAAD,IAAAA,CAAC,WAAD,oBAAAA,CAAC,CAAEC,CAAH,8CAAO,cAAP,OAA2B,kBAA/B;AAAA,GADH,EAEE,CAFF,CADF,yEAGU,IAHV;AAKD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AAqD;AACnDxB,IAAAA,eAAe,CAAC,cAAD,CAAf,CAAgC0B,MAAhC,CAAuCF,KAAvC,EAA8C,CAA9C;AACD;;AACD,SAAOxB,eAAP;AACD;;AAEM,SAASmB,iBAAT,CACLiB,IADK,EAEgB;AACrB;AACA,SAAOC,MAAM,CAACC,OAAP,CAAeF,IAAf,EAAqBG,MAArB,CACL,CAACC,IAAD,EAAO,CAACC,GAAD,EAAMC,IAAN,CAAP,MAAwB,EAAE,GAAGF,IAAL;AAAW,KAAE,WAAUC,GAAI,EAAhB,GAAoBC;AAA/B,GAAxB,CADK,EAEL,EAFK,CAAP;AAID","sourcesContent":["import assert from 'assert';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport * as XML from '../utils/XML';\n\nexport type StringBoolean = 'true' | 'false';\n\ntype ManifestMetaDataAttributes = AndroidManifestAttributes & {\n 'android:value'?: string;\n 'android:resource'?: string;\n};\n\ntype AndroidManifestAttributes = {\n 'android:name': string | 'android.intent.action.VIEW';\n};\n\ntype ManifestAction = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestCategory = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestData = {\n $: {\n [key: string]: string | undefined;\n 'android:host'?: string;\n 'android:pathPrefix'?: string;\n 'android:scheme'?: string;\n };\n};\n\ntype ManifestReceiver = {\n $: AndroidManifestAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:enabled'?: StringBoolean;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\nexport type ManifestIntentFilter = {\n $?: {\n 'android:autoVerify'?: StringBoolean;\n 'data-generated'?: StringBoolean;\n };\n action?: ManifestAction[];\n data?: ManifestData[];\n category?: ManifestCategory[];\n};\n\nexport type ManifestMetaData = {\n $: ManifestMetaDataAttributes;\n};\n\ntype ManifestServiceAttributes = AndroidManifestAttributes & {\n 'android:enabled'?: StringBoolean;\n 'android:exported'?: StringBoolean;\n 'android:permission'?: string;\n // ...\n};\n\ntype ManifestService = {\n $: ManifestServiceAttributes;\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\ntype ManifestApplicationAttributes = {\n 'android:name': string | '.MainApplication';\n 'android:icon'?: string;\n 'android:label'?: string;\n 'android:allowBackup'?: StringBoolean;\n 'android:largeHeap'?: StringBoolean;\n 'android:requestLegacyExternalStorage'?: StringBoolean;\n 'android:usesCleartextTraffic'?: StringBoolean;\n [key: string]: string | undefined;\n};\n\nexport type ManifestActivity = {\n $: ManifestApplicationAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:launchMode'?: string;\n 'android:theme'?: string;\n 'android:windowSoftInputMode'?:\n | string\n | 'stateUnspecified'\n | 'stateUnchanged'\n | 'stateHidden'\n | 'stateAlwaysHidden'\n | 'stateVisible'\n | 'stateAlwaysVisible'\n | 'adjustUnspecified'\n | 'adjustResize'\n | 'adjustPan';\n [key: string]: string | undefined;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n // ...\n};\n\nexport type ManifestUsesLibrary = {\n $: AndroidManifestAttributes & {\n 'android:required'?: StringBoolean;\n };\n};\n\nexport type ManifestApplication = {\n $: ManifestApplicationAttributes;\n activity?: ManifestActivity[];\n service?: ManifestService[];\n receiver?: ManifestReceiver[];\n 'meta-data'?: ManifestMetaData[];\n 'uses-library'?: ManifestUsesLibrary[];\n // ...\n};\n\ntype ManifestPermission = {\n $: AndroidManifestAttributes & {\n 'android:protectionLevel'?: string | 'signature';\n };\n};\n\nexport type ManifestUsesPermission = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestUsesFeature = {\n $: AndroidManifestAttributes & {\n 'android:glEsVersion'?: string;\n 'android:required': StringBoolean;\n };\n};\n\nexport type AndroidManifest = {\n manifest: {\n // Probably more, but this is currently all we'd need for most cases in Expo.\n $: { 'xmlns:android': string; package?: string; [key: string]: string | undefined };\n permission?: ManifestPermission[];\n 'uses-permission'?: ManifestUsesPermission[];\n 'uses-permission-sdk-23'?: ManifestUsesPermission[];\n 'uses-feature'?: ManifestUsesFeature[];\n application?: ManifestApplication[];\n };\n};\n\nexport async function writeAndroidManifestAsync(\n manifestPath: string,\n androidManifest: AndroidManifest\n): Promise<void> {\n const manifestXml = XML.format(androidManifest);\n await fs.ensureDir(path.dirname(manifestPath));\n await fs.writeFile(manifestPath, manifestXml);\n}\n\nexport async function readAndroidManifestAsync(manifestPath: string): Promise<AndroidManifest> {\n const xml = await XML.readXMLAsync({ path: manifestPath });\n if (!isManifest(xml)) {\n throw new Error('Invalid manifest found at: ' + manifestPath);\n }\n return xml;\n}\n\nfunction isManifest(xml: XML.XMLObject): xml is AndroidManifest {\n // TODO: Maybe more validation\n return !!xml.manifest;\n}\n\nexport function getMainApplication(androidManifest: AndroidManifest): ManifestApplication | null {\n return (\n androidManifest?.manifest?.application?.filter(\n e => e?.$?.['android:name'] === '.MainApplication'\n )[0] ?? null\n );\n}\n\nexport function getMainApplicationOrThrow(androidManifest: AndroidManifest): ManifestApplication {\n const mainApplication = getMainApplication(androidManifest);\n assert(mainApplication, 'AndroidManifest.xml is missing the required MainApplication element');\n return mainApplication;\n}\n\nexport function getMainActivityOrThrow(androidManifest: AndroidManifest): ManifestActivity {\n const mainActivity = getMainActivity(androidManifest);\n assert(mainActivity, 'AndroidManifest.xml is missing the required MainActivity element');\n return mainActivity;\n}\n\nexport function getRunnableActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n // Get enabled activities\n const enabledActivities = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:enabled'] !== 'false' && e.$['android:enabled'] !== false\n );\n\n if (!enabledActivities) {\n return null;\n }\n\n // Get the activity that has a runnable intent-filter\n for (const activity of enabledActivities) {\n if (Array.isArray(activity['intent-filter'])) {\n for (const intentFilter of activity['intent-filter']) {\n if (\n intentFilter.action?.find(\n action => action.$['android:name'] === 'android.intent.action.MAIN'\n ) &&\n intentFilter.category?.find(\n category => category.$['android:name'] === 'android.intent.category.LAUNCHER'\n )\n ) {\n return activity;\n }\n }\n }\n }\n\n return null;\n}\n\nexport function getMainActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n const mainActivity = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:name'] === '.MainActivity'\n );\n return mainActivity?.[0] ?? null;\n}\n\nexport function addMetaDataItemToMainApplication(\n mainApplication: ManifestApplication,\n itemName: string,\n itemValue: string,\n itemType: 'resource' | 'value' = 'value'\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys({ name: itemName, [itemType]: itemValue }),\n } as ManifestMetaData;\n if (mainApplication['meta-data']) {\n existingMetaDataItem = mainApplication['meta-data'].filter(\n (e: any) => e.$['android:name'] === itemName\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$[\n `android:${itemType}` as keyof ManifestMetaDataAttributes\n ] = itemValue;\n } else {\n mainApplication['meta-data'].push(newItem);\n }\n } else {\n mainApplication['meta-data'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeMetaDataItemFromMainApplication(mainApplication: any, itemName: string) {\n const index = findMetaDataItem(mainApplication, itemName);\n if (mainApplication?.['meta-data'] && index > -1) {\n mainApplication['meta-data'].splice(index, 1);\n }\n return mainApplication;\n}\n\nfunction findApplicationSubItem(\n mainApplication: ManifestApplication,\n category: keyof ManifestApplication,\n itemName: string\n): number {\n const parent = mainApplication[category];\n if (Array.isArray(parent)) {\n const index = parent.findIndex((e: any) => e.$['android:name'] === itemName);\n\n return index;\n }\n return -1;\n}\n\nexport function findMetaDataItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'meta-data', itemName);\n}\n\nexport function findUsesLibraryItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'uses-library', itemName);\n}\n\nexport function getMainApplicationMetaDataValue(\n androidManifest: AndroidManifest,\n name: string\n): string | null {\n const mainApplication = getMainApplication(androidManifest);\n\n if (mainApplication?.hasOwnProperty('meta-data')) {\n const item = mainApplication?.['meta-data']?.find((e: any) => e.$['android:name'] === name);\n return item?.$['android:value'] ?? null;\n }\n\n return null;\n}\n\nexport function addUsesLibraryItemToMainApplication(\n mainApplication: ManifestApplication,\n item: { name: string; required?: boolean }\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys(item),\n } as ManifestUsesLibrary;\n\n if (mainApplication['uses-library']) {\n existingMetaDataItem = mainApplication['uses-library'].filter(\n e => e.$['android:name'] === item.name\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$ = newItem.$;\n } else {\n mainApplication['uses-library'].push(newItem);\n }\n } else {\n mainApplication['uses-library'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeUsesLibraryItemFromMainApplication(\n mainApplication: ManifestApplication,\n itemName: string\n) {\n const index = findUsesLibraryItem(mainApplication, itemName);\n if (mainApplication?.['uses-library'] && index > -1) {\n mainApplication['uses-library'].splice(index, 1);\n }\n return mainApplication;\n}\n\nexport function prefixAndroidKeys<T extends Record<string, any> = Record<string, string>>(\n head: T\n): Record<string, any> {\n // prefix all keys with `android:`\n return Object.entries(head).reduce(\n (prev, [key, curr]) => ({ ...prev, [`android:${key}`]: curr }),\n {} as T\n );\n}\n"],"file":"Manifest.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/android/Manifest.ts"],"names":["writeAndroidManifestAsync","manifestPath","androidManifest","manifestXml","XML","format","fs","ensureDir","path","dirname","writeFile","readAndroidManifestAsync","xml","readXMLAsync","isManifest","Error","manifest","getMainApplication","application","filter","e","$","getMainApplicationOrThrow","mainApplication","getMainActivityOrThrow","mainActivity","getMainActivity","getRunnableActivity","enabledActivities","activity","Array","isArray","intentFilter","action","find","category","addMetaDataItemToMainApplication","itemName","itemValue","itemType","existingMetaDataItem","newItem","prefixAndroidKeys","name","length","push","removeMetaDataItemFromMainApplication","index","findMetaDataItem","splice","findApplicationSubItem","parent","findIndex","findUsesLibraryItem","getMainApplicationMetaDataValue","hasOwnProperty","item","addUsesLibraryItemToMainApplication","removeUsesLibraryItemFromMainApplication","head","Object","entries","re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,CAAf,CAAgC0B,MAAhC,CAAuCF,KAAvC,EAA8C,CAA9C;AACD;;AACD,SAAOxB,eAAP;AACD;;AAEM,SAASmB,iBAAT,CACLiB,IADK,EAEgB;AACrB;AACA,SAAOC,MAAM,CAACC,OAAP,CAAeF,IAAf,EAAqBG,MAArB,CACL,CAACC,IAAD,EAAO,CAACC,GAAD,EAAMC,IAAN,CAAP,MAAwB,EAAE,GAAGF,IAAL;AAAW,KAAE,WAAUC,GAAI,EAAhB,GAAoBC;AAA/B,GAAxB,CADK,EAEL,EAFK,CAAP;AAID","sourcesContent":["import assert from 'assert';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport * as XML from '../utils/XML';\n\nexport type StringBoolean = 'true' | 'false';\n\ntype ManifestMetaDataAttributes = AndroidManifestAttributes & {\n 'android:value'?: string;\n 'android:resource'?: string;\n};\n\ntype AndroidManifestAttributes = {\n 'android:name': string | 'android.intent.action.VIEW';\n 'tools:node'?: string | 'remove';\n};\n\ntype ManifestAction = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestCategory = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestData = {\n $: {\n [key: string]: string | undefined;\n 'android:host'?: string;\n 'android:pathPrefix'?: string;\n 'android:scheme'?: string;\n };\n};\n\ntype ManifestReceiver = {\n $: AndroidManifestAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:enabled'?: StringBoolean;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\nexport type ManifestIntentFilter = {\n $?: {\n 'android:autoVerify'?: StringBoolean;\n 'data-generated'?: StringBoolean;\n };\n action?: ManifestAction[];\n data?: ManifestData[];\n category?: ManifestCategory[];\n};\n\nexport type ManifestMetaData = {\n $: ManifestMetaDataAttributes;\n};\n\ntype ManifestServiceAttributes = AndroidManifestAttributes & {\n 'android:enabled'?: StringBoolean;\n 'android:exported'?: StringBoolean;\n 'android:permission'?: string;\n // ...\n};\n\ntype ManifestService = {\n $: ManifestServiceAttributes;\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\ntype ManifestApplicationAttributes = {\n 'android:name': string | '.MainApplication';\n 'android:icon'?: string;\n 'android:label'?: string;\n 'android:allowBackup'?: StringBoolean;\n 'android:largeHeap'?: StringBoolean;\n 'android:requestLegacyExternalStorage'?: StringBoolean;\n 'android:usesCleartextTraffic'?: StringBoolean;\n [key: string]: string | undefined;\n};\n\nexport type ManifestActivity = {\n $: ManifestApplicationAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:launchMode'?: string;\n 'android:theme'?: string;\n 'android:windowSoftInputMode'?:\n | string\n | 'stateUnspecified'\n | 'stateUnchanged'\n | 'stateHidden'\n | 'stateAlwaysHidden'\n | 'stateVisible'\n | 'stateAlwaysVisible'\n | 'adjustUnspecified'\n | 'adjustResize'\n | 'adjustPan';\n [key: string]: string | undefined;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n // ...\n};\n\nexport type ManifestUsesLibrary = {\n $: AndroidManifestAttributes & {\n 'android:required'?: StringBoolean;\n };\n};\n\nexport type ManifestApplication = {\n $: ManifestApplicationAttributes;\n activity?: ManifestActivity[];\n service?: ManifestService[];\n receiver?: ManifestReceiver[];\n 'meta-data'?: ManifestMetaData[];\n 'uses-library'?: ManifestUsesLibrary[];\n // ...\n};\n\ntype ManifestPermission = {\n $: AndroidManifestAttributes & {\n 'android:protectionLevel'?: string | 'signature';\n };\n};\n\nexport type ManifestUsesPermission = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestUsesFeature = {\n $: AndroidManifestAttributes & {\n 'android:glEsVersion'?: string;\n 'android:required': StringBoolean;\n };\n};\n\nexport type AndroidManifest = {\n manifest: {\n // Probably more, but this is currently all we'd need for most cases in Expo.\n $: {\n 'xmlns:android': string;\n 'xmlns:tools'?: string;\n package?: string;\n [key: string]: string | undefined;\n };\n permission?: ManifestPermission[];\n 'uses-permission'?: ManifestUsesPermission[];\n 'uses-permission-sdk-23'?: ManifestUsesPermission[];\n 'uses-feature'?: ManifestUsesFeature[];\n application?: ManifestApplication[];\n };\n};\n\nexport async function writeAndroidManifestAsync(\n manifestPath: string,\n androidManifest: AndroidManifest\n): Promise<void> {\n const manifestXml = XML.format(androidManifest);\n await fs.ensureDir(path.dirname(manifestPath));\n await fs.writeFile(manifestPath, manifestXml);\n}\n\nexport async function readAndroidManifestAsync(manifestPath: string): Promise<AndroidManifest> {\n const xml = await XML.readXMLAsync({ path: manifestPath });\n if (!isManifest(xml)) {\n throw new Error('Invalid manifest found at: ' + manifestPath);\n }\n return xml;\n}\n\nfunction isManifest(xml: XML.XMLObject): xml is AndroidManifest {\n // TODO: Maybe more validation\n return !!xml.manifest;\n}\n\nexport function getMainApplication(androidManifest: AndroidManifest): ManifestApplication | null {\n return (\n androidManifest?.manifest?.application?.filter(\n e => e?.$?.['android:name'] === '.MainApplication'\n )[0] ?? null\n );\n}\n\nexport function getMainApplicationOrThrow(androidManifest: AndroidManifest): ManifestApplication {\n const mainApplication = getMainApplication(androidManifest);\n assert(mainApplication, 'AndroidManifest.xml is missing the required MainApplication element');\n return mainApplication;\n}\n\nexport function getMainActivityOrThrow(androidManifest: AndroidManifest): ManifestActivity {\n const mainActivity = getMainActivity(androidManifest);\n assert(mainActivity, 'AndroidManifest.xml is missing the required MainActivity element');\n return mainActivity;\n}\n\nexport function getRunnableActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n // Get enabled activities\n const enabledActivities = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:enabled'] !== 'false' && e.$['android:enabled'] !== false\n );\n\n if (!enabledActivities) {\n return null;\n }\n\n // Get the activity that has a runnable intent-filter\n for (const activity of enabledActivities) {\n if (Array.isArray(activity['intent-filter'])) {\n for (const intentFilter of activity['intent-filter']) {\n if (\n intentFilter.action?.find(\n action => action.$['android:name'] === 'android.intent.action.MAIN'\n ) &&\n intentFilter.category?.find(\n category => category.$['android:name'] === 'android.intent.category.LAUNCHER'\n )\n ) {\n return activity;\n }\n }\n }\n }\n\n return null;\n}\n\nexport function getMainActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n const mainActivity = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:name'] === '.MainActivity'\n );\n return mainActivity?.[0] ?? null;\n}\n\nexport function addMetaDataItemToMainApplication(\n mainApplication: ManifestApplication,\n itemName: string,\n itemValue: string,\n itemType: 'resource' | 'value' = 'value'\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys({ name: itemName, [itemType]: itemValue }),\n } as ManifestMetaData;\n if (mainApplication['meta-data']) {\n existingMetaDataItem = mainApplication['meta-data'].filter(\n (e: any) => e.$['android:name'] === itemName\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$[\n `android:${itemType}` as keyof ManifestMetaDataAttributes\n ] = itemValue;\n } else {\n mainApplication['meta-data'].push(newItem);\n }\n } else {\n mainApplication['meta-data'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeMetaDataItemFromMainApplication(mainApplication: any, itemName: string) {\n const index = findMetaDataItem(mainApplication, itemName);\n if (mainApplication?.['meta-data'] && index > -1) {\n mainApplication['meta-data'].splice(index, 1);\n }\n return mainApplication;\n}\n\nfunction findApplicationSubItem(\n mainApplication: ManifestApplication,\n category: keyof ManifestApplication,\n itemName: string\n): number {\n const parent = mainApplication[category];\n if (Array.isArray(parent)) {\n const index = parent.findIndex((e: any) => e.$['android:name'] === itemName);\n\n return index;\n }\n return -1;\n}\n\nexport function findMetaDataItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'meta-data', itemName);\n}\n\nexport function findUsesLibraryItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'uses-library', itemName);\n}\n\nexport function getMainApplicationMetaDataValue(\n androidManifest: AndroidManifest,\n name: string\n): string | null {\n const mainApplication = getMainApplication(androidManifest);\n\n if (mainApplication?.hasOwnProperty('meta-data')) {\n const item = mainApplication?.['meta-data']?.find((e: any) => e.$['android:name'] === name);\n return item?.$['android:value'] ?? null;\n }\n\n return null;\n}\n\nexport function addUsesLibraryItemToMainApplication(\n mainApplication: ManifestApplication,\n item: { name: string; required?: boolean }\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys(item),\n } as ManifestUsesLibrary;\n\n if (mainApplication['uses-library']) {\n existingMetaDataItem = mainApplication['uses-library'].filter(\n e => e.$['android:name'] === item.name\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$ = newItem.$;\n } else {\n mainApplication['uses-library'].push(newItem);\n }\n } else {\n mainApplication['uses-library'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeUsesLibraryItemFromMainApplication(\n mainApplication: ManifestApplication,\n itemName: string\n) {\n const index = findUsesLibraryItem(mainApplication, itemName);\n if (mainApplication?.['uses-library'] && index > -1) {\n mainApplication['uses-library'].splice(index, 1);\n }\n return mainApplication;\n}\n\nexport function prefixAndroidKeys<T extends Record<string, any> = Record<string, string>>(\n head: T\n): Record<string, any> {\n // prefix all keys with `android:`\n return Object.entries(head).reduce(\n (prev, [key, curr]) => ({ ...prev, [`android:${key}`]: curr }),\n {} as T\n );\n}\n"],"file":"Manifest.js"}
|
|
@@ -2,6 +2,8 @@ import { ExpoConfig } from '@expo/config-types';
|
|
|
2
2
|
import { ConfigPlugin } from '../Plugin.types';
|
|
3
3
|
import { AndroidManifest, ManifestUsesPermission } from './Manifest';
|
|
4
4
|
export declare const withPermissions: ConfigPlugin<string[] | void>;
|
|
5
|
+
export declare const withBlockedPermissions: ConfigPlugin<string[]>;
|
|
6
|
+
export declare function addBlockedPermissions(androidManifest: AndroidManifest, permissions: string[]): AndroidManifest;
|
|
5
7
|
export declare function getAndroidPermissions(config: Pick<ExpoConfig, 'android'>): string[];
|
|
6
8
|
export declare function setAndroidPermissions(config: Pick<ExpoConfig, 'android'>, androidManifest: AndroidManifest): AndroidManifest;
|
|
7
9
|
export declare function isPermissionAlreadyRequested(permission: string, manifestPermissions: ManifestUsesPermission[]): boolean;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.addBlockedPermissions = addBlockedPermissions;
|
|
6
7
|
exports.addPermission = addPermission;
|
|
7
8
|
exports.addPermissionToManifest = addPermissionToManifest;
|
|
8
9
|
exports.ensurePermission = ensurePermission;
|
|
@@ -13,7 +14,17 @@ exports.getPermissions = getPermissions;
|
|
|
13
14
|
exports.isPermissionAlreadyRequested = isPermissionAlreadyRequested;
|
|
14
15
|
exports.removePermissions = removePermissions;
|
|
15
16
|
exports.setAndroidPermissions = setAndroidPermissions;
|
|
16
|
-
exports.withPermissions = void 0;
|
|
17
|
+
exports.withPermissions = exports.withBlockedPermissions = void 0;
|
|
18
|
+
|
|
19
|
+
function _assert() {
|
|
20
|
+
const data = _interopRequireDefault(require("assert"));
|
|
21
|
+
|
|
22
|
+
_assert = function () {
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
17
28
|
|
|
18
29
|
function _androidPlugins() {
|
|
19
30
|
const data = require("../plugins/android-plugins");
|
|
@@ -25,6 +36,8 @@ function _androidPlugins() {
|
|
|
25
36
|
return data;
|
|
26
37
|
}
|
|
27
38
|
|
|
39
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
40
|
+
|
|
28
41
|
const USES_PERMISSION = 'uses-permission';
|
|
29
42
|
|
|
30
43
|
const withPermissions = (config, permissions) => {
|
|
@@ -44,6 +57,78 @@ const withPermissions = (config, permissions) => {
|
|
|
44
57
|
|
|
45
58
|
exports.withPermissions = withPermissions;
|
|
46
59
|
|
|
60
|
+
const withBlockedPermissions = (config, permissions) => {
|
|
61
|
+
var _config$android;
|
|
62
|
+
|
|
63
|
+
(0, _assert().default)(Array.isArray(permissions), 'permissions prop must be an array');
|
|
64
|
+
|
|
65
|
+
if (config !== null && config !== void 0 && (_config$android = config.android) !== null && _config$android !== void 0 && _config$android.permissions && Array.isArray(config.android.permissions)) {
|
|
66
|
+
// Remove any static config permissions
|
|
67
|
+
config.android.permissions = config.android.permissions.filter(permission => !permissions.includes(permission));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (0, _androidPlugins().withAndroidManifest)(config, async config => {
|
|
71
|
+
config.modResults = ensureToolsAvailable(config.modResults);
|
|
72
|
+
config.modResults = addBlockedPermissions(config.modResults, permissions);
|
|
73
|
+
return config;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Ensure the `tools:*` namespace is available in the manifest.
|
|
78
|
+
*
|
|
79
|
+
* @param manifest AndroidManifest.xml
|
|
80
|
+
* @returns manifest with the `tools:*` namespace available
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
exports.withBlockedPermissions = withBlockedPermissions;
|
|
85
|
+
|
|
86
|
+
function ensureToolsAvailable(manifest) {
|
|
87
|
+
var _manifest$manifest, _manifest$manifest$$;
|
|
88
|
+
|
|
89
|
+
if (manifest !== null && manifest !== void 0 && (_manifest$manifest = manifest.manifest) !== null && _manifest$manifest !== void 0 && (_manifest$manifest$$ = _manifest$manifest.$) !== null && _manifest$manifest$$ !== void 0 && _manifest$manifest$$['xmlns:tools']) {
|
|
90
|
+
return manifest;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
manifest.manifest.$['xmlns:tools'] = 'http://schemas.android.com/tools';
|
|
94
|
+
return manifest;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function addBlockedPermissions(androidManifest, permissions) {
|
|
98
|
+
if (!Array.isArray(androidManifest.manifest['uses-permission'])) {
|
|
99
|
+
androidManifest.manifest['uses-permission'] = [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const permission of permissions) {
|
|
103
|
+
androidManifest.manifest['uses-permission'] = ensureBlockedPermission(androidManifest.manifest['uses-permission'], permission);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return androidManifest;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Filter any existing permissions matching the provided permission name, then add a
|
|
110
|
+
* restricted permission to overwrite any extra permissions that may be added in a
|
|
111
|
+
* third-party package's AndroidManifest.xml.
|
|
112
|
+
*
|
|
113
|
+
* @param manifestPermissions manifest `uses-permissions` array.
|
|
114
|
+
* @param permission `android:name` of the permission to restrict
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
function ensureBlockedPermission(manifestPermissions, permission) {
|
|
120
|
+
// Remove permission if it currently exists
|
|
121
|
+
manifestPermissions = manifestPermissions.filter(e => e.$['android:name'] !== permission); // Add a permission with tools:node to overwrite any existing permission and ensure it's removed upon building.
|
|
122
|
+
|
|
123
|
+
manifestPermissions.push({
|
|
124
|
+
$: {
|
|
125
|
+
'android:name': permission,
|
|
126
|
+
'tools:node': 'remove'
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return manifestPermissions;
|
|
130
|
+
}
|
|
131
|
+
|
|
47
132
|
function prefixAndroidPermissionsIfNecessary(permissions) {
|
|
48
133
|
return permissions.map(permission => {
|
|
49
134
|
if (!permission.includes('.')) {
|
|
@@ -55,9 +140,9 @@ function prefixAndroidPermissionsIfNecessary(permissions) {
|
|
|
55
140
|
}
|
|
56
141
|
|
|
57
142
|
function getAndroidPermissions(config) {
|
|
58
|
-
var _config$android$permi, _config$
|
|
143
|
+
var _config$android$permi, _config$android2;
|
|
59
144
|
|
|
60
|
-
return (_config$android$permi = (_config$
|
|
145
|
+
return (_config$android$permi = (_config$android2 = config.android) === null || _config$android2 === void 0 ? void 0 : _config$android2.permissions) !== null && _config$android$permi !== void 0 ? _config$android$permi : [];
|
|
61
146
|
}
|
|
62
147
|
|
|
63
148
|
function setAndroidPermissions(config, androidManifest) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/Permissions.ts"],"names":["USES_PERMISSION","withPermissions","config","permissions","Array","isArray","filter","Boolean","android","Set","concat","modResults","setAndroidPermissions","prefixAndroidPermissionsIfNecessary","map","permission","includes","getAndroidPermissions","androidManifest","providedPermissions","permissionsToAdd","manifest","hasOwnProperty","manifestPermissions","forEach","isPermissionAlreadyRequested","addPermissionToManifest","some","e","$","push","removePermissions","permissionNames","targetNames","ensurePermissionNameFormat","nextPermissions","attribute","value","name","addPermission","permissionName","usesPermissions","ensurePermissions","getPermissions","results","targetName","ensurePermission","com","split","pop","toUpperCase","join","permissionObject"],"mappings":";;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA,MAAMA,eAAe,GAAG,iBAAxB;;AAEO,MAAMC,eAA8C,GAAG,CAACC,MAAD,EAASC,WAAT,KAAyB;AACrF,MAAIC,KAAK,CAACC,OAAN,CAAcF,WAAd,CAAJ,EAAgC;AAC9BA,IAAAA,WAAW,GAAGA,WAAW,CAACG,MAAZ,CAAmBC,OAAnB,CAAd;AACA,QAAI,CAACL,MAAM,CAACM,OAAZ,EAAqBN,MAAM,CAACM,OAAP,GAAiB,EAAjB;AACrB,QAAI,CAACN,MAAM,CAACM,OAAP,CAAeL,WAApB,EAAiCD,MAAM,CAACM,OAAP,CAAeL,WAAf,GAA6B,EAA7B;AACjCD,IAAAA,MAAM,CAACM,OAAP,CAAeL,WAAf,GAA6B,CAC3B;AACA,OAAG,IAAIM,GAAJ,CAAQP,MAAM,CAACM,OAAP,CAAeL,WAAf,CAA2BO,MAA3B,CAAkCP,WAAlC,CAAR,CAFwB,CAA7B;AAID;;AACD,SAAO,2CAAoBD,MAApB,EAA4B,MAAMA,MAAN,IAAgB;AACjDA,IAAAA,MAAM,CAACS,UAAP,GAAoB,MAAMC,qBAAqB,CAACV,MAAD,EAASA,MAAM,CAACS,UAAhB,CAA/C;AACA,WAAOT,MAAP;AACD,GAHM,CAAP;AAID,CAdM;;;;AAgBP,SAASW,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eAAyC,GAAGvB,eAAe,CAACG,QAAhB,CAAyBrB,eAAzB,KAA6C,EAA/F;AACA,QAAMG,WAAW,GAAGsC,eAAe,CAAC3B,GAAhB,CAAoBsC,gBAAgB,IAAI;AAC1D,WAAOA,gBAAgB,CAACvB,CAAjB,CAAmB,cAAnB,KAAsCuB,gBAAgB,CAACvB,CAAjB,CAAmBS,IAAhE;AACD,GAFmB,CAApB;AAGA,SAAOnC,WAAP;AACD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAndroidManifest } from '../plugins/android-plugins';\nimport { AndroidManifest, ManifestUsesPermission } from './Manifest';\n\nconst USES_PERMISSION = 'uses-permission';\n\nexport const withPermissions: ConfigPlugin<string[] | void> = (config, permissions) => {\n if (Array.isArray(permissions)) {\n permissions = permissions.filter(Boolean);\n if (!config.android) config.android = {};\n if (!config.android.permissions) config.android.permissions = [];\n config.android.permissions = [\n // @ts-ignore\n ...new Set(config.android.permissions.concat(permissions)),\n ];\n }\n return withAndroidManifest(config, async config => {\n config.modResults = await setAndroidPermissions(config, config.modResults);\n return config;\n });\n};\n\nfunction prefixAndroidPermissionsIfNecessary(permissions: string[]): string[] {\n return permissions.map(permission => {\n if (!permission.includes('.')) {\n return `android.permission.${permission}`;\n }\n return permission;\n });\n}\n\nexport function getAndroidPermissions(config: Pick<ExpoConfig, 'android'>): string[] {\n return config.android?.permissions ?? [];\n}\n\nexport function setAndroidPermissions(\n config: Pick<ExpoConfig, 'android'>,\n androidManifest: AndroidManifest\n) {\n const permissions = getAndroidPermissions(config);\n const providedPermissions = prefixAndroidPermissionsIfNecessary(permissions);\n const permissionsToAdd = [...providedPermissions];\n\n if (!androidManifest.manifest.hasOwnProperty('uses-permission')) {\n androidManifest.manifest['uses-permission'] = [];\n }\n // manifest.manifest['uses-permission'] = [];\n\n const manifestPermissions = androidManifest.manifest['uses-permission'] ?? [];\n\n permissionsToAdd.forEach(permission => {\n if (!isPermissionAlreadyRequested(permission, manifestPermissions)) {\n addPermissionToManifest(permission, manifestPermissions);\n }\n });\n\n return androidManifest;\n}\n\nexport function isPermissionAlreadyRequested(\n permission: string,\n manifestPermissions: ManifestUsesPermission[]\n): boolean {\n return manifestPermissions.some(e => e.$['android:name'] === permission);\n}\n\nexport function addPermissionToManifest(\n permission: string,\n manifestPermissions: ManifestUsesPermission[]\n) {\n manifestPermissions.push({ $: { 'android:name': permission } });\n return manifestPermissions;\n}\n\nexport function removePermissions(androidManifest: AndroidManifest, permissionNames?: string[]) {\n const targetNames = permissionNames ? permissionNames.map(ensurePermissionNameFormat) : null;\n const permissions = androidManifest.manifest[USES_PERMISSION] || [];\n const nextPermissions = [];\n for (const attribute of permissions) {\n if (targetNames) {\n // @ts-ignore: name isn't part of the type\n const value = attribute.$['android:name'] || attribute.$.name;\n if (!targetNames.includes(value)) {\n nextPermissions.push(attribute);\n }\n }\n }\n\n androidManifest.manifest[USES_PERMISSION] = nextPermissions;\n}\n\nexport function addPermission(androidManifest: AndroidManifest, permissionName: string): void {\n const usesPermissions: ManifestUsesPermission[] = androidManifest.manifest[USES_PERMISSION] || [];\n usesPermissions.push({\n $: { 'android:name': permissionName },\n });\n androidManifest.manifest[USES_PERMISSION] = usesPermissions;\n}\n\nexport function ensurePermissions(\n androidManifest: AndroidManifest,\n permissionNames: string[]\n): { [permission: string]: boolean } {\n const permissions = getPermissions(androidManifest);\n\n const results: { [permission: string]: boolean } = {};\n for (const permissionName of permissionNames) {\n const targetName = ensurePermissionNameFormat(permissionName);\n if (!permissions.includes(targetName)) {\n addPermission(androidManifest, targetName);\n results[permissionName] = true;\n } else {\n results[permissionName] = false;\n }\n }\n return results;\n}\n\nexport function ensurePermission(\n androidManifest: AndroidManifest,\n permissionName: string\n): boolean {\n const permissions = getPermissions(androidManifest);\n const targetName = ensurePermissionNameFormat(permissionName);\n\n if (!permissions.includes(targetName)) {\n addPermission(androidManifest, targetName);\n return true;\n }\n return false;\n}\n\nexport function ensurePermissionNameFormat(permissionName: string): string {\n if (permissionName.includes('.')) {\n const com = permissionName.split('.');\n const name = com.pop() as string;\n return [...com, name.toUpperCase()].join('.');\n } else {\n // If shorthand form like `WRITE_CONTACTS` is provided, expand it to `android.permission.WRITE_CONTACTS`.\n return ensurePermissionNameFormat(`android.permission.${permissionName}`);\n }\n}\n\nexport function getPermissions(androidManifest: AndroidManifest): string[] {\n const usesPermissions: { [key: string]: any }[] = androidManifest.manifest[USES_PERMISSION] || [];\n const permissions = usesPermissions.map(permissionObject => {\n return permissionObject.$['android:name'] || permissionObject.$.name;\n });\n return permissions;\n}\n"],"file":"Permissions.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/android/Permissions.ts"],"names":["USES_PERMISSION","withPermissions","config","permissions","Array","isArray","filter","Boolean","android","Set","concat","modResults","setAndroidPermissions","withBlockedPermissions","permission","includes","ensureToolsAvailable","addBlockedPermissions","manifest","$","androidManifest","ensureBlockedPermission","manifestPermissions","e","push","prefixAndroidPermissionsIfNecessary","map","getAndroidPermissions","providedPermissions","permissionsToAdd","hasOwnProperty","forEach","isPermissionAlreadyRequested","addPermissionToManifest","some","removePermissions","permissionNames","targetNames","ensurePermissionNameFormat","nextPermissions","attribute","value","name","addPermission","permissionName","usesPermissions","ensurePermissions","getPermissions","results","targetName","ensurePermission","com","split","pop","toUpperCase","join","permissionObject"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;AAGA,MAAMA,eAAe,GAAG,iBAAxB;;AAEO,MAAMC,eAA8C,GAAG,CAACC,MAAD,EAASC,WAAT,KAAyB;AACrF,MAAIC,KAAK,CAACC,OAAN,CAAcF,WAAd,CAAJ,EAAgC;AAC9BA,IAAAA,WAAW,GAAGA,WAAW,CAACG,MAAZ,CAAmBC,OAAnB,CAAd;AACA,QAAI,CAACL,MAAM,CAACM,OAAZ,EAAqBN,MAAM,CAAC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eAAxB,EAAoE;AACzE,QAAMyB,eAAyC,GAAGzB,eAAe,CAACF,QAAhB,CAAyBlB,eAAzB,KAA6C,EAA/F;AACA,QAAMG,WAAW,GAAG0C,eAAe,CAACnB,GAAhB,CAAoB8B,gBAAgB,IAAI;AAC1D,WAAOA,gBAAgB,CAACrC,CAAjB,CAAmB,cAAnB,KAAsCqC,gBAAgB,CAACrC,CAAjB,CAAmBuB,IAAhE;AACD,GAFmB,CAApB;AAGA,SAAOvC,WAAP;AACD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport assert from 'assert';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAndroidManifest } from '../plugins/android-plugins';\nimport { AndroidManifest, ManifestUsesPermission } from './Manifest';\n\nconst USES_PERMISSION = 'uses-permission';\n\nexport const withPermissions: ConfigPlugin<string[] | void> = (config, permissions) => {\n if (Array.isArray(permissions)) {\n permissions = permissions.filter(Boolean);\n if (!config.android) config.android = {};\n if (!config.android.permissions) config.android.permissions = [];\n config.android.permissions = [\n // @ts-ignore\n ...new Set(config.android.permissions.concat(permissions)),\n ];\n }\n return withAndroidManifest(config, async config => {\n config.modResults = await setAndroidPermissions(config, config.modResults);\n return config;\n });\n};\n\nexport const withBlockedPermissions: ConfigPlugin<string[]> = (config, permissions) => {\n assert(Array.isArray(permissions), 'permissions prop must be an array');\n\n if (config?.android?.permissions && Array.isArray(config.android.permissions)) {\n // Remove any static config permissions\n config.android.permissions = config.android.permissions.filter(\n permission => !permissions.includes(permission)\n );\n }\n\n return withAndroidManifest(config, async config => {\n config.modResults = ensureToolsAvailable(config.modResults);\n config.modResults = addBlockedPermissions(config.modResults, permissions);\n\n return config;\n });\n};\n\n/**\n * Ensure the `tools:*` namespace is available in the manifest.\n *\n * @param manifest AndroidManifest.xml\n * @returns manifest with the `tools:*` namespace available\n */\nfunction ensureToolsAvailable(manifest: AndroidManifest) {\n if (manifest?.manifest?.$?.['xmlns:tools']) {\n return manifest;\n }\n manifest.manifest.$['xmlns:tools'] = 'http://schemas.android.com/tools';\n return manifest;\n}\n\nexport function addBlockedPermissions(androidManifest: AndroidManifest, permissions: string[]) {\n if (!Array.isArray(androidManifest.manifest['uses-permission'])) {\n androidManifest.manifest['uses-permission'] = [];\n }\n\n for (const permission of permissions) {\n androidManifest.manifest['uses-permission'] = ensureBlockedPermission(\n androidManifest.manifest['uses-permission'],\n permission\n );\n }\n\n return androidManifest;\n}\n\n/**\n * Filter any existing permissions matching the provided permission name, then add a\n * restricted permission to overwrite any extra permissions that may be added in a\n * third-party package's AndroidManifest.xml.\n *\n * @param manifestPermissions manifest `uses-permissions` array.\n * @param permission `android:name` of the permission to restrict\n * @returns\n */\nfunction ensureBlockedPermission(\n manifestPermissions: ManifestUsesPermission[],\n permission: string\n) {\n // Remove permission if it currently exists\n manifestPermissions = manifestPermissions.filter(e => e.$['android:name'] !== permission);\n\n // Add a permission with tools:node to overwrite any existing permission and ensure it's removed upon building.\n manifestPermissions.push({\n $: { 'android:name': permission, 'tools:node': 'remove' },\n });\n return manifestPermissions;\n}\n\nfunction prefixAndroidPermissionsIfNecessary(permissions: string[]): string[] {\n return permissions.map(permission => {\n if (!permission.includes('.')) {\n return `android.permission.${permission}`;\n }\n return permission;\n });\n}\n\nexport function getAndroidPermissions(config: Pick<ExpoConfig, 'android'>): string[] {\n return config.android?.permissions ?? [];\n}\n\nexport function setAndroidPermissions(\n config: Pick<ExpoConfig, 'android'>,\n androidManifest: AndroidManifest\n) {\n const permissions = getAndroidPermissions(config);\n const providedPermissions = prefixAndroidPermissionsIfNecessary(permissions);\n const permissionsToAdd = [...providedPermissions];\n\n if (!androidManifest.manifest.hasOwnProperty('uses-permission')) {\n androidManifest.manifest['uses-permission'] = [];\n }\n // manifest.manifest['uses-permission'] = [];\n\n const manifestPermissions = androidManifest.manifest['uses-permission'] ?? [];\n\n permissionsToAdd.forEach(permission => {\n if (!isPermissionAlreadyRequested(permission, manifestPermissions)) {\n addPermissionToManifest(permission, manifestPermissions);\n }\n });\n\n return androidManifest;\n}\n\nexport function isPermissionAlreadyRequested(\n permission: string,\n manifestPermissions: ManifestUsesPermission[]\n): boolean {\n return manifestPermissions.some(e => e.$['android:name'] === permission);\n}\n\nexport function addPermissionToManifest(\n permission: string,\n manifestPermissions: ManifestUsesPermission[]\n) {\n manifestPermissions.push({ $: { 'android:name': permission } });\n return manifestPermissions;\n}\n\nexport function removePermissions(androidManifest: AndroidManifest, permissionNames?: string[]) {\n const targetNames = permissionNames ? permissionNames.map(ensurePermissionNameFormat) : null;\n const permissions = androidManifest.manifest[USES_PERMISSION] || [];\n const nextPermissions = [];\n for (const attribute of permissions) {\n if (targetNames) {\n // @ts-ignore: name isn't part of the type\n const value = attribute.$['android:name'] || attribute.$.name;\n if (!targetNames.includes(value)) {\n nextPermissions.push(attribute);\n }\n }\n }\n\n androidManifest.manifest[USES_PERMISSION] = nextPermissions;\n}\n\nexport function addPermission(androidManifest: AndroidManifest, permissionName: string): void {\n const usesPermissions: ManifestUsesPermission[] = androidManifest.manifest[USES_PERMISSION] || [];\n usesPermissions.push({\n $: { 'android:name': permissionName },\n });\n androidManifest.manifest[USES_PERMISSION] = usesPermissions;\n}\n\nexport function ensurePermissions(\n androidManifest: AndroidManifest,\n permissionNames: string[]\n): { [permission: string]: boolean } {\n const permissions = getPermissions(androidManifest);\n\n const results: { [permission: string]: boolean } = {};\n for (const permissionName of permissionNames) {\n const targetName = ensurePermissionNameFormat(permissionName);\n if (!permissions.includes(targetName)) {\n addPermission(androidManifest, targetName);\n results[permissionName] = true;\n } else {\n results[permissionName] = false;\n }\n }\n return results;\n}\n\nexport function ensurePermission(\n androidManifest: AndroidManifest,\n permissionName: string\n): boolean {\n const permissions = getPermissions(androidManifest);\n const targetName = ensurePermissionNameFormat(permissionName);\n\n if (!permissions.includes(targetName)) {\n addPermission(androidManifest, targetName);\n return true;\n }\n return false;\n}\n\nexport function ensurePermissionNameFormat(permissionName: string): string {\n if (permissionName.includes('.')) {\n const com = permissionName.split('.');\n const name = com.pop() as string;\n return [...com, name.toUpperCase()].join('.');\n } else {\n // If shorthand form like `WRITE_CONTACTS` is provided, expand it to `android.permission.WRITE_CONTACTS`.\n return ensurePermissionNameFormat(`android.permission.${permissionName}`);\n }\n}\n\nexport function getPermissions(androidManifest: AndroidManifest): string[] {\n const usesPermissions: { [key: string]: any }[] = androidManifest.manifest[USES_PERMISSION] || [];\n const permissions = usesPermissions.map(permissionObject => {\n return permissionObject.$['android:name'] || permissionObject.$.name;\n });\n return permissions;\n}\n"],"file":"Permissions.js"}
|
package/build/ios/Maps.js
CHANGED
|
@@ -76,10 +76,10 @@ function _generateCode() {
|
|
|
76
76
|
|
|
77
77
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
78
78
|
|
|
79
|
-
const debug = require('debug')('expo:config-plugins:ios:maps'); // Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules).
|
|
79
|
+
const debug = require('debug')('expo:config-plugins:ios:maps'); // Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules), and SDK +44 React AppDelegate subscriber.
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
const MATCH_INIT = /(?:(self\.|_)(\w+)\s?=\s?\[\[UMModuleRegistryAdapter alloc\])|(?:RCTBridge\s?\*\s?(\w+)\s?=\s?\[\[RCTBridge alloc\])/g;
|
|
82
|
+
const MATCH_INIT = /(?:(self\.|_)(\w+)\s?=\s?\[\[UMModuleRegistryAdapter alloc\])|(?:RCTBridge\s?\*\s?(\w+)\s?=\s?\[\[RCTBridge alloc\])|(\[self\.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions\])/g;
|
|
83
83
|
exports.MATCH_INIT = MATCH_INIT;
|
|
84
84
|
const withGoogleMapsKey = (0, _iosPlugins().createInfoPlistPlugin)(setGoogleMapsApiKey, 'withGoogleMapsKey');
|
|
85
85
|
|
package/build/ios/Maps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ios/Maps.ts"],"names":["debug","require","MATCH_INIT","withGoogleMapsKey","setGoogleMapsApiKey","withMaps","config","apiKey","getGoogleMapsApiKey","withMapsCocoaPods","useGoogleMaps","withGoogleMapsAppDelegate","ios","googleMapsApiKey","GMSApiKey","infoPlist","addGoogleMapsAppDelegateImport","src","newSrc","push","tag","join","anchor","offset","comment","removeGoogleMapsAppDelegateImport","addGoogleMapsAppDelegateInit","removeGoogleMapsAppDelegateInit","addMapsCocoaPods","googleMapsPath","removeMapsCocoaPods","isReactNativeMapsInstalled","projectRoot","resolved","resolveFrom","silent","path","dirname","isReactNativeMapsAutolinked","_internal","autolinkedModules","includes","filePath","modRequest","platformProjectRoot","contents","fs","readFile","results","isLinked","googleMapsPodPath","relative","error","code","Error","didMerge","didClear","writeFile","modResults","language"],"mappings":";;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;AAEA,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAAP,CAAiB,8BAAjB,CAAd,C,CAEA;;;AACO,MAAMC,UAAU,GAAG,uHAAnB;;AAEP,MAAMC,iBAAiB,GAAG,yCAAsBC,mBAAtB,EAA2C,mBAA3C,CAA1B;;AAEO,MAAMC,QAAsB,GAAGC,MAAM,IAAI;AAC9CA,EAAAA,MAAM,GAAGH,iBAAiB,CAACG,MAAD,CAA1B;AAEA,QAAMC,MAAM,GAAGC,mBAAmB,CAACF,MAAD,CAAlC,CAH8C,CAI9C;;AAEAN,EAAAA,KAAK,CAAC,sBAAD,EAAyBO,MAAzB,CAAL;AACAD,EAAAA,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jC,CAE3BA,QAFF;AAGAvC,QAAAA,MAAM,CAACoD,UAAP,CAAkBb,QAAlB,GAA6BlB,+BAA+B,CAC1DrB,MAAM,CAACoD,UAAP,CAAkBb,QADwC,CAA/B,CAE3BA,QAFF;AAGD;AACF,KA9BD,MA8BO;AACL,YAAM,IAAIS,KAAJ,CAAU,qEAAV,CAAN;AACD;;AACD,WAAOhD,MAAP;AACD,GAnCM,CAAP;AAoCD,CArCD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { ConfigPlugin, InfoPlist } from '../Plugin.types';\nimport { createInfoPlistPlugin, withAppDelegate } from '../plugins/ios-plugins';\nimport { withDangerousMod } from '../plugins/withDangerousMod';\nimport { mergeContents, MergeResults, removeContents } from '../utils/generateCode';\n\nconst debug = require('debug')('expo:config-plugins:ios:maps') as typeof console.log;\n\n// Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules).\nexport const MATCH_INIT = /(?:(self\\.|_)(\\w+)\\s?=\\s?\\[\\[UMModuleRegistryAdapter alloc\\])|(?:RCTBridge\\s?\\*\\s?(\\w+)\\s?=\\s?\\[\\[RCTBridge alloc\\])/g;\n\nconst withGoogleMapsKey = createInfoPlistPlugin(setGoogleMapsApiKey, 'withGoogleMapsKey');\n\nexport const withMaps: ConfigPlugin = config => {\n config = withGoogleMapsKey(config);\n\n const apiKey = getGoogleMapsApiKey(config);\n // Technically adds react-native-maps (Apple maps) and google maps.\n\n debug('Google Maps API Key:', apiKey);\n config = withMapsCocoaPods(config, { useGoogleMaps: !!apiKey });\n\n // Adds/Removes AppDelegate setup for Google Maps API on iOS\n config = withGoogleMapsAppDelegate(config, { apiKey });\n\n return config;\n};\n\nexport function getGoogleMapsApiKey(config: Pick<ExpoConfig, 'ios'>) {\n return config.ios?.config?.googleMapsApiKey ?? null;\n}\n\nexport function setGoogleMapsApiKey(\n config: Pick<ExpoConfig, 'ios'>,\n { GMSApiKey, ...infoPlist }: InfoPlist\n): InfoPlist {\n const apiKey = getGoogleMapsApiKey(config);\n\n if (apiKey === null) {\n return infoPlist;\n }\n\n return {\n ...infoPlist,\n GMSApiKey: apiKey,\n };\n}\n\nexport function addGoogleMapsAppDelegateImport(src: string): MergeResults {\n const newSrc = [];\n newSrc.push(\n '#if __has_include(<GoogleMaps/GoogleMaps.h>)',\n '#import <GoogleMaps/GoogleMaps.h>',\n '#endif'\n );\n\n return mergeContents({\n tag: 'react-native-maps-import',\n src,\n newSrc: newSrc.join('\\n'),\n anchor: /#import \"AppDelegate\\.h\"/,\n offset: 1,\n comment: '//',\n });\n}\n\nexport function removeGoogleMapsAppDelegateImport(src: string): MergeResults {\n return removeContents({\n tag: 'react-native-maps-import',\n src,\n });\n}\n\nexport function addGoogleMapsAppDelegateInit(src: string, apiKey: string): MergeResults {\n const newSrc = [];\n newSrc.push(\n '#if __has_include(<GoogleMaps/GoogleMaps.h>)',\n ` [GMSServices provideAPIKey:@\"${apiKey}\"];`,\n '#endif'\n );\n\n return mergeContents({\n tag: 'react-native-maps-init',\n src,\n newSrc: newSrc.join('\\n'),\n anchor: MATCH_INIT,\n offset: 0,\n comment: '//',\n });\n}\n\nexport function removeGoogleMapsAppDelegateInit(src: string): MergeResults {\n return removeContents({\n tag: 'react-native-maps-init',\n src,\n });\n}\n\n/**\n * @param src\n * @param useGoogleMaps\n * @param googleMapsPath '../node_modules/react-native-maps'\n * @returns\n */\nexport function addMapsCocoaPods(src: string, googleMapsPath: string): MergeResults {\n return mergeContents({\n tag: 'react-native-maps',\n src,\n newSrc: ` pod 'react-native-google-maps', path: '${googleMapsPath}'`,\n anchor: /use_native_modules/,\n offset: 0,\n comment: '#',\n });\n}\n\nexport function removeMapsCocoaPods(src: string): MergeResults {\n return removeContents({\n tag: 'react-native-maps',\n src,\n });\n}\n\nfunction isReactNativeMapsInstalled(projectRoot: string): string | null {\n const resolved = resolveFrom.silent(projectRoot, 'react-native-maps/package.json');\n return resolved ? path.dirname(resolved) : null;\n}\n\nfunction isReactNativeMapsAutolinked(config: Pick<ExpoConfig, '_internal'>): string | null {\n // Only add the native code changes if we know that the package is going to be linked natively.\n // This is specifically for monorepo support where one app might have react-native-maps (adding it to the node_modules)\n // but another app will not have it installed in the package.json, causing it to not be linked natively.\n // This workaround only exists because react-native-maps doesn't have a config plugin vendored in the package.\n return (\n !config._internal?.autolinkedModules ||\n config._internal.autolinkedModules.includes('react-native-maps')\n );\n}\n\nconst withMapsCocoaPods: ConfigPlugin<{ useGoogleMaps: boolean }> = (config, { useGoogleMaps }) => {\n return withDangerousMod(config, [\n 'ios',\n async config => {\n const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');\n const contents = await fs.readFile(filePath, 'utf-8');\n let results: MergeResults;\n // Only add the block if react-native-maps is installed in the project (best effort).\n // Generally prebuild runs after a yarn install so this should always work as expected.\n const googleMapsPath = isReactNativeMapsInstalled(config.modRequest.projectRoot);\n const isLinked = isReactNativeMapsAutolinked(config);\n debug('Is Expo Autolinked:', isLinked);\n debug('react-native-maps path:', googleMapsPath);\n if (isLinked && googleMapsPath && useGoogleMaps) {\n // Make the pod path relative to the ios folder.\n const googleMapsPodPath = path.relative(\n config.modRequest.platformProjectRoot,\n googleMapsPath\n );\n try {\n results = addMapsCocoaPods(contents, googleMapsPodPath);\n } catch (error: any) {\n if (error.code === 'ERR_NO_MATCH') {\n throw new Error(\n `Cannot add react-native-maps to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.`\n );\n }\n throw error;\n }\n } else {\n // If the package is no longer installed, then remove the block.\n results = removeMapsCocoaPods(contents);\n }\n if (results.didMerge || results.didClear) {\n await fs.writeFile(filePath, results.contents);\n }\n return config;\n },\n ]);\n};\n\nconst withGoogleMapsAppDelegate: ConfigPlugin<{ apiKey: string | null }> = (config, { apiKey }) => {\n return withAppDelegate(config, config => {\n if (config.modResults.language === 'objc') {\n if (\n apiKey &&\n isReactNativeMapsAutolinked(config) &&\n isReactNativeMapsInstalled(config.modRequest.projectRoot)\n ) {\n try {\n config.modResults.contents = addGoogleMapsAppDelegateImport(\n config.modResults.contents\n ).contents;\n config.modResults.contents = addGoogleMapsAppDelegateInit(\n config.modResults.contents,\n apiKey\n ).contents;\n } catch (error) {\n if (error.code === 'ERR_NO_MATCH') {\n throw new Error(\n `Cannot add Google Maps to the project's AppDelegate because it's malformed. Please report this with a copy of your project AppDelegate.`\n );\n }\n throw error;\n }\n } else {\n config.modResults.contents = removeGoogleMapsAppDelegateImport(\n config.modResults.contents\n ).contents;\n config.modResults.contents = removeGoogleMapsAppDelegateInit(\n config.modResults.contents\n ).contents;\n }\n } else {\n throw new Error('Cannot setup Google Maps because the AppDelegate is not Objective C');\n }\n return config;\n });\n};\n"],"file":"Maps.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/ios/Maps.ts"],"names":["debug","require","MATCH_INIT","withGoogleMapsKey","setGoogleMapsApiKey","withMaps","config","apiKey","getGoogleMapsApiKey","withMapsCocoaPods","useGoogleMaps","withGoogleMapsAppDelegate","ios","googleMapsApiKey","GMSApiKey","infoPlist","addGoogleMapsAppDelegateImport","src","newSrc","push","tag","join","anchor","offset","comment","removeGoogleMapsAppDelegateImport","addGoogleMapsAppDelegateInit","removeGoogleMapsAppDelegateInit","addMapsCocoaPods","googleMapsPath","removeMapsCocoaPods","isReactNativeMapsInstalled","projectRoot","resolved","resolveFrom","silent","path","dirname","isReactNativeMapsAutolinked","_internal","autolinkedModules","includes","filePath","modRequest","platformProjectRoot","contents","fs","readFile","results","isLinked","googleMapsPodPath","relative","error","code","Error","didMerge","didClear","writeFile","modResults","language"],"mappings":";;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;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MAAM,CAACoD,UAAP,CAAkBb,QADuC,CAA9B,CAE3BA,QAFF;AAGAvC,UAAAA,MAAM,CAACoD,UAAP,CAAkBb,QAAlB,GAA6BnB,4BAA4B,CACvDpB,MAAM,CAACoD,UAAP,CAAkBb,QADqC,EAEvDtC,MAFuD,CAA5B,CAG3BsC,QAHF;AAID,SARD,CAQE,OAAOO,KAAP,EAAc;AACd,cAAIA,KAAK,CAACC,IAAN,KAAe,cAAnB,EAAmC;AACjC,kBAAM,IAAIC,KAAJ,CACH,yIADG,CAAN;AAGD;;AACD,gBAAMF,KAAN;AACD;AACF,OArBD,MAqBO;AACL9C,QAAAA,MAAM,CAACoD,UAAP,CAAkBb,QAAlB,GAA6BpB,iCAAiC,CAC5DnB,MAAM,CAACoD,UAAP,CAAkBb,QAD0C,CAAjC,CAE3BA,QAFF;AAGAvC,QAAAA,MAAM,CAACoD,UAAP,CAAkBb,QAAlB,GAA6BlB,+BAA+B,CAC1DrB,MAAM,CAACoD,UAAP,CAAkBb,QADwC,CAA/B,CAE3BA,QAFF;AAGD;AACF,KA9BD,MA8BO;AACL,YAAM,IAAIS,KAAJ,CAAU,qEAAV,CAAN;AACD;;AACD,WAAOhD,MAAP;AACD,GAnCM,CAAP;AAoCD,CArCD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { ConfigPlugin, InfoPlist } from '../Plugin.types';\nimport { createInfoPlistPlugin, withAppDelegate } from '../plugins/ios-plugins';\nimport { withDangerousMod } from '../plugins/withDangerousMod';\nimport { mergeContents, MergeResults, removeContents } from '../utils/generateCode';\n\nconst debug = require('debug')('expo:config-plugins:ios:maps') as typeof console.log;\n\n// Match against `UMModuleRegistryAdapter` (unimodules), and React Native without unimodules (Expo Modules), and SDK +44 React AppDelegate subscriber.\nexport const MATCH_INIT = /(?:(self\\.|_)(\\w+)\\s?=\\s?\\[\\[UMModuleRegistryAdapter alloc\\])|(?:RCTBridge\\s?\\*\\s?(\\w+)\\s?=\\s?\\[\\[RCTBridge alloc\\])|(\\[self\\.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions\\])/g;\n\nconst withGoogleMapsKey = createInfoPlistPlugin(setGoogleMapsApiKey, 'withGoogleMapsKey');\n\nexport const withMaps: ConfigPlugin = config => {\n config = withGoogleMapsKey(config);\n\n const apiKey = getGoogleMapsApiKey(config);\n // Technically adds react-native-maps (Apple maps) and google maps.\n\n debug('Google Maps API Key:', apiKey);\n config = withMapsCocoaPods(config, { useGoogleMaps: !!apiKey });\n\n // Adds/Removes AppDelegate setup for Google Maps API on iOS\n config = withGoogleMapsAppDelegate(config, { apiKey });\n\n return config;\n};\n\nexport function getGoogleMapsApiKey(config: Pick<ExpoConfig, 'ios'>) {\n return config.ios?.config?.googleMapsApiKey ?? null;\n}\n\nexport function setGoogleMapsApiKey(\n config: Pick<ExpoConfig, 'ios'>,\n { GMSApiKey, ...infoPlist }: InfoPlist\n): InfoPlist {\n const apiKey = getGoogleMapsApiKey(config);\n\n if (apiKey === null) {\n return infoPlist;\n }\n\n return {\n ...infoPlist,\n GMSApiKey: apiKey,\n };\n}\n\nexport function addGoogleMapsAppDelegateImport(src: string): MergeResults {\n const newSrc = [];\n newSrc.push(\n '#if __has_include(<GoogleMaps/GoogleMaps.h>)',\n '#import <GoogleMaps/GoogleMaps.h>',\n '#endif'\n );\n\n return mergeContents({\n tag: 'react-native-maps-import',\n src,\n newSrc: newSrc.join('\\n'),\n anchor: /#import \"AppDelegate\\.h\"/,\n offset: 1,\n comment: '//',\n });\n}\n\nexport function removeGoogleMapsAppDelegateImport(src: string): MergeResults {\n return removeContents({\n tag: 'react-native-maps-import',\n src,\n });\n}\n\nexport function addGoogleMapsAppDelegateInit(src: string, apiKey: string): MergeResults {\n const newSrc = [];\n newSrc.push(\n '#if __has_include(<GoogleMaps/GoogleMaps.h>)',\n ` [GMSServices provideAPIKey:@\"${apiKey}\"];`,\n '#endif'\n );\n\n return mergeContents({\n tag: 'react-native-maps-init',\n src,\n newSrc: newSrc.join('\\n'),\n anchor: MATCH_INIT,\n offset: 0,\n comment: '//',\n });\n}\n\nexport function removeGoogleMapsAppDelegateInit(src: string): MergeResults {\n return removeContents({\n tag: 'react-native-maps-init',\n src,\n });\n}\n\n/**\n * @param src\n * @param useGoogleMaps\n * @param googleMapsPath '../node_modules/react-native-maps'\n * @returns\n */\nexport function addMapsCocoaPods(src: string, googleMapsPath: string): MergeResults {\n return mergeContents({\n tag: 'react-native-maps',\n src,\n newSrc: ` pod 'react-native-google-maps', path: '${googleMapsPath}'`,\n anchor: /use_native_modules/,\n offset: 0,\n comment: '#',\n });\n}\n\nexport function removeMapsCocoaPods(src: string): MergeResults {\n return removeContents({\n tag: 'react-native-maps',\n src,\n });\n}\n\nfunction isReactNativeMapsInstalled(projectRoot: string): string | null {\n const resolved = resolveFrom.silent(projectRoot, 'react-native-maps/package.json');\n return resolved ? path.dirname(resolved) : null;\n}\n\nfunction isReactNativeMapsAutolinked(config: Pick<ExpoConfig, '_internal'>): string | null {\n // Only add the native code changes if we know that the package is going to be linked natively.\n // This is specifically for monorepo support where one app might have react-native-maps (adding it to the node_modules)\n // but another app will not have it installed in the package.json, causing it to not be linked natively.\n // This workaround only exists because react-native-maps doesn't have a config plugin vendored in the package.\n return (\n !config._internal?.autolinkedModules ||\n config._internal.autolinkedModules.includes('react-native-maps')\n );\n}\n\nconst withMapsCocoaPods: ConfigPlugin<{ useGoogleMaps: boolean }> = (config, { useGoogleMaps }) => {\n return withDangerousMod(config, [\n 'ios',\n async config => {\n const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');\n const contents = await fs.readFile(filePath, 'utf-8');\n let results: MergeResults;\n // Only add the block if react-native-maps is installed in the project (best effort).\n // Generally prebuild runs after a yarn install so this should always work as expected.\n const googleMapsPath = isReactNativeMapsInstalled(config.modRequest.projectRoot);\n const isLinked = isReactNativeMapsAutolinked(config);\n debug('Is Expo Autolinked:', isLinked);\n debug('react-native-maps path:', googleMapsPath);\n if (isLinked && googleMapsPath && useGoogleMaps) {\n // Make the pod path relative to the ios folder.\n const googleMapsPodPath = path.relative(\n config.modRequest.platformProjectRoot,\n googleMapsPath\n );\n try {\n results = addMapsCocoaPods(contents, googleMapsPodPath);\n } catch (error: any) {\n if (error.code === 'ERR_NO_MATCH') {\n throw new Error(\n `Cannot add react-native-maps to the project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.`\n );\n }\n throw error;\n }\n } else {\n // If the package is no longer installed, then remove the block.\n results = removeMapsCocoaPods(contents);\n }\n if (results.didMerge || results.didClear) {\n await fs.writeFile(filePath, results.contents);\n }\n return config;\n },\n ]);\n};\n\nconst withGoogleMapsAppDelegate: ConfigPlugin<{ apiKey: string | null }> = (config, { apiKey }) => {\n return withAppDelegate(config, config => {\n if (config.modResults.language === 'objc') {\n if (\n apiKey &&\n isReactNativeMapsAutolinked(config) &&\n isReactNativeMapsInstalled(config.modRequest.projectRoot)\n ) {\n try {\n config.modResults.contents = addGoogleMapsAppDelegateImport(\n config.modResults.contents\n ).contents;\n config.modResults.contents = addGoogleMapsAppDelegateInit(\n config.modResults.contents,\n apiKey\n ).contents;\n } catch (error) {\n if (error.code === 'ERR_NO_MATCH') {\n throw new Error(\n `Cannot add Google Maps to the project's AppDelegate because it's malformed. Please report this with a copy of your project AppDelegate.`\n );\n }\n throw error;\n }\n } else {\n config.modResults.contents = removeGoogleMapsAppDelegateImport(\n config.modResults.contents\n ).contents;\n config.modResults.contents = removeGoogleMapsAppDelegateInit(\n config.modResults.contents\n ).contents;\n }\n } else {\n throw new Error('Cannot setup Google Maps because the AppDelegate is not Objective C');\n }\n return config;\n });\n};\n"],"file":"Maps.js"}
|