@expo/config-plugins 4.0.11 → 4.0.15
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 +3 -0
- package/build/android/Manifest.js +3 -1
- 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/android/Updates.js +5 -0
- package/build/android/Updates.js.map +1 -1
- package/build/ios/Maps.d.ts +3 -5
- package/build/ios/Maps.js +16 -14
- package/build/ios/Maps.js.map +1 -1
- package/build/ios/Name.d.ts +7 -2
- package/build/ios/Name.js +58 -1
- package/build/ios/Name.js.map +1 -1
- package/build/ios/Updates.js +5 -0
- package/build/ios/Updates.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
|
};
|
|
@@ -111,6 +113,7 @@ export declare type AndroidManifest = {
|
|
|
111
113
|
};
|
|
112
114
|
export declare function writeAndroidManifestAsync(manifestPath: string, androidManifest: AndroidManifest): Promise<void>;
|
|
113
115
|
export declare function readAndroidManifestAsync(manifestPath: string): Promise<AndroidManifest>;
|
|
116
|
+
/** Returns the `manifest.application` tag ending in `.MainApplication` */
|
|
114
117
|
export declare function getMainApplication(androidManifest: AndroidManifest): ManifestApplication | null;
|
|
115
118
|
export declare function getMainApplicationOrThrow(androidManifest: AndroidManifest): ManifestApplication;
|
|
116
119
|
export declare function getMainActivityOrThrow(androidManifest: AndroidManifest): ManifestActivity;
|
|
@@ -87,6 +87,8 @@ function isManifest(xml) {
|
|
|
87
87
|
// TODO: Maybe more validation
|
|
88
88
|
return !!xml.manifest;
|
|
89
89
|
}
|
|
90
|
+
/** Returns the `manifest.application` tag ending in `.MainApplication` */
|
|
91
|
+
|
|
90
92
|
|
|
91
93
|
function getMainApplication(androidManifest) {
|
|
92
94
|
var _androidManifest$mani, _androidManifest$mani2, _androidManifest$mani3;
|
|
@@ -94,7 +96,7 @@ function getMainApplication(androidManifest) {
|
|
|
94
96
|
return (_androidManifest$mani = androidManifest === null || androidManifest === void 0 ? void 0 : (_androidManifest$mani2 = androidManifest.manifest) === null || _androidManifest$mani2 === void 0 ? void 0 : (_androidManifest$mani3 = _androidManifest$mani2.application) === null || _androidManifest$mani3 === void 0 ? void 0 : _androidManifest$mani3.filter(e => {
|
|
95
97
|
var _e$$;
|
|
96
98
|
|
|
97
|
-
return
|
|
99
|
+
return e === null || e === void 0 ? void 0 : (_e$$ = e.$) === null || _e$$ === void 0 ? void 0 : _e$$['android:name'].endsWith('.MainApplication');
|
|
98
100
|
})[0]) !== null && _androidManifest$mani !== void 0 ? _androidManifest$mani : null;
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -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,SAA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AAlB,CAAjC;;AACA,MAAId,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAG,cAAH,CAAf,IAAqCwB,KAAK,GAAG,CAAC,CAAlD,EAAqD;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","$","endsWith","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;;;;;;;;AAoJO,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;AAED;;;AACO,SAASC,kBAAT,CAA4Bf,eAA5B,EAA0F;AAAA;;AAC/F,kCACEA,eADF,aACEA,eADF,iDACEA,eAAe,CAAEc,QADnB,qFACE,uBAA2BE,WAD7B,2DACE,uBAAwCC,MAAxC,CAA+CC,CAAC;AAAA;;AAAA,WAC9CA,CAD8C,aAC9CA,CAD8C,+BAC9CA,CAAC,C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CAAjC;;AACA,MAAId,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAG,cAAH,CAAf,IAAqCwB,KAAK,GAAG,CAAC,CAAlD,EAAqD;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 '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\n/** Returns the `manifest.application` tag ending in `.MainApplication` */\nexport function getMainApplication(androidManifest: AndroidManifest): ManifestApplication | null {\n return (\n androidManifest?.manifest?.application?.filter(e =>\n e?.$?.['android:name'].endsWith('.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,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,WAAL,EAAT,EAA6BC,IAA7B,CAAkC,GAAlC,CAAP;AACD,GAJD,MAIO;AACL;AACA,WAAOjB,0BAA0B,CAAE,sBAAqBM,cAAe,EAAtC,CAAjC;AACD;AACF;;AAEM,SAASG,cAAT,CAAwBzB,eAAxB,EAAoE;AACzE,QAAMuB,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,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AGF,GAAJ,EAAST,IAAI,CAACY,WAAL,EAAT,EAA6BC,IAA7B,CAAkC,GAAlC,CAAP;AACD,GAJD,MAIO;AACL;AACA,WAAOjB,0BAA0B,CAAE,sBAAqBM,cAAe,EAAtC,CAAjC;AACD;AACF;;AAEM,SAASG,cAAT,CAAwB3B,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/android/Updates.js
CHANGED
|
@@ -159,6 +159,11 @@ function setUpdatesConfig(config, androidManifest, username, expoUpdatesPackageV
|
|
|
159
159
|
function setVersionsConfig(config, androidManifest) {
|
|
160
160
|
const mainApplication = (0, _Manifest().getMainApplicationOrThrow)(androidManifest);
|
|
161
161
|
const runtimeVersion = (0, _Updates().getRuntimeVersionNullable)(config, 'android');
|
|
162
|
+
|
|
163
|
+
if (!runtimeVersion && (0, _Manifest().findMetaDataItem)(mainApplication, Config.RUNTIME_VERSION) > -1) {
|
|
164
|
+
throw new Error('A runtime version is set in your AndroidManifest.xml, but is missing from your app.json/app.config.js. Please either set runtimeVersion in your app.json/app.config.js or remove expo.modules.updates.EXPO_RUNTIME_VERSION from your AndroidManifest.xml.');
|
|
165
|
+
}
|
|
166
|
+
|
|
162
167
|
const sdkVersion = getSDKVersion(config);
|
|
163
168
|
|
|
164
169
|
if (runtimeVersion) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/Updates.ts"],"names":["CREATE_MANIFEST_ANDROID_PATH","Config","withUpdates","config","expoUsername","expoUpdatesPackageVersion","modRequest","projectRoot","modResults","setUpdatesConfig","getSDKVersion","sdkVersion","getUpdatesEnabled","updates","enabled","getUpdatesTimeout","fallbackToCacheTimeout","getUpdatesCheckOnLaunch","checkAutomatically","semver","gte","androidManifest","username","mainApplication","ENABLED","String","CHECK_ON_LAUNCH","LAUNCH_WAIT_MS","updateUrl","UPDATE_URL","setVersionsConfig","runtimeVersion","SDK_VERSION","RUNTIME_VERSION","ensureBuildGradleContainsConfigurationScript","buildGradleContents","isBuildGradleConfigured","cleanedUpBuildGradleContents","isBuildGradleMisconfigured","split","some","line","includes","replace","RegExp","gradleScriptApply","formatApplyLineForBuildGradle","updatesGradleScriptPath","resolveFrom","silent","Error","relativePath","path","relative","join","posixPath","process","platform","androidBuildScript","isMainApplicationMetaDataSet","Boolean","isMainApplicationMetaDataSynced","areVersionsSynced","expectedRuntimeVersion","expectedSdkVersion","currentRuntimeVersion","currentSdkVersion"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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;;AAMA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;AAQA,MAAMA,4BAA4B,GAAG,qDAArC;IAEYC,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M;;AAWL,MAAMC,WAA0D,GAAG,CACxEC,MADwE,EAExE;AAAEC,EAAAA;AAAF,CAFwE,KAGrE;AACH,SAAO,2CAAoBD,MAApB,EAA4BA,MAAM,IAAI;AAC3C,UAAME,yBAAyB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AAT,CATnB;AAWD;;AAEM,SAASyC,iBAAT,CACL3D,MADK,EAELkB,eAFK,EAGI;AACT,QAAM0C,sBAAsB,GAAG,0CAA0B5D,MAA1B,EAAkC,SAAlC,CAA/B;AACA,QAAM6D,kBAAkB,GAAGtD,aAAa,CAACP,MAAD,CAAxC;AAEA,QAAM8D,qBAAqB,GAAG,iDAC5B5C,eAD4B,EAE5BpB,MAAM,CAACgC,eAFqB,CAA9B;AAIA,QAAMiC,iBAAiB,GAAG,iDAAgC7C,eAAhC,EAAiDpB,MAAM,CAAC+B,WAAxD,CAA1B;;AAEA,MAAI+B,sBAAsB,KAAK,IAA/B,EAAqC;AACnC,WAAOE,qBAAqB,KAAKF,sBAA1B,IAAoDG,iBAAiB,KAAK,IAAjF;AACD,GAFD,MAEO,IAAIF,kBAAkB,KAAK,IAA3B,EAAiC;AACtC,WAAOE,iBAAiB,KAAKF,kBAAtB,IAA4CC,qBAAqB,KAAK,IAA7E;AACD,GAFM,MAEA;AACL,WAAO,IAAP;AACD;AACF","sourcesContent":["import path from 'path';\nimport resolveFrom from 'resolve-from';\nimport semver from 'semver';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAndroidManifest } from '../plugins/android-plugins';\nimport {\n ExpoConfigUpdates,\n getExpoUpdatesPackageVersion,\n getRuntimeVersionNullable,\n getUpdateUrl,\n} from '../utils/Updates';\nimport {\n addMetaDataItemToMainApplication,\n AndroidManifest,\n getMainApplicationMetaDataValue,\n getMainApplicationOrThrow,\n removeMetaDataItemFromMainApplication,\n} from './Manifest';\n\nconst CREATE_MANIFEST_ANDROID_PATH = 'expo-updates/scripts/create-manifest-android.gradle';\n\nexport enum Config {\n ENABLED = 'expo.modules.updates.ENABLED',\n CHECK_ON_LAUNCH = 'expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH',\n LAUNCH_WAIT_MS = 'expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS',\n SDK_VERSION = 'expo.modules.updates.EXPO_SDK_VERSION',\n RUNTIME_VERSION = 'expo.modules.updates.EXPO_RUNTIME_VERSION',\n UPDATE_URL = 'expo.modules.updates.EXPO_UPDATE_URL',\n RELEASE_CHANNEL = 'expo.modules.updates.EXPO_RELEASE_CHANNEL',\n UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY = 'expo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY',\n}\n\nexport const withUpdates: ConfigPlugin<{ expoUsername: string | null }> = (\n config,\n { expoUsername }\n) => {\n return withAndroidManifest(config, config => {\n const expoUpdatesPackageVersion = getExpoUpdatesPackageVersion(config.modRequest.projectRoot);\n config.modResults = setUpdatesConfig(\n config,\n config.modResults,\n expoUsername,\n expoUpdatesPackageVersion\n );\n return config;\n });\n};\n\nexport function getSDKVersion(config: Pick<ExpoConfigUpdates, 'sdkVersion'>): string | null {\n return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;\n}\n\nexport function getUpdatesEnabled(config: Pick<ExpoConfigUpdates, 'updates'>): boolean {\n return config.updates?.enabled !== false;\n}\n\nexport function getUpdatesTimeout(config: Pick<ExpoConfigUpdates, 'updates'>): number {\n return config.updates?.fallbackToCacheTimeout ?? 0;\n}\n\nexport function getUpdatesCheckOnLaunch(\n config: Pick<ExpoConfigUpdates, 'updates'>,\n expoUpdatesPackageVersion?: string | null\n): 'NEVER' | 'ERROR_RECOVERY_ONLY' | 'ALWAYS' {\n if (config.updates?.checkAutomatically === 'ON_ERROR_RECOVERY') {\n // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x\n if (expoUpdatesPackageVersion && semver.gte(expoUpdatesPackageVersion, '0.11.0')) {\n return 'ERROR_RECOVERY_ONLY';\n }\n return 'NEVER';\n } else if (config.updates?.checkAutomatically === 'ON_LOAD') {\n return 'ALWAYS';\n }\n return 'ALWAYS';\n}\n\nexport function setUpdatesConfig(\n config: ExpoConfigUpdates,\n androidManifest: AndroidManifest,\n username: string | null,\n expoUpdatesPackageVersion?: string | null\n): AndroidManifest {\n const mainApplication = getMainApplicationOrThrow(androidManifest);\n\n addMetaDataItemToMainApplication(\n mainApplication,\n Config.ENABLED,\n String(getUpdatesEnabled(config))\n );\n addMetaDataItemToMainApplication(\n mainApplication,\n Config.CHECK_ON_LAUNCH,\n getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion)\n );\n addMetaDataItemToMainApplication(\n mainApplication,\n Config.LAUNCH_WAIT_MS,\n String(getUpdatesTimeout(config))\n );\n\n const updateUrl = getUpdateUrl(config, username);\n if (updateUrl) {\n addMetaDataItemToMainApplication(mainApplication, Config.UPDATE_URL, updateUrl);\n } else {\n removeMetaDataItemFromMainApplication(mainApplication, Config.UPDATE_URL);\n }\n\n return setVersionsConfig(config, androidManifest);\n}\n\nexport function setVersionsConfig(\n config: Pick<ExpoConfigUpdates, 'sdkVersion' | 'runtimeVersion'>,\n androidManifest: AndroidManifest\n): AndroidManifest {\n const mainApplication = getMainApplicationOrThrow(androidManifest);\n\n const runtimeVersion = getRuntimeVersionNullable(config, 'android');\n const sdkVersion = getSDKVersion(config);\n if (runtimeVersion) {\n removeMetaDataItemFromMainApplication(mainApplication, Config.SDK_VERSION);\n addMetaDataItemToMainApplication(mainApplication, Config.RUNTIME_VERSION, runtimeVersion);\n } else if (sdkVersion) {\n /**\n * runtime version maybe null in projects using classic updates. In that\n * case we use SDK version\n */\n removeMetaDataItemFromMainApplication(mainApplication, Config.RUNTIME_VERSION);\n addMetaDataItemToMainApplication(mainApplication, Config.SDK_VERSION, sdkVersion);\n } else {\n removeMetaDataItemFromMainApplication(mainApplication, Config.RUNTIME_VERSION);\n removeMetaDataItemFromMainApplication(mainApplication, Config.SDK_VERSION);\n }\n\n return androidManifest;\n}\nexport function ensureBuildGradleContainsConfigurationScript(\n projectRoot: string,\n buildGradleContents: string\n): string {\n if (!isBuildGradleConfigured(projectRoot, buildGradleContents)) {\n let cleanedUpBuildGradleContents;\n\n const isBuildGradleMisconfigured = buildGradleContents\n .split('\\n')\n .some(line => line.includes(CREATE_MANIFEST_ANDROID_PATH));\n if (isBuildGradleMisconfigured) {\n cleanedUpBuildGradleContents = buildGradleContents.replace(\n new RegExp(`(\\n// Integration with Expo updates)?\\n.*${CREATE_MANIFEST_ANDROID_PATH}.*\\n`),\n ''\n );\n } else {\n cleanedUpBuildGradleContents = buildGradleContents;\n }\n\n const gradleScriptApply = formatApplyLineForBuildGradle(projectRoot);\n return `${cleanedUpBuildGradleContents}\\n// Integration with Expo updates\\n${gradleScriptApply}\\n`;\n } else {\n return buildGradleContents;\n }\n}\n\nexport function formatApplyLineForBuildGradle(projectRoot: string): string {\n const updatesGradleScriptPath = resolveFrom.silent(projectRoot, CREATE_MANIFEST_ANDROID_PATH);\n\n if (!updatesGradleScriptPath) {\n throw new Error(\n \"Could not find the build script for Android. This could happen in case of outdated 'node_modules'. Run 'npm install' to make sure that it's up-to-date.\"\n );\n }\n\n const relativePath = path.relative(\n path.join(projectRoot, 'android', 'app'),\n updatesGradleScriptPath\n );\n const posixPath = process.platform === 'win32' ? relativePath.replace(/\\\\/g, '/') : relativePath;\n\n return `apply from: \"${posixPath}\"`;\n}\n\nexport function isBuildGradleConfigured(projectRoot: string, buildGradleContents: string): boolean {\n const androidBuildScript = formatApplyLineForBuildGradle(projectRoot);\n\n return (\n buildGradleContents\n .replace(/\\r\\n/g, '\\n')\n .split('\\n')\n // Check for both single and double quotes\n .some(line => line === androidBuildScript || line === androidBuildScript.replace(/\"/g, \"'\"))\n );\n}\n\nexport function isMainApplicationMetaDataSet(androidManifest: AndroidManifest): boolean {\n const updateUrl = getMainApplicationMetaDataValue(androidManifest, Config.UPDATE_URL);\n const runtimeVersion = getMainApplicationMetaDataValue(androidManifest, Config.RUNTIME_VERSION);\n const sdkVersion = getMainApplicationMetaDataValue(androidManifest, Config.SDK_VERSION);\n\n return Boolean(updateUrl && (sdkVersion || runtimeVersion));\n}\n\nexport function isMainApplicationMetaDataSynced(\n config: ExpoConfigUpdates,\n androidManifest: AndroidManifest,\n username: string | null\n): boolean {\n return (\n getUpdateUrl(config, username) ===\n getMainApplicationMetaDataValue(androidManifest, Config.UPDATE_URL) &&\n String(getUpdatesEnabled(config)) ===\n getMainApplicationMetaDataValue(androidManifest, Config.ENABLED) &&\n String(getUpdatesTimeout(config)) ===\n getMainApplicationMetaDataValue(androidManifest, Config.LAUNCH_WAIT_MS) &&\n getUpdatesCheckOnLaunch(config) ===\n getMainApplicationMetaDataValue(androidManifest, Config.CHECK_ON_LAUNCH) &&\n areVersionsSynced(config, androidManifest)\n );\n}\n\nexport function areVersionsSynced(\n config: Pick<ExpoConfigUpdates, 'runtimeVersion' | 'sdkVersion'>,\n androidManifest: AndroidManifest\n): boolean {\n const expectedRuntimeVersion = getRuntimeVersionNullable(config, 'android');\n const expectedSdkVersion = getSDKVersion(config);\n\n const currentRuntimeVersion = getMainApplicationMetaDataValue(\n androidManifest,\n Config.RUNTIME_VERSION\n );\n const currentSdkVersion = getMainApplicationMetaDataValue(androidManifest, Config.SDK_VERSION);\n\n if (expectedRuntimeVersion !== null) {\n return currentRuntimeVersion === expectedRuntimeVersion && currentSdkVersion === null;\n } else if (expectedSdkVersion !== null) {\n return currentSdkVersion === expectedSdkVersion && currentRuntimeVersion === null;\n } else {\n return true;\n }\n}\n"],"file":"Updates.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/android/Updates.ts"],"names":["CREATE_MANIFEST_ANDROID_PATH","Config","withUpdates","config","expoUsername","expoUpdatesPackageVersion","modRequest","projectRoot","modResults","setUpdatesConfig","getSDKVersion","sdkVersion","getUpdatesEnabled","updates","enabled","getUpdatesTimeout","fallbackToCacheTimeout","getUpdatesCheckOnLaunch","checkAutomatically","semver","gte","androidManifest","username","mainApplication","ENABLED","String","CHECK_ON_LAUNCH","LAUNCH_WAIT_MS","updateUrl","UPDATE_URL","setVersionsConfig","runtimeVersion","RUNTIME_VERSION","Error","SDK_VERSION","ensureBuildGradleContainsConfigurationScript","buildGradleContents","isBuildGradleConfigured","cleanedUpBuildGradleContents","isBuildGradleMisconfigured","split","some","line","includes","replace","RegExp","gradleScriptApply","formatApplyLineForBuildGradle","updatesGradleScriptPath","resolveFrom","silent","relativePath","path","relative","join","posixPath","process","platform","androidBuildScript","isMainApplicationMetaDataSet","Boolean","isMainApplicationMetaDataSynced","areVersionsSynced","expectedRuntimeVersion","expectedSdkVersion","currentRuntimeVersion","currentSdkVersion"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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;;AAMA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;AASA,MAAMA,4BAA4B,GAAG,qDAArC;IAEYC,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M;;AAWL,MAAMC,WAA0D,GAAG,CACxEC,MADwE,EAExE;AAAEC,EAAAA;AAAF,CAFwE,KAGrE;AACH,SAAO,2CAAoBD,MAApB,EAA4BA,MAAM,IAAI;AAC3C,UAAME,yBAAyB,GAAG,6CAA6BF,MAAM,CAACG,UAAP,CAAkBC,WAA/C,CAAlC;AACAJ,IAAAA,MAAM,CAACK,UAAP,GAAoBC,gBAAgB,CAClCN,MADkC,EAElCA,MAAM,CAACK,UAF2B,EAGlCJ,YAHkC,EAIlCC,yBAJkC,CAApC;AAMA,WAAOF,MAAP;AACD,GATM,CAAP;AAUD,CAdM;;;;AAgBA,SAASO,aAAT,CAAuBP,MAAvB,EAAqF;AAC1F,SAAO,OAAOA,MAAM,CAACQ,UAAd,KAA6B,QAA7B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P,MAAD,CAAxC;AAEA,QAAM8D,qBAAqB,GAAG,iDAC5B5C,eAD4B,EAE5BpB,MAAM,CAAC+B,eAFqB,CAA9B;AAIA,QAAMkC,iBAAiB,GAAG,iDAAgC7C,eAAhC,EAAiDpB,MAAM,CAACiC,WAAxD,CAA1B;;AAEA,MAAI6B,sBAAsB,KAAK,IAA/B,EAAqC;AACnC,WAAOE,qBAAqB,KAAKF,sBAA1B,IAAoDG,iBAAiB,KAAK,IAAjF;AACD,GAFD,MAEO,IAAIF,kBAAkB,KAAK,IAA3B,EAAiC;AACtC,WAAOE,iBAAiB,KAAKF,kBAAtB,IAA4CC,qBAAqB,KAAK,IAA7E;AACD,GAFM,MAEA;AACL,WAAO,IAAP;AACD;AACF","sourcesContent":["import path from 'path';\nimport resolveFrom from 'resolve-from';\nimport semver from 'semver';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAndroidManifest } from '../plugins/android-plugins';\nimport {\n ExpoConfigUpdates,\n getExpoUpdatesPackageVersion,\n getRuntimeVersionNullable,\n getUpdateUrl,\n} from '../utils/Updates';\nimport {\n addMetaDataItemToMainApplication,\n AndroidManifest,\n findMetaDataItem,\n getMainApplicationMetaDataValue,\n getMainApplicationOrThrow,\n removeMetaDataItemFromMainApplication,\n} from './Manifest';\n\nconst CREATE_MANIFEST_ANDROID_PATH = 'expo-updates/scripts/create-manifest-android.gradle';\n\nexport enum Config {\n ENABLED = 'expo.modules.updates.ENABLED',\n CHECK_ON_LAUNCH = 'expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH',\n LAUNCH_WAIT_MS = 'expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS',\n SDK_VERSION = 'expo.modules.updates.EXPO_SDK_VERSION',\n RUNTIME_VERSION = 'expo.modules.updates.EXPO_RUNTIME_VERSION',\n UPDATE_URL = 'expo.modules.updates.EXPO_UPDATE_URL',\n RELEASE_CHANNEL = 'expo.modules.updates.EXPO_RELEASE_CHANNEL',\n UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY = 'expo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY',\n}\n\nexport const withUpdates: ConfigPlugin<{ expoUsername: string | null }> = (\n config,\n { expoUsername }\n) => {\n return withAndroidManifest(config, config => {\n const expoUpdatesPackageVersion = getExpoUpdatesPackageVersion(config.modRequest.projectRoot);\n config.modResults = setUpdatesConfig(\n config,\n config.modResults,\n expoUsername,\n expoUpdatesPackageVersion\n );\n return config;\n });\n};\n\nexport function getSDKVersion(config: Pick<ExpoConfigUpdates, 'sdkVersion'>): string | null {\n return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;\n}\n\nexport function getUpdatesEnabled(config: Pick<ExpoConfigUpdates, 'updates'>): boolean {\n return config.updates?.enabled !== false;\n}\n\nexport function getUpdatesTimeout(config: Pick<ExpoConfigUpdates, 'updates'>): number {\n return config.updates?.fallbackToCacheTimeout ?? 0;\n}\n\nexport function getUpdatesCheckOnLaunch(\n config: Pick<ExpoConfigUpdates, 'updates'>,\n expoUpdatesPackageVersion?: string | null\n): 'NEVER' | 'ERROR_RECOVERY_ONLY' | 'ALWAYS' {\n if (config.updates?.checkAutomatically === 'ON_ERROR_RECOVERY') {\n // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x\n if (expoUpdatesPackageVersion && semver.gte(expoUpdatesPackageVersion, '0.11.0')) {\n return 'ERROR_RECOVERY_ONLY';\n }\n return 'NEVER';\n } else if (config.updates?.checkAutomatically === 'ON_LOAD') {\n return 'ALWAYS';\n }\n return 'ALWAYS';\n}\n\nexport function setUpdatesConfig(\n config: ExpoConfigUpdates,\n androidManifest: AndroidManifest,\n username: string | null,\n expoUpdatesPackageVersion?: string | null\n): AndroidManifest {\n const mainApplication = getMainApplicationOrThrow(androidManifest);\n\n addMetaDataItemToMainApplication(\n mainApplication,\n Config.ENABLED,\n String(getUpdatesEnabled(config))\n );\n addMetaDataItemToMainApplication(\n mainApplication,\n Config.CHECK_ON_LAUNCH,\n getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion)\n );\n addMetaDataItemToMainApplication(\n mainApplication,\n Config.LAUNCH_WAIT_MS,\n String(getUpdatesTimeout(config))\n );\n\n const updateUrl = getUpdateUrl(config, username);\n if (updateUrl) {\n addMetaDataItemToMainApplication(mainApplication, Config.UPDATE_URL, updateUrl);\n } else {\n removeMetaDataItemFromMainApplication(mainApplication, Config.UPDATE_URL);\n }\n\n return setVersionsConfig(config, androidManifest);\n}\n\nexport function setVersionsConfig(\n config: Pick<ExpoConfigUpdates, 'sdkVersion' | 'runtimeVersion'>,\n androidManifest: AndroidManifest\n): AndroidManifest {\n const mainApplication = getMainApplicationOrThrow(androidManifest);\n\n const runtimeVersion = getRuntimeVersionNullable(config, 'android');\n if (!runtimeVersion && findMetaDataItem(mainApplication, Config.RUNTIME_VERSION) > -1) {\n throw new Error(\n 'A runtime version is set in your AndroidManifest.xml, but is missing from your app.json/app.config.js. Please either set runtimeVersion in your app.json/app.config.js or remove expo.modules.updates.EXPO_RUNTIME_VERSION from your AndroidManifest.xml.'\n );\n }\n const sdkVersion = getSDKVersion(config);\n if (runtimeVersion) {\n removeMetaDataItemFromMainApplication(mainApplication, Config.SDK_VERSION);\n addMetaDataItemToMainApplication(mainApplication, Config.RUNTIME_VERSION, runtimeVersion);\n } else if (sdkVersion) {\n /**\n * runtime version maybe null in projects using classic updates. In that\n * case we use SDK version\n */\n removeMetaDataItemFromMainApplication(mainApplication, Config.RUNTIME_VERSION);\n addMetaDataItemToMainApplication(mainApplication, Config.SDK_VERSION, sdkVersion);\n } else {\n removeMetaDataItemFromMainApplication(mainApplication, Config.RUNTIME_VERSION);\n removeMetaDataItemFromMainApplication(mainApplication, Config.SDK_VERSION);\n }\n\n return androidManifest;\n}\nexport function ensureBuildGradleContainsConfigurationScript(\n projectRoot: string,\n buildGradleContents: string\n): string {\n if (!isBuildGradleConfigured(projectRoot, buildGradleContents)) {\n let cleanedUpBuildGradleContents;\n\n const isBuildGradleMisconfigured = buildGradleContents\n .split('\\n')\n .some(line => line.includes(CREATE_MANIFEST_ANDROID_PATH));\n if (isBuildGradleMisconfigured) {\n cleanedUpBuildGradleContents = buildGradleContents.replace(\n new RegExp(`(\\n// Integration with Expo updates)?\\n.*${CREATE_MANIFEST_ANDROID_PATH}.*\\n`),\n ''\n );\n } else {\n cleanedUpBuildGradleContents = buildGradleContents;\n }\n\n const gradleScriptApply = formatApplyLineForBuildGradle(projectRoot);\n return `${cleanedUpBuildGradleContents}\\n// Integration with Expo updates\\n${gradleScriptApply}\\n`;\n } else {\n return buildGradleContents;\n }\n}\n\nexport function formatApplyLineForBuildGradle(projectRoot: string): string {\n const updatesGradleScriptPath = resolveFrom.silent(projectRoot, CREATE_MANIFEST_ANDROID_PATH);\n\n if (!updatesGradleScriptPath) {\n throw new Error(\n \"Could not find the build script for Android. This could happen in case of outdated 'node_modules'. Run 'npm install' to make sure that it's up-to-date.\"\n );\n }\n\n const relativePath = path.relative(\n path.join(projectRoot, 'android', 'app'),\n updatesGradleScriptPath\n );\n const posixPath = process.platform === 'win32' ? relativePath.replace(/\\\\/g, '/') : relativePath;\n\n return `apply from: \"${posixPath}\"`;\n}\n\nexport function isBuildGradleConfigured(projectRoot: string, buildGradleContents: string): boolean {\n const androidBuildScript = formatApplyLineForBuildGradle(projectRoot);\n\n return (\n buildGradleContents\n .replace(/\\r\\n/g, '\\n')\n .split('\\n')\n // Check for both single and double quotes\n .some(line => line === androidBuildScript || line === androidBuildScript.replace(/\"/g, \"'\"))\n );\n}\n\nexport function isMainApplicationMetaDataSet(androidManifest: AndroidManifest): boolean {\n const updateUrl = getMainApplicationMetaDataValue(androidManifest, Config.UPDATE_URL);\n const runtimeVersion = getMainApplicationMetaDataValue(androidManifest, Config.RUNTIME_VERSION);\n const sdkVersion = getMainApplicationMetaDataValue(androidManifest, Config.SDK_VERSION);\n\n return Boolean(updateUrl && (sdkVersion || runtimeVersion));\n}\n\nexport function isMainApplicationMetaDataSynced(\n config: ExpoConfigUpdates,\n androidManifest: AndroidManifest,\n username: string | null\n): boolean {\n return (\n getUpdateUrl(config, username) ===\n getMainApplicationMetaDataValue(androidManifest, Config.UPDATE_URL) &&\n String(getUpdatesEnabled(config)) ===\n getMainApplicationMetaDataValue(androidManifest, Config.ENABLED) &&\n String(getUpdatesTimeout(config)) ===\n getMainApplicationMetaDataValue(androidManifest, Config.LAUNCH_WAIT_MS) &&\n getUpdatesCheckOnLaunch(config) ===\n getMainApplicationMetaDataValue(androidManifest, Config.CHECK_ON_LAUNCH) &&\n areVersionsSynced(config, androidManifest)\n );\n}\n\nexport function areVersionsSynced(\n config: Pick<ExpoConfigUpdates, 'runtimeVersion' | 'sdkVersion'>,\n androidManifest: AndroidManifest\n): boolean {\n const expectedRuntimeVersion = getRuntimeVersionNullable(config, 'android');\n const expectedSdkVersion = getSDKVersion(config);\n\n const currentRuntimeVersion = getMainApplicationMetaDataValue(\n androidManifest,\n Config.RUNTIME_VERSION\n );\n const currentSdkVersion = getMainApplicationMetaDataValue(androidManifest, Config.SDK_VERSION);\n\n if (expectedRuntimeVersion !== null) {\n return currentRuntimeVersion === expectedRuntimeVersion && currentSdkVersion === null;\n } else if (expectedSdkVersion !== null) {\n return currentSdkVersion === expectedSdkVersion && currentRuntimeVersion === null;\n } else {\n return true;\n }\n}\n"],"file":"Updates.js"}
|
package/build/ios/Maps.d.ts
CHANGED
|
@@ -10,10 +10,8 @@ export declare function removeGoogleMapsAppDelegateImport(src: string): MergeRes
|
|
|
10
10
|
export declare function addGoogleMapsAppDelegateInit(src: string, apiKey: string): MergeResults;
|
|
11
11
|
export declare function removeGoogleMapsAppDelegateInit(src: string): MergeResults;
|
|
12
12
|
/**
|
|
13
|
-
* @param src
|
|
14
|
-
* @
|
|
15
|
-
* @param googleMapsPath '../node_modules/react-native-maps'
|
|
16
|
-
* @returns
|
|
13
|
+
* @param src The contents of the Podfile.
|
|
14
|
+
* @returns Podfile with Google Maps added.
|
|
17
15
|
*/
|
|
18
|
-
export declare function addMapsCocoaPods(src: string
|
|
16
|
+
export declare function addMapsCocoaPods(src: string): MergeResults;
|
|
19
17
|
export declare function removeMapsCocoaPods(src: string): MergeResults;
|
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
|
|
|
@@ -161,18 +161,16 @@ function removeGoogleMapsAppDelegateInit(src) {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* @param src
|
|
165
|
-
* @
|
|
166
|
-
* @param googleMapsPath '../node_modules/react-native-maps'
|
|
167
|
-
* @returns
|
|
164
|
+
* @param src The contents of the Podfile.
|
|
165
|
+
* @returns Podfile with Google Maps added.
|
|
168
166
|
*/
|
|
169
167
|
|
|
170
168
|
|
|
171
|
-
function addMapsCocoaPods(src
|
|
169
|
+
function addMapsCocoaPods(src) {
|
|
172
170
|
return (0, _generateCode().mergeContents)({
|
|
173
171
|
tag: 'react-native-maps',
|
|
174
172
|
src,
|
|
175
|
-
newSrc: ` pod 'react-native-google-maps', path: '
|
|
173
|
+
newSrc: ` pod 'react-native-google-maps', path: File.dirname(\`node --print "require.resolve('react-native-maps/package.json')"\`)`,
|
|
176
174
|
anchor: /use_native_modules/,
|
|
177
175
|
offset: 0,
|
|
178
176
|
comment: '#'
|
|
@@ -193,8 +191,15 @@ function isReactNativeMapsInstalled(projectRoot) {
|
|
|
193
191
|
}
|
|
194
192
|
|
|
195
193
|
function isReactNativeMapsAutolinked(config) {
|
|
196
|
-
//
|
|
197
|
-
|
|
194
|
+
// Only add the native code changes if we know that the package is going to be linked natively.
|
|
195
|
+
// This is specifically for monorepo support where one app might have react-native-maps (adding it to the node_modules)
|
|
196
|
+
// but another app will not have it installed in the package.json, causing it to not be linked natively.
|
|
197
|
+
// This workaround only exists because react-native-maps doesn't have a config plugin vendored in the package.
|
|
198
|
+
// TODO: `react-native-maps` doesn't use Expo autolinking so we cannot safely disable the module.
|
|
199
|
+
return true; // return (
|
|
200
|
+
// !config._internal?.autolinkedModules ||
|
|
201
|
+
// config._internal.autolinkedModules.includes('react-native-maps')
|
|
202
|
+
// );
|
|
198
203
|
}
|
|
199
204
|
|
|
200
205
|
const withMapsCocoaPods = (config, {
|
|
@@ -213,11 +218,8 @@ const withMapsCocoaPods = (config, {
|
|
|
213
218
|
debug('react-native-maps path:', googleMapsPath);
|
|
214
219
|
|
|
215
220
|
if (isLinked && googleMapsPath && useGoogleMaps) {
|
|
216
|
-
// Make the pod path relative to the ios folder.
|
|
217
|
-
const googleMapsPodPath = _path().default.relative(config.modRequest.platformProjectRoot, googleMapsPath);
|
|
218
|
-
|
|
219
221
|
try {
|
|
220
|
-
results = addMapsCocoaPods(contents
|
|
222
|
+
results = addMapsCocoaPods(contents);
|
|
221
223
|
} catch (error) {
|
|
222
224
|
if (error.code === 'ERR_NO_MATCH') {
|
|
223
225
|
throw new Error(`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.`);
|
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","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,EAAA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ACiD,UAAP,CAAkBb,QAD0C,CAAjC,CAE3BA,QAFF;AAGApC,QAAAA,MAAM,CAACiD,UAAP,CAAkBb,QAAlB,GAA6Bf,+BAA+B,CAC1DrB,MAAM,CAACiD,UAAP,CAAkBb,QADwC,CAA/B,CAE3BA,QAFF;AAGD;AACF,KA9BD,MA8BO;AACL,YAAM,IAAIS,KAAJ,CAAU,qEAAV,CAAN;AACD;;AACD,WAAO7C,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'>): boolean {\n // TODO: Detect autolinking\n return true;\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","removeMapsCocoaPods","isReactNativeMapsInstalled","projectRoot","resolved","resolveFrom","silent","path","dirname","isReactNativeMapsAutolinked","filePath","modRequest","platformProjectRoot","contents","fs","readFile","results","googleMapsPath","isLinked","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,2MAAn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DnB,MAAM,CAAC+C,UAAP,CAAkBZ,QAD0C,CAAjC,CAE3BA,QAFF;AAGAnC,QAAAA,MAAM,CAAC+C,UAAP,CAAkBZ,QAAlB,GAA6Bd,+BAA+B,CAC1DrB,MAAM,CAAC+C,UAAP,CAAkBZ,QADwC,CAA/B,CAE3BA,QAFF;AAGD;AACF,KA9BD,MA8BO;AACL,YAAM,IAAIQ,KAAJ,CAAU,qEAAV,CAAN;AACD;;AACD,WAAO3C,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 The contents of the Podfile.\n * @returns Podfile with Google Maps added.\n */\nexport function addMapsCocoaPods(src: string): MergeResults {\n return mergeContents({\n tag: 'react-native-maps',\n src,\n newSrc: ` pod 'react-native-google-maps', path: File.dirname(\\`node --print \"require.resolve('react-native-maps/package.json')\"\\`)`,\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'>): boolean {\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\n // TODO: `react-native-maps` doesn't use Expo autolinking so we cannot safely disable the module.\n return true;\n\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 try {\n results = addMapsCocoaPods(contents);\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"}
|
package/build/ios/Name.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { ExpoConfig } from '@expo/config-types';
|
|
2
|
+
import { XcodeProject } from 'xcode';
|
|
3
|
+
import { ConfigPlugin } from '../Plugin.types';
|
|
2
4
|
import { InfoPlist } from './IosConfig.types';
|
|
3
|
-
export declare const withDisplayName:
|
|
4
|
-
export declare const withName:
|
|
5
|
+
export declare const withDisplayName: ConfigPlugin<void>;
|
|
6
|
+
export declare const withName: ConfigPlugin<void>;
|
|
7
|
+
/** Set the PRODUCT_NAME variable in the xcproj file based on the app.json name property. */
|
|
8
|
+
export declare const withProductName: ConfigPlugin;
|
|
5
9
|
export declare function getName(config: Pick<ExpoConfig, 'name'>): string | null;
|
|
6
10
|
/**
|
|
7
11
|
* CFBundleDisplayName is used for most things: the name on the home screen, in
|
|
@@ -13,3 +17,4 @@ export declare function setDisplayName(configOrName: Pick<ExpoConfig, 'name'> |
|
|
|
13
17
|
* sometimes on the App Store
|
|
14
18
|
*/
|
|
15
19
|
export declare function setName(config: Pick<ExpoConfig, 'name'>, { CFBundleName, ...infoPlist }: InfoPlist): InfoPlist;
|
|
20
|
+
export declare function setProductName(config: Pick<ExpoConfig, 'name'>, project: XcodeProject): XcodeProject;
|
package/build/ios/Name.js
CHANGED
|
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getName = getName;
|
|
7
7
|
exports.setDisplayName = setDisplayName;
|
|
8
8
|
exports.setName = setName;
|
|
9
|
-
exports.
|
|
9
|
+
exports.setProductName = setProductName;
|
|
10
|
+
exports.withProductName = exports.withName = exports.withDisplayName = void 0;
|
|
10
11
|
|
|
11
12
|
function _iosPlugins() {
|
|
12
13
|
const data = require("../plugins/ios-plugins");
|
|
@@ -18,11 +19,42 @@ function _iosPlugins() {
|
|
|
18
19
|
return data;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
function _Target() {
|
|
23
|
+
const data = require("./Target");
|
|
24
|
+
|
|
25
|
+
_Target = function () {
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _Xcodeproj() {
|
|
33
|
+
const data = require("./utils/Xcodeproj");
|
|
34
|
+
|
|
35
|
+
_Xcodeproj = function () {
|
|
36
|
+
return data;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
|
|
21
42
|
const withDisplayName = (0, _iosPlugins().createInfoPlistPlugin)(setDisplayName, 'withDisplayName');
|
|
22
43
|
exports.withDisplayName = withDisplayName;
|
|
23
44
|
const withName = (0, _iosPlugins().createInfoPlistPlugin)(setName, 'withName');
|
|
45
|
+
/** Set the PRODUCT_NAME variable in the xcproj file based on the app.json name property. */
|
|
46
|
+
|
|
24
47
|
exports.withName = withName;
|
|
25
48
|
|
|
49
|
+
const withProductName = config => {
|
|
50
|
+
return (0, _iosPlugins().withXcodeProject)(config, config => {
|
|
51
|
+
config.modResults = setProductName(config, config.modResults);
|
|
52
|
+
return config;
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.withProductName = withProductName;
|
|
57
|
+
|
|
26
58
|
function getName(config) {
|
|
27
59
|
return typeof config.name === 'string' ? config.name : null;
|
|
28
60
|
}
|
|
@@ -72,4 +104,29 @@ function setName(config, {
|
|
|
72
104
|
CFBundleName: name
|
|
73
105
|
};
|
|
74
106
|
}
|
|
107
|
+
|
|
108
|
+
function setProductName(config, project) {
|
|
109
|
+
var _getName;
|
|
110
|
+
|
|
111
|
+
const name = (0, _Xcodeproj().sanitizedName)((_getName = getName(config)) !== null && _getName !== void 0 ? _getName : '');
|
|
112
|
+
|
|
113
|
+
if (!name) {
|
|
114
|
+
return project;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const quotedName = ensureQuotes(name);
|
|
118
|
+
const [, nativeTarget] = (0, _Target().findFirstNativeTarget)(project);
|
|
119
|
+
(0, _Xcodeproj().getBuildConfigurationsForListId)(project, nativeTarget.buildConfigurationList).forEach(([, item]) => {
|
|
120
|
+
item.buildSettings.PRODUCT_NAME = quotedName;
|
|
121
|
+
});
|
|
122
|
+
return project;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const ensureQuotes = value => {
|
|
126
|
+
if (!value.match(/^['"]/)) {
|
|
127
|
+
return `"${value}"`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return value;
|
|
131
|
+
};
|
|
75
132
|
//# sourceMappingURL=Name.js.map
|
package/build/ios/Name.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ios/Name.ts"],"names":["withDisplayName","setDisplayName","withName","setName","
|
|
1
|
+
{"version":3,"sources":["../../src/ios/Name.ts"],"names":["withDisplayName","setDisplayName","withName","setName","withProductName","config","modResults","setProductName","getName","name","configOrName","CFBundleDisplayName","infoPlist","CFBundleName","project","quotedName","ensureQuotes","nativeTarget","buildConfigurationList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M;AACX,QAAMH,IAAI,GAAGD,OAAO,CAACH,MAAD,CAApB;;AAEA,MAAI,CAACI,IAAL,EAAW;AACT,WAAOG,SAAP;AACD;;AAED,SAAO,EACL,GAAGA,SADE;AAELC,IAAAA,YAAY,EAAEJ;AAFT,GAAP;AAID;;AAEM,SAASF,cAAT,CACLF,MADK,EAELS,OAFK,EAGS;AAAA;;AACd,QAAML,IAAI,GAAG,4CAAcD,OAAO,CAACH,MAAD,CAArB,+CAAiC,EAAjC,CAAb;;AAEA,MAAI,CAACI,IAAL,EAAW;AACT,WAAOK,OAAP;AACD;;AACD,QAAMC,UAAU,GAAGC,YAAY,CAACP,IAAD,CAA/B;AAEA,QAAM,GAAGQ,YAAH,IAAmB,qCAAsBH,OAAtB,CAAzB;AAEA,oDAAgCA,OAAhC,EAAyCG,YAAY,CAACC,sBAAtD,EAA8EC,OAA9E,CACE,CAAC,GAAGC,IAAH,CAAD,KAAyC;AACvCA,IAAAA,IAAI,CAACC,aAAL,CAAmBC,YAAnB,GAAkCP,UAAlC;AACD,GAHH;AAMA,SAAOD,OAAP;AACD;;AAED,MAAME,YAAY,GAAIO,KAAD,IAAmB;AACtC,MAAI,CAACA,KAAK,CAACC,KAAN,CAAY,OAAZ,CAAL,EAA2B;AACzB,WAAQ,IAAGD,KAAM,GAAjB;AACD;;AACD,SAAOA,KAAP;AACD,CALD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport { XcodeProject } from 'xcode';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { createInfoPlistPlugin, withXcodeProject } from '../plugins/ios-plugins';\nimport { InfoPlist } from './IosConfig.types';\nimport { findFirstNativeTarget } from './Target';\nimport {\n ConfigurationSectionEntry,\n getBuildConfigurationsForListId,\n sanitizedName,\n} from './utils/Xcodeproj';\n\nexport const withDisplayName = createInfoPlistPlugin(setDisplayName, 'withDisplayName');\n\nexport const withName = createInfoPlistPlugin(setName, 'withName');\n\n/** Set the PRODUCT_NAME variable in the xcproj file based on the app.json name property. */\nexport const withProductName: ConfigPlugin = config => {\n return withXcodeProject(config, config => {\n config.modResults = setProductName(config, config.modResults);\n return config;\n });\n};\n\nexport function getName(config: Pick<ExpoConfig, 'name'>) {\n return typeof config.name === 'string' ? config.name : null;\n}\n\n/**\n * CFBundleDisplayName is used for most things: the name on the home screen, in\n * notifications, and others.\n */\nexport function setDisplayName(\n configOrName: Pick<ExpoConfig, 'name'> | string,\n { CFBundleDisplayName, ...infoPlist }: InfoPlist\n): InfoPlist {\n let name: string | null = null;\n if (typeof configOrName === 'string') {\n name = configOrName;\n } else {\n name = getName(configOrName);\n }\n\n if (!name) {\n return infoPlist;\n }\n\n return {\n ...infoPlist,\n CFBundleDisplayName: name,\n };\n}\n\n/**\n * CFBundleName is recommended to be 16 chars or less and is used in lists, eg:\n * sometimes on the App Store\n */\nexport function setName(\n config: Pick<ExpoConfig, 'name'>,\n { CFBundleName, ...infoPlist }: InfoPlist\n): InfoPlist {\n const name = getName(config);\n\n if (!name) {\n return infoPlist;\n }\n\n return {\n ...infoPlist,\n CFBundleName: name,\n };\n}\n\nexport function setProductName(\n config: Pick<ExpoConfig, 'name'>,\n project: XcodeProject\n): XcodeProject {\n const name = sanitizedName(getName(config) ?? '');\n\n if (!name) {\n return project;\n }\n const quotedName = ensureQuotes(name);\n\n const [, nativeTarget] = findFirstNativeTarget(project);\n\n getBuildConfigurationsForListId(project, nativeTarget.buildConfigurationList).forEach(\n ([, item]: ConfigurationSectionEntry) => {\n item.buildSettings.PRODUCT_NAME = quotedName;\n }\n );\n\n return project;\n}\n\nconst ensureQuotes = (value: string) => {\n if (!value.match(/^['\"]/)) {\n return `\"${value}\"`;\n }\n return value;\n};\n"],"file":"Name.js"}
|
package/build/ios/Updates.js
CHANGED
|
@@ -155,6 +155,11 @@ function setVersionsConfig(config, expoPlist) {
|
|
|
155
155
|
const newExpoPlist = { ...expoPlist
|
|
156
156
|
};
|
|
157
157
|
const runtimeVersion = (0, _Updates().getRuntimeVersionNullable)(config, 'ios');
|
|
158
|
+
|
|
159
|
+
if (!runtimeVersion && expoPlist[Config.RUNTIME_VERSION]) {
|
|
160
|
+
throw new Error('A runtime version is set in your Expo.plist, but is missing from your app.json/app.config.js. Please either set runtimeVersion in your app.json/app.config.js or remove EXUpdatesRuntimeVersion from your Expo.plist.');
|
|
161
|
+
}
|
|
162
|
+
|
|
158
163
|
const sdkVersion = getSDKVersion(config);
|
|
159
164
|
|
|
160
165
|
if (runtimeVersion) {
|
package/build/ios/Updates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ios/Updates.ts"],"names":["CREATE_MANIFEST_IOS_PATH","Config","getSDKVersion","config","sdkVersion","getUpdatesEnabled","updates","enabled","getUpdatesTimeout","fallbackToCacheTimeout","getUpdatesCheckOnLaunch","expoUpdatesPackageVersion","checkAutomatically","semver","gte","withUpdates","expoUsername","modRequest","projectRoot","modResults","setUpdatesConfig","expoPlist","username","newExpoPlist","ENABLED","CHECK_ON_LAUNCH","LAUNCH_WAIT_MS","updateUrl","UPDATE_URL","setVersionsConfig","runtimeVersion","SDK_VERSION","RUNTIME_VERSION","formatConfigurationScriptPath","buildScriptPath","resolveFrom","silent","Error","relativePath","path","relative","join","process","platform","replace","getBundleReactNativePhase","project","shellScriptBuildPhase","hash","objects","PBXShellScriptBuildPhase","bundleReactNative","Object","values","find","buildPhase","name","ensureBundleReactNativePhaseContainsConfigurationScript","buildPhaseShellScriptPath","isShellScriptBuildPhaseConfigured","shellScript","includes","RegExp","isPlistConfigurationSet","Boolean","EXUpdatesURL","EXUpdatesSDKVersion","EXUpdatesRuntimeVersion","isPlistConfigurationSynced","EXUpdatesEnabled","EXUpdatesLaunchWaitMs","EXUpdatesCheckOnLaunch","isPlistVersionConfigurationSynced","expectedRuntimeVersion","expectedSdkVersion","currentRuntimeVersion","currentSdkVersion"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAC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,MADK,EAELkB,SAFK,EAGLC,QAHK,EAII;AACT,SACE,6BAAanB,MAAb,EAAqBmB,QAArB,MAAmCD,SAAS,CAAC4C,YAA7C,IACA5D,iBAAiB,CAACF,MAAD,CAAjB,KAA8BkB,SAAS,CAACgD,gBADxC,IAEA7D,iBAAiB,CAACL,MAAD,CAAjB,KAA8BkB,SAAS,CAACiD,qBAFxC,IAGA5D,uBAAuB,CAACP,MAAD,CAAvB,KAAoCkB,SAAS,CAACkD,sBAH9C,IAIAC,iCAAiC,CAACrE,MAAD,EAASkB,SAAT,CALnC;AAOD;;AAEM,SAASmD,iCAAT,CACLrE,MADK,EAELkB,SAFK,EAGI;AAAA;;AACT,QAAMoD,sBAAsB,GAAG,0CAA0BtE,MAA1B,EAAkC,KAAlC,CAA/B;AACA,QAAMuE,kBAAkB,GAAGxE,aAAa,CAACC,MAAD,CAAxC;AAEA,QAAMwE,qBAAqB,4BAAGtD,SAAS,CAAC8C,uBAAb,yEAAwC,IAAnE;AACA,QAAMS,iBAAiB,4BAAGvD,SAAS,CAAC6C,mBAAb,yEAAoC,IAA3D;;AAEA,MAAIO,sBAAsB,KAAK,IAA/B,EAAqC;AACnC,WAAOE,qBAAqB,KAAKF,sBAA1B,IAAoDG,iBAAiB,KAAK,IAAjF;AACD,GAFD,MAEO,IAAIF,kBAAkB,KAAK,IAA3B,EAAiC;AACtC,WAAOE,iBAAiB,KAAKF,kBAAtB,IAA4CC,qBAAqB,KAAK,IAA7E;AACD,GAFM,MAEA;AACL,WAAO,IAAP;AACD;AACF","sourcesContent":["import * as path from 'path';\nimport resolveFrom from 'resolve-from';\nimport semver from 'semver';\nimport xcode from 'xcode';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withExpoPlist } from '../plugins/ios-plugins';\nimport {\n ExpoConfigUpdates,\n getExpoUpdatesPackageVersion,\n getRuntimeVersionNullable,\n getUpdateUrl,\n} from '../utils/Updates';\nimport { ExpoPlist } from './IosConfig.types';\n\nconst CREATE_MANIFEST_IOS_PATH = 'expo-updates/scripts/create-manifest-ios.sh';\n\nexport enum Config {\n ENABLED = 'EXUpdatesEnabled',\n CHECK_ON_LAUNCH = 'EXUpdatesCheckOnLaunch',\n LAUNCH_WAIT_MS = 'EXUpdatesLaunchWaitMs',\n RUNTIME_VERSION = 'EXUpdatesRuntimeVersion',\n SDK_VERSION = 'EXUpdatesSDKVersion',\n UPDATE_URL = 'EXUpdatesURL',\n RELEASE_CHANNEL = 'EXUpdatesReleaseChannel',\n UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY = 'EXUpdatesRequestHeaders',\n}\n\nexport function getSDKVersion(config: Pick<ExpoConfigUpdates, 'sdkVersion'>): string | null {\n return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;\n}\n\nexport function getUpdatesEnabled(config: Pick<ExpoConfigUpdates, 'updates'>): boolean {\n return config.updates?.enabled !== false;\n}\n\nexport function getUpdatesTimeout(config: Pick<ExpoConfigUpdates, 'updates'>) {\n return config.updates?.fallbackToCacheTimeout ?? 0;\n}\n\nexport function getUpdatesCheckOnLaunch(\n config: Pick<ExpoConfigUpdates, 'updates'>,\n expoUpdatesPackageVersion?: string | null\n): 'NEVER' | 'ERROR_RECOVERY_ONLY' | 'ALWAYS' {\n if (config.updates?.checkAutomatically === 'ON_ERROR_RECOVERY') {\n // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x\n if (expoUpdatesPackageVersion && semver.gte(expoUpdatesPackageVersion, '0.11.0')) {\n return 'ERROR_RECOVERY_ONLY';\n }\n return 'NEVER';\n } else if (config.updates?.checkAutomatically === 'ON_LOAD') {\n return 'ALWAYS';\n }\n return 'ALWAYS';\n}\n\nexport const withUpdates: ConfigPlugin<{ expoUsername: string | null }> = (\n config,\n { expoUsername }\n) => {\n return withExpoPlist(config, config => {\n const expoUpdatesPackageVersion = getExpoUpdatesPackageVersion(config.modRequest.projectRoot);\n config.modResults = setUpdatesConfig(\n config,\n config.modResults,\n expoUsername,\n expoUpdatesPackageVersion\n );\n return config;\n });\n};\n\nexport function setUpdatesConfig(\n config: ExpoConfigUpdates,\n expoPlist: ExpoPlist,\n username: string | null,\n expoUpdatesPackageVersion?: string | null\n): ExpoPlist {\n const newExpoPlist = {\n ...expoPlist,\n [Config.ENABLED]: getUpdatesEnabled(config),\n [Config.CHECK_ON_LAUNCH]: getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion),\n [Config.LAUNCH_WAIT_MS]: getUpdatesTimeout(config),\n };\n\n const updateUrl = getUpdateUrl(config, username);\n if (updateUrl) {\n newExpoPlist[Config.UPDATE_URL] = updateUrl;\n } else {\n delete newExpoPlist[Config.UPDATE_URL];\n }\n\n return setVersionsConfig(config, newExpoPlist);\n}\n\nexport function setVersionsConfig(config: ExpoConfigUpdates, expoPlist: ExpoPlist): ExpoPlist {\n const newExpoPlist = { ...expoPlist };\n\n const runtimeVersion = getRuntimeVersionNullable(config, 'ios');\n const sdkVersion = getSDKVersion(config);\n if (runtimeVersion) {\n delete newExpoPlist[Config.SDK_VERSION];\n newExpoPlist[Config.RUNTIME_VERSION] = runtimeVersion;\n } else if (sdkVersion) {\n /**\n * runtime version maybe null in projects using classic updates. In that\n * case we use SDK version\n */\n delete newExpoPlist[Config.RUNTIME_VERSION];\n newExpoPlist[Config.SDK_VERSION] = sdkVersion;\n } else {\n delete newExpoPlist[Config.SDK_VERSION];\n delete newExpoPlist[Config.RUNTIME_VERSION];\n }\n\n return newExpoPlist;\n}\n\nfunction formatConfigurationScriptPath(projectRoot: string): string {\n const buildScriptPath = resolveFrom.silent(projectRoot, CREATE_MANIFEST_IOS_PATH);\n\n if (!buildScriptPath) {\n throw new Error(\n \"Could not find the build script for iOS. This could happen in case of outdated 'node_modules'. Run 'npm install' to make sure that it's up-to-date.\"\n );\n }\n\n const relativePath = path.relative(path.join(projectRoot, 'ios'), buildScriptPath);\n return process.platform === 'win32' ? relativePath.replace(/\\\\/g, '/') : relativePath;\n}\n\ninterface ShellScriptBuildPhase {\n isa: 'PBXShellScriptBuildPhase';\n name: string;\n shellScript: string;\n [key: string]: any;\n}\n\nexport function getBundleReactNativePhase(project: xcode.XcodeProject): ShellScriptBuildPhase {\n const shellScriptBuildPhase = project.hash.project.objects.PBXShellScriptBuildPhase as Record<\n string,\n ShellScriptBuildPhase\n >;\n const bundleReactNative = Object.values(shellScriptBuildPhase).find(\n buildPhase => buildPhase.name === '\"Bundle React Native code and images\"'\n );\n\n if (!bundleReactNative) {\n throw new Error(`Couldn't find a build phase \"Bundle React Native code and images\"`);\n }\n\n return bundleReactNative;\n}\n\nexport function ensureBundleReactNativePhaseContainsConfigurationScript(\n projectRoot: string,\n project: xcode.XcodeProject\n): xcode.XcodeProject {\n const bundleReactNative = getBundleReactNativePhase(project);\n const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);\n\n if (!isShellScriptBuildPhaseConfigured(projectRoot, project)) {\n // check if there's already another path to create-manifest-ios.sh\n // this might be the case for monorepos\n if (bundleReactNative.shellScript.includes(CREATE_MANIFEST_IOS_PATH)) {\n bundleReactNative.shellScript = bundleReactNative.shellScript.replace(\n new RegExp(`(\\\\\\\\n)(\\\\.\\\\.)+/node_modules/${CREATE_MANIFEST_IOS_PATH}`),\n ''\n );\n }\n bundleReactNative.shellScript = `${bundleReactNative.shellScript.replace(\n /\"$/,\n ''\n )}${buildPhaseShellScriptPath}\\\\n\"`;\n }\n return project;\n}\n\nexport function isShellScriptBuildPhaseConfigured(\n projectRoot: string,\n project: xcode.XcodeProject\n): boolean {\n const bundleReactNative = getBundleReactNativePhase(project);\n const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);\n return bundleReactNative.shellScript.includes(buildPhaseShellScriptPath);\n}\n\nexport function isPlistConfigurationSet(expoPlist: ExpoPlist): boolean {\n return Boolean(\n expoPlist.EXUpdatesURL && (expoPlist.EXUpdatesSDKVersion || expoPlist.EXUpdatesRuntimeVersion)\n );\n}\n\nexport function isPlistConfigurationSynced(\n config: ExpoConfigUpdates,\n expoPlist: ExpoPlist,\n username: string | null\n): boolean {\n return (\n getUpdateUrl(config, username) === expoPlist.EXUpdatesURL &&\n getUpdatesEnabled(config) === expoPlist.EXUpdatesEnabled &&\n getUpdatesTimeout(config) === expoPlist.EXUpdatesLaunchWaitMs &&\n getUpdatesCheckOnLaunch(config) === expoPlist.EXUpdatesCheckOnLaunch &&\n isPlistVersionConfigurationSynced(config, expoPlist)\n );\n}\n\nexport function isPlistVersionConfigurationSynced(\n config: Pick<ExpoConfigUpdates, 'sdkVersion' | 'runtimeVersion'>,\n expoPlist: ExpoPlist\n): boolean {\n const expectedRuntimeVersion = getRuntimeVersionNullable(config, 'ios');\n const expectedSdkVersion = getSDKVersion(config);\n\n const currentRuntimeVersion = expoPlist.EXUpdatesRuntimeVersion ?? null;\n const currentSdkVersion = expoPlist.EXUpdatesSDKVersion ?? null;\n\n if (expectedRuntimeVersion !== null) {\n return currentRuntimeVersion === expectedRuntimeVersion && currentSdkVersion === null;\n } else if (expectedSdkVersion !== null) {\n return currentSdkVersion === expectedSdkVersion && currentRuntimeVersion === null;\n } else {\n return true;\n }\n}\n"],"file":"Updates.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/ios/Updates.ts"],"names":["CREATE_MANIFEST_IOS_PATH","Config","getSDKVersion","config","sdkVersion","getUpdatesEnabled","updates","enabled","getUpdatesTimeout","fallbackToCacheTimeout","getUpdatesCheckOnLaunch","expoUpdatesPackageVersion","checkAutomatically","semver","gte","withUpdates","expoUsername","modRequest","projectRoot","modResults","setUpdatesConfig","expoPlist","username","newExpoPlist","ENABLED","CHECK_ON_LAUNCH","LAUNCH_WAIT_MS","updateUrl","UPDATE_URL","setVersionsConfig","runtimeVersion","RUNTIME_VERSION","Error","SDK_VERSION","formatConfigurationScriptPath","buildScriptPath","resolveFrom","silent","relativePath","path","relative","join","process","platform","replace","getBundleReactNativePhase","project","shellScriptBuildPhase","hash","objects","PBXShellScriptBuildPhase","bundleReactNative","Object","values","find","buildPhase","name","ensureBundleReactNativePhaseContainsConfigurationScript","buildPhaseShellScriptPath","isShellScriptBuildPhaseConfigured","shellScript","includes","RegExp","isPlistConfigurationSet","Boolean","EXUpdatesURL","EXUpdatesSDKVersion","EXUpdatesRuntimeVersion","isPlistConfigurationSynced","EXUpdatesEnabled","EXUpdatesLaunchWaitMs","EXUpdatesCheckOnLaunch","isPlistVersionConfigurationSynced","expectedRuntimeVersion","expectedSdkVersion","currentRuntimeVersion","currentSdkVersion"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;AAQA,MAAMA,wBAAwB,GAAG,6CAAjC;IAEYC,M;;;WAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;AAAAA,EAAAA,M;GAAAA,M,sBAAAA,M;;AAWL,SAASC,aAAT,CAAuBC,MAAvB,EAAqF;AAC1F,SAAO,OAAOA,MAAM,CAACC,UAAd,KAA6B,QAA7B,GAAwCD,MAAM,CAACC,UAA/C,GAA4D,IAAnE;AACD;;AAEM,SAASC,iBAAT,CAA2BF,MAA3B,EAAgF;AAAA;;AACrF,SAAO,oBAAAA,MAAM,CAACG,OAAP,oEAAgBC,OAAhB,MAA4B,KAAnC;AACD;;AAEM,SAASC,iBAAT,CAA2BL,MAA3B,EAAuE;AAAA;;AAC5E,sDAAOA,MAAM,CAACG,OAAd,qDAAO,iBAAgBG,sBAAvB,yEAAiD,CAAjD;AACD;;AAEM,SAASC,uBAAT,CACLP,MADK,EAELQ,yBAFK,EAGuC;AAAA;;AAC5C,MAAI,qBAAAR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BAAqB,KAAKF,sBAA1B,IAAoDG,iBAAiB,KAAK,IAAjF;AACD,GAFD,MAEO,IAAIF,kBAAkB,KAAK,IAA3B,EAAiC;AACtC,WAAOE,iBAAiB,KAAKF,kBAAtB,IAA4CC,qBAAqB,KAAK,IAA7E;AACD,GAFM,MAEA;AACL,WAAO,IAAP;AACD;AACF","sourcesContent":["import * as path from 'path';\nimport resolveFrom from 'resolve-from';\nimport semver from 'semver';\nimport xcode from 'xcode';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withExpoPlist } from '../plugins/ios-plugins';\nimport {\n ExpoConfigUpdates,\n getExpoUpdatesPackageVersion,\n getRuntimeVersionNullable,\n getUpdateUrl,\n} from '../utils/Updates';\nimport { ExpoPlist } from './IosConfig.types';\n\nconst CREATE_MANIFEST_IOS_PATH = 'expo-updates/scripts/create-manifest-ios.sh';\n\nexport enum Config {\n ENABLED = 'EXUpdatesEnabled',\n CHECK_ON_LAUNCH = 'EXUpdatesCheckOnLaunch',\n LAUNCH_WAIT_MS = 'EXUpdatesLaunchWaitMs',\n RUNTIME_VERSION = 'EXUpdatesRuntimeVersion',\n SDK_VERSION = 'EXUpdatesSDKVersion',\n UPDATE_URL = 'EXUpdatesURL',\n RELEASE_CHANNEL = 'EXUpdatesReleaseChannel',\n UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY = 'EXUpdatesRequestHeaders',\n}\n\nexport function getSDKVersion(config: Pick<ExpoConfigUpdates, 'sdkVersion'>): string | null {\n return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;\n}\n\nexport function getUpdatesEnabled(config: Pick<ExpoConfigUpdates, 'updates'>): boolean {\n return config.updates?.enabled !== false;\n}\n\nexport function getUpdatesTimeout(config: Pick<ExpoConfigUpdates, 'updates'>) {\n return config.updates?.fallbackToCacheTimeout ?? 0;\n}\n\nexport function getUpdatesCheckOnLaunch(\n config: Pick<ExpoConfigUpdates, 'updates'>,\n expoUpdatesPackageVersion?: string | null\n): 'NEVER' | 'ERROR_RECOVERY_ONLY' | 'ALWAYS' {\n if (config.updates?.checkAutomatically === 'ON_ERROR_RECOVERY') {\n // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x\n if (expoUpdatesPackageVersion && semver.gte(expoUpdatesPackageVersion, '0.11.0')) {\n return 'ERROR_RECOVERY_ONLY';\n }\n return 'NEVER';\n } else if (config.updates?.checkAutomatically === 'ON_LOAD') {\n return 'ALWAYS';\n }\n return 'ALWAYS';\n}\n\nexport const withUpdates: ConfigPlugin<{ expoUsername: string | null }> = (\n config,\n { expoUsername }\n) => {\n return withExpoPlist(config, config => {\n const expoUpdatesPackageVersion = getExpoUpdatesPackageVersion(config.modRequest.projectRoot);\n config.modResults = setUpdatesConfig(\n config,\n config.modResults,\n expoUsername,\n expoUpdatesPackageVersion\n );\n return config;\n });\n};\n\nexport function setUpdatesConfig(\n config: ExpoConfigUpdates,\n expoPlist: ExpoPlist,\n username: string | null,\n expoUpdatesPackageVersion?: string | null\n): ExpoPlist {\n const newExpoPlist = {\n ...expoPlist,\n [Config.ENABLED]: getUpdatesEnabled(config),\n [Config.CHECK_ON_LAUNCH]: getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion),\n [Config.LAUNCH_WAIT_MS]: getUpdatesTimeout(config),\n };\n\n const updateUrl = getUpdateUrl(config, username);\n if (updateUrl) {\n newExpoPlist[Config.UPDATE_URL] = updateUrl;\n } else {\n delete newExpoPlist[Config.UPDATE_URL];\n }\n\n return setVersionsConfig(config, newExpoPlist);\n}\n\nexport function setVersionsConfig(config: ExpoConfigUpdates, expoPlist: ExpoPlist): ExpoPlist {\n const newExpoPlist = { ...expoPlist };\n\n const runtimeVersion = getRuntimeVersionNullable(config, 'ios');\n if (!runtimeVersion && expoPlist[Config.RUNTIME_VERSION]) {\n throw new Error(\n 'A runtime version is set in your Expo.plist, but is missing from your app.json/app.config.js. Please either set runtimeVersion in your app.json/app.config.js or remove EXUpdatesRuntimeVersion from your Expo.plist.'\n );\n }\n const sdkVersion = getSDKVersion(config);\n if (runtimeVersion) {\n delete newExpoPlist[Config.SDK_VERSION];\n newExpoPlist[Config.RUNTIME_VERSION] = runtimeVersion;\n } else if (sdkVersion) {\n /**\n * runtime version maybe null in projects using classic updates. In that\n * case we use SDK version\n */\n delete newExpoPlist[Config.RUNTIME_VERSION];\n newExpoPlist[Config.SDK_VERSION] = sdkVersion;\n } else {\n delete newExpoPlist[Config.SDK_VERSION];\n delete newExpoPlist[Config.RUNTIME_VERSION];\n }\n\n return newExpoPlist;\n}\n\nfunction formatConfigurationScriptPath(projectRoot: string): string {\n const buildScriptPath = resolveFrom.silent(projectRoot, CREATE_MANIFEST_IOS_PATH);\n\n if (!buildScriptPath) {\n throw new Error(\n \"Could not find the build script for iOS. This could happen in case of outdated 'node_modules'. Run 'npm install' to make sure that it's up-to-date.\"\n );\n }\n\n const relativePath = path.relative(path.join(projectRoot, 'ios'), buildScriptPath);\n return process.platform === 'win32' ? relativePath.replace(/\\\\/g, '/') : relativePath;\n}\n\ninterface ShellScriptBuildPhase {\n isa: 'PBXShellScriptBuildPhase';\n name: string;\n shellScript: string;\n [key: string]: any;\n}\n\nexport function getBundleReactNativePhase(project: xcode.XcodeProject): ShellScriptBuildPhase {\n const shellScriptBuildPhase = project.hash.project.objects.PBXShellScriptBuildPhase as Record<\n string,\n ShellScriptBuildPhase\n >;\n const bundleReactNative = Object.values(shellScriptBuildPhase).find(\n buildPhase => buildPhase.name === '\"Bundle React Native code and images\"'\n );\n\n if (!bundleReactNative) {\n throw new Error(`Couldn't find a build phase \"Bundle React Native code and images\"`);\n }\n\n return bundleReactNative;\n}\n\nexport function ensureBundleReactNativePhaseContainsConfigurationScript(\n projectRoot: string,\n project: xcode.XcodeProject\n): xcode.XcodeProject {\n const bundleReactNative = getBundleReactNativePhase(project);\n const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);\n\n if (!isShellScriptBuildPhaseConfigured(projectRoot, project)) {\n // check if there's already another path to create-manifest-ios.sh\n // this might be the case for monorepos\n if (bundleReactNative.shellScript.includes(CREATE_MANIFEST_IOS_PATH)) {\n bundleReactNative.shellScript = bundleReactNative.shellScript.replace(\n new RegExp(`(\\\\\\\\n)(\\\\.\\\\.)+/node_modules/${CREATE_MANIFEST_IOS_PATH}`),\n ''\n );\n }\n bundleReactNative.shellScript = `${bundleReactNative.shellScript.replace(\n /\"$/,\n ''\n )}${buildPhaseShellScriptPath}\\\\n\"`;\n }\n return project;\n}\n\nexport function isShellScriptBuildPhaseConfigured(\n projectRoot: string,\n project: xcode.XcodeProject\n): boolean {\n const bundleReactNative = getBundleReactNativePhase(project);\n const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);\n return bundleReactNative.shellScript.includes(buildPhaseShellScriptPath);\n}\n\nexport function isPlistConfigurationSet(expoPlist: ExpoPlist): boolean {\n return Boolean(\n expoPlist.EXUpdatesURL && (expoPlist.EXUpdatesSDKVersion || expoPlist.EXUpdatesRuntimeVersion)\n );\n}\n\nexport function isPlistConfigurationSynced(\n config: ExpoConfigUpdates,\n expoPlist: ExpoPlist,\n username: string | null\n): boolean {\n return (\n getUpdateUrl(config, username) === expoPlist.EXUpdatesURL &&\n getUpdatesEnabled(config) === expoPlist.EXUpdatesEnabled &&\n getUpdatesTimeout(config) === expoPlist.EXUpdatesLaunchWaitMs &&\n getUpdatesCheckOnLaunch(config) === expoPlist.EXUpdatesCheckOnLaunch &&\n isPlistVersionConfigurationSynced(config, expoPlist)\n );\n}\n\nexport function isPlistVersionConfigurationSynced(\n config: Pick<ExpoConfigUpdates, 'sdkVersion' | 'runtimeVersion'>,\n expoPlist: ExpoPlist\n): boolean {\n const expectedRuntimeVersion = getRuntimeVersionNullable(config, 'ios');\n const expectedSdkVersion = getSDKVersion(config);\n\n const currentRuntimeVersion = expoPlist.EXUpdatesRuntimeVersion ?? null;\n const currentSdkVersion = expoPlist.EXUpdatesSDKVersion ?? null;\n\n if (expectedRuntimeVersion !== null) {\n return currentRuntimeVersion === expectedRuntimeVersion && currentSdkVersion === null;\n } else if (expectedSdkVersion !== null) {\n return currentSdkVersion === expectedSdkVersion && currentRuntimeVersion === null;\n } else {\n return true;\n }\n}\n"],"file":"Updates.js"}
|