diff --git a/src/__tests__/plugin/android/mergeGradleProperties.test.ts b/src/__tests__/plugin/android/mergeGradleProperties.test.ts index b81cbd0e..f576816b 100644 --- a/src/__tests__/plugin/android/mergeGradleProperties.test.ts +++ b/src/__tests__/plugin/android/mergeGradleProperties.test.ts @@ -1,37 +1,43 @@ -import { mergeGradleProperties } from "../../../plugin/android"; +import { + GRADLE_PROPERTIES_PREFIX, + mergeGradleProperties, +} from "../../../plugin/android"; -const PROPERTY = { +const OTHER_PROPERTY = { type: "property", - key: "exampleProperty", - value: "value", + key: `some.other.exampleProperty`, + value: "example", +} as const; + +const OLD_PROPERTY = { + type: "property", + key: `${GRADLE_PROPERTIES_PREFIX}exampleProperty`, + value: "old", } as const; const NEW_PROPERTY = { type: "property", - key: "newProperty", + key: `${GRADLE_PROPERTIES_PREFIX}exampleProperty`, value: "new", } as const; describe("Expo Plugin Android – mergeGradleProperties", () => { - it("replaces duplicate property", () => { - expect( - mergeGradleProperties( - [ - PROPERTY, - { - ...NEW_PROPERTY, - value: "old", - }, - ], - [NEW_PROPERTY], - ), - ).toEqual([PROPERTY, NEW_PROPERTY]); - }); - it("adds new property", () => { - expect(mergeGradleProperties([PROPERTY], [NEW_PROPERTY])).toEqual([ - PROPERTY, + expect(mergeGradleProperties([OTHER_PROPERTY], [NEW_PROPERTY])).toEqual([ + OTHER_PROPERTY, NEW_PROPERTY, ]); }); + + it("removes obsolete property", () => { + expect(mergeGradleProperties([OTHER_PROPERTY, OLD_PROPERTY], [])).toEqual([ + OTHER_PROPERTY, + ]); + }); + + it("replaces property", () => { + expect( + mergeGradleProperties([OTHER_PROPERTY, OLD_PROPERTY], [NEW_PROPERTY]), + ).toEqual([OTHER_PROPERTY, NEW_PROPERTY]); + }); }); diff --git a/src/plugin/android.ts b/src/plugin/android.ts index 5e858b91..bcdef4af 100644 --- a/src/plugin/android.ts +++ b/src/plugin/android.ts @@ -12,6 +12,8 @@ type PropertyItem = { value: string; }; +export const GRADLE_PROPERTIES_PREFIX = "org.maplibre.reactnative."; + export const getGradleProperties = ( props: MapLibrePluginProps, ): PropertyItem[] => { @@ -20,7 +22,7 @@ export const getGradleProperties = ( if (key && value) { properties.push({ type: "property", - key: `org.maplibre.reactnative.${key}`, + key: `${GRADLE_PROPERTIES_PREFIX}${key}`, value: value.toString(), }); } @@ -35,10 +37,12 @@ export const mergeGradleProperties = ( oldProperties: PropertiesItem[], newProperties: PropertyItem[], ): PropertiesItem[] => { - const newPropertiesKeys = newProperties.map(({ key }) => key); const merged = oldProperties.filter( (item) => - !(item.type === "property" && newPropertiesKeys.includes(item.key)), + !( + item.type === "property" && + item.key.startsWith(GRADLE_PROPERTIES_PREFIX) + ), ); merged.push(...newProperties);