Skip to content

Commit 57f877f

Browse files
committed
refactor: cleanup
1 parent 543bb5e commit 57f877f

5 files changed

Lines changed: 343 additions & 182 deletions

File tree

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

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ import * as path from 'node:path';
55
import type { ResolvedBrownfieldPluginConfigWithAndroid } from '../../types';
66
import {
77
createAndroidModule,
8-
syncAndroidModuleManifest,
9-
syncAndroidModuleStringResources,
8+
syncAndroidModuleExpoUpdatesFromAppFiles,
109
} from '../withAndroidModuleFiles';
11-
import {
12-
extractExpoUpdatesApplicationMetaDataFromAndroidManifest,
13-
extractExpoUpdatesStringResourcesFromResourcesXml,
14-
} from '../utils/androidManifest';
1510

1611
describe('createAndroidModule', () => {
1712
const tempDirectories: string[] = [];
@@ -100,7 +95,7 @@ describe('createAndroidModule', () => {
10095
`);
10196
});
10297

103-
it('overwrites existing library metadata with the final Expo manifest values', () => {
98+
it('overwrites existing library Expo Updates files with the finalized app file values', () => {
10499
const androidDir = createAndroidDir();
105100
const config = createConfig();
106101

@@ -110,9 +105,17 @@ describe('createAndroidModule', () => {
110105
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
111106
<application android:name=".MainApplication">
112107
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="NEVER" />
108+
<meta-data android:name="expo.modules.updates.EXPO_RUNTIME_VERSION" android:value="@string/expo_runtime_version" />
113109
</application>
114110
</manifest>`
115111
);
112+
writeAppStrings(
113+
androidDir,
114+
`<?xml version="1.0" encoding="utf-8"?>
115+
<resources>
116+
<string name="expo_runtime_version">1.0.0</string>
117+
</resources>`
118+
);
116119

117120
createAndroidModule({
118121
androidDir,
@@ -121,51 +124,38 @@ describe('createAndroidModule', () => {
121124
isExpoPre55: false,
122125
});
123126

124-
const finalExpoMetaData =
125-
extractExpoUpdatesApplicationMetaDataFromAndroidManifest({
126-
manifest: {
127-
$: {
128-
'xmlns:android': 'http://schemas.android.com/apk/res/android',
129-
},
130-
queries: [],
131-
application: [
132-
{
133-
$: {
134-
'android:name': '.MainApplication',
135-
},
136-
'meta-data': [
137-
{
138-
$: {
139-
'android:name':
140-
'expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH',
141-
'android:value': 'ALWAYS',
142-
},
143-
},
144-
],
145-
},
146-
],
147-
},
148-
});
149-
150-
syncAndroidModuleManifest({
127+
writeAppManifest(
151128
androidDir,
152-
config,
153-
expoUpdatesMetaData: finalExpoMetaData,
154-
});
129+
`<?xml version="1.0" encoding="utf-8"?>
130+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
131+
<application android:name=".MainApplication">
132+
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS" />
133+
<meta-data android:name="expo.modules.updates.EXPO_RUNTIME_VERSION" android:value="@string/expo_runtime_version" />
134+
</application>
135+
</manifest>`
136+
);
137+
writeAppStrings(
138+
androidDir,
139+
`<?xml version="1.0" encoding="utf-8"?>
140+
<resources>
141+
<string name="expo_runtime_version">2.0.0</string>
142+
</resources>`
143+
);
155144

156-
syncAndroidModuleStringResources({
145+
syncAndroidModuleExpoUpdatesFromAppFiles({
157146
androidDir,
158147
config,
159-
expoUpdatesStringResources:
160-
extractExpoUpdatesStringResourcesFromResourcesXml(
161-
{ resources: {} },
162-
finalExpoMetaData
163-
),
164148
});
165149

166150
expect(readLibraryManifest(androidDir)).toContain(
167151
'android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"'
168152
);
153+
expect(readLibraryManifest(androidDir)).not.toContain(
154+
'android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="NEVER"'
155+
);
156+
expect(readLibraryStrings(androidDir)).toContain(
157+
'<string name="expo_runtime_version">2.0.0</string>'
158+
);
169159
});
170160

171161
function createAndroidDir(): string {

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

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

55
import {
6-
extractExpoUpdatesApplicationMetaData,
7-
readExpoUpdatesApplicationMetaData,
8-
readExpoUpdatesStringResources,
6+
extractApplicationMetaDataFromAndroidManifest,
7+
extractStringResourcesFromResourcesXml,
98
renderLibraryManifestApplication,
109
renderLibraryStringResources,
1110
} from '../androidManifest';
11+
import {
12+
extractExpoUpdatesApplicationMetaData,
13+
readExpoUpdatesApplicationMetaData,
14+
readExpoUpdatesStringResources,
15+
} from '../expo-updates';
1216

1317
describe('android manifest helpers', () => {
1418
const tempDirectories: string[] = [];
@@ -124,6 +128,142 @@ describe('android manifest helpers', () => {
124128
);
125129
});
126130

131+
it('keeps typed extraction aligned for android:value entries and referenced string resources', () => {
132+
const androidDir = createAndroidDir();
133+
const manifestContent = `<?xml version="1.0" encoding="utf-8"?>
134+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
135+
<application android:name=".MainApplication">
136+
<meta-data android:name="expo.modules.updates.ENABLED" android:value="true" />
137+
<meta-data android:name="expo.modules.updates.EXPO_RUNTIME_VERSION" android:value="@string/expo_runtime_version" />
138+
<meta-data android:name="com.example.NOT_UPDATES" android:value="ignored" />
139+
</application>
140+
</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"?>
180+
<resources>
181+
<string name="expo_runtime_version">1.0.0-preview</string>
182+
</resources>`
183+
);
184+
185+
const fileMetaData = extractExpoUpdatesApplicationMetaData(manifestContent);
186+
const typedMetaData = extractApplicationMetaDataFromAndroidManifest(
187+
typedManifest
188+
).filter(({ name }) => name.startsWith('expo.modules.updates.'));
189+
190+
expect(typedMetaData).toEqual(fileMetaData);
191+
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+
)
205+
).toEqual(readExpoUpdatesStringResources(androidDir, fileMetaData));
206+
});
207+
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([
240+
{
241+
name: 'expo.modules.updates.EXPO_RUNTIME_VERSION',
242+
value: '@string/expo_runtime_version',
243+
},
244+
]);
245+
expect(
246+
extractStringResourcesFromResourcesXml(
247+
{
248+
resources: {
249+
string: [
250+
{
251+
$: { name: 'expo_runtime_version' },
252+
_: '2.0.0',
253+
},
254+
],
255+
},
256+
},
257+
['expo_runtime_version']
258+
)
259+
).toEqual([
260+
{
261+
name: 'expo_runtime_version',
262+
value: '2.0.0',
263+
},
264+
]);
265+
});
266+
127267
function createAndroidDir(): string {
128268
const tempDirectory = fs.mkdtempSync(
129269
path.join(os.tmpdir(), 'react-native-brownfield-android-')

0 commit comments

Comments
 (0)