Skip to content

Commit 8bd2cc5

Browse files
committed
refactor: cleanup
1 parent b0ff65e commit 8bd2cc5

2 files changed

Lines changed: 33 additions & 156 deletions

File tree

packages/react-native-brownfield/src/expo-config-plugin/android/utils/__tests__/androidManifest.test.ts

Lines changed: 33 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as os from 'node:os';
33
import * as path from 'node:path';
44

55
import {
6-
extractApplicationMetaDataFromAndroidManifest,
7-
extractStringResourcesFromResourcesXml,
6+
extractApplicationMetaData,
7+
extractStringResourcesFromXml,
88
renderLibraryManifestApplication,
99
renderLibraryStringResources,
1010
} from '../androidManifest';
@@ -128,7 +128,7 @@ describe('android manifest helpers', () => {
128128
);
129129
});
130130

131-
it('keeps typed extraction aligned for android:value entries and referenced string resources', () => {
131+
it('keeps raw XML extraction aligned for android:value entries and referenced string resources', () => {
132132
const androidDir = createAndroidDir();
133133
const manifestContent = `<?xml version="1.0" encoding="utf-8"?>
134134
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
@@ -138,122 +138,49 @@ describe('android manifest helpers', () => {
138138
<meta-data android:name="com.example.NOT_UPDATES" android:value="ignored" />
139139
</application>
140140
</manifest>`;
141-
const typedManifest = {
142-
manifest: {
143-
$: {
144-
'xmlns:android': 'http://schemas.android.com/apk/res/android',
145-
},
146-
queries: [],
147-
application: [
148-
{
149-
$: {
150-
'android:name': '.MainApplication',
151-
},
152-
'meta-data': [
153-
{
154-
$: {
155-
'android:name': 'expo.modules.updates.ENABLED',
156-
'android:value': 'true',
157-
},
158-
},
159-
{
160-
$: {
161-
'android:name': 'expo.modules.updates.EXPO_RUNTIME_VERSION',
162-
'android:value': '@string/expo_runtime_version',
163-
},
164-
},
165-
{
166-
$: {
167-
'android:name': 'com.example.NOT_UPDATES',
168-
'android:value': 'ignored',
169-
},
170-
},
171-
],
172-
},
173-
],
174-
},
175-
};
176-
177-
writeAppStrings(
178-
androidDir,
179-
`<?xml version="1.0" encoding="utf-8"?>
141+
const stringsContent = `<?xml version="1.0" encoding="utf-8"?>
180142
<resources>
181143
<string name="expo_runtime_version">1.0.0-preview</string>
182-
</resources>`
183-
);
144+
</resources>`;
145+
146+
writeAppManifest(androidDir, manifestContent);
147+
writeAppStrings(androidDir, stringsContent);
184148

185149
const fileMetaData = extractExpoUpdatesApplicationMetaData(manifestContent);
186-
const typedMetaData = extractApplicationMetaDataFromAndroidManifest(
187-
typedManifest
188-
).filter(({ name }) => name.startsWith('expo.modules.updates.'));
150+
const rawMetaData = extractApplicationMetaData(manifestContent).filter(
151+
({ name }) => name.startsWith('expo.modules.updates.')
152+
);
189153

190-
expect(typedMetaData).toEqual(fileMetaData);
154+
expect(rawMetaData).toEqual(fileMetaData);
191155
expect(
192-
extractStringResourcesFromResourcesXml(
193-
{
194-
resources: {
195-
string: [
196-
{
197-
$: { name: 'expo_runtime_version' },
198-
_: '1.0.0-preview',
199-
},
200-
],
201-
},
202-
},
203-
['expo_runtime_version']
204-
)
156+
extractStringResourcesFromXml(stringsContent, ['expo_runtime_version'])
205157
).toEqual(readExpoUpdatesStringResources(androidDir, 'app', fileMetaData));
206158
});
207159

208-
it('supports android:resource entries in the typed manifest adapter', () => {
209-
const metaDataEntries = extractApplicationMetaDataFromAndroidManifest({
210-
manifest: {
211-
$: {
212-
'xmlns:android': 'http://schemas.android.com/apk/res/android',
213-
},
214-
queries: [],
215-
application: [
216-
{
217-
$: {
218-
'android:name': '.MainApplication',
219-
},
220-
'meta-data': [
221-
{
222-
$: {
223-
'android:name': 'expo.modules.updates.EXPO_RUNTIME_VERSION',
224-
'android:resource': '@string/expo_runtime_version',
225-
},
226-
},
227-
{
228-
$: {
229-
'android:name': 'com.example.NOT_UPDATES',
230-
'android:resource': '@string/ignored',
231-
},
232-
},
233-
],
234-
},
235-
],
236-
},
237-
}).filter(({ name }) => name.startsWith('expo.modules.updates.'));
238-
239-
expect(metaDataEntries).toEqual([
160+
it('ignores android:resource entries because only android:value metadata is supported', () => {
161+
expect(
162+
extractApplicationMetaData(`<?xml version="1.0" encoding="utf-8"?>
163+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
164+
<application android:name=".MainApplication">
165+
<meta-data
166+
android:name="expo.modules.updates.EXPO_RUNTIME_VERSION"
167+
android:resource="@string/expo_runtime_version" />
168+
<meta-data android:name="expo.modules.updates.ENABLED" android:value="true" />
169+
</application>
170+
</manifest>`)
171+
).toEqual([
240172
{
241-
name: 'expo.modules.updates.EXPO_RUNTIME_VERSION',
242-
value: '@string/expo_runtime_version',
173+
name: 'expo.modules.updates.ENABLED',
174+
value: 'true',
243175
},
244176
]);
177+
245178
expect(
246-
extractStringResourcesFromResourcesXml(
247-
{
248-
resources: {
249-
string: [
250-
{
251-
$: { name: 'expo_runtime_version' },
252-
_: '2.0.0',
253-
},
254-
],
255-
},
256-
},
179+
extractStringResourcesFromXml(
180+
`<?xml version="1.0" encoding="utf-8"?>
181+
<resources>
182+
<string name="expo_runtime_version">2.0.0</string>
183+
</resources>`,
257184
['expo_runtime_version']
258185
)
259186
).toEqual([

packages/react-native-brownfield/src/expo-config-plugin/android/utils/androidManifest.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { AndroidConfig } from '@expo/config-plugins';
2-
31
export type AndroidManifestMetaDataEntry = {
42
name: string;
53
value: string;
@@ -32,28 +30,6 @@ export function extractApplicationMetaData(
3230
);
3331
}
3432

35-
export function extractApplicationMetaDataFromAndroidManifest(
36-
androidManifest: AndroidConfig.Manifest.AndroidManifest
37-
): AndroidManifestMetaDataEntry[] {
38-
const application = androidManifest.manifest.application?.[0];
39-
40-
if (!application?.['meta-data']) {
41-
return [];
42-
}
43-
44-
return application['meta-data']
45-
.map((metaDataItem) =>
46-
parseMetaDataAttributes(
47-
metaDataItem.$['android:name'],
48-
metaDataItem.$['android:value'] ?? metaDataItem.$['android:resource']
49-
)
50-
)
51-
.filter(
52-
(metaDataEntry): metaDataEntry is AndroidManifestMetaDataEntry =>
53-
metaDataEntry !== null
54-
);
55-
}
56-
5733
export function extractStringResourcesFromXml(
5834
stringsContent: string,
5935
resourceNames: string[]
@@ -70,32 +46,6 @@ export function extractStringResourcesFromXml(
7046
);
7147
}
7248

73-
export function extractStringResourcesFromResourcesXml(
74-
stringsXml: AndroidConfig.Resources.ResourceXML,
75-
resourceNames: string[]
76-
): AndroidStringResourceEntry[] {
77-
if (resourceNames.length === 0) {
78-
return [];
79-
}
80-
81-
return resourceNames
82-
.map((name) => {
83-
const stringItem = stringsXml.resources.string?.find(
84-
(item) => item.$.name === name
85-
);
86-
87-
if (!stringItem || stringItem._ === undefined) {
88-
return null;
89-
}
90-
91-
return { name, value: stringItem._ };
92-
})
93-
.filter(
94-
(stringResource): stringResource is AndroidStringResourceEntry =>
95-
stringResource !== null
96-
);
97-
}
98-
9949
export function renderLibraryManifestApplication(
10050
metaDataEntries: AndroidManifestMetaDataEntry[]
10151
): string {

0 commit comments

Comments
 (0)