Skip to content

Commit

Permalink
fix: plugin remove obsolete gradle.properties (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian authored Jan 21, 2025
1 parent 3a9a44d commit 31bf300
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
50 changes: 28 additions & 22 deletions src/__tests__/plugin/android/mergeGradleProperties.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
});
10 changes: 7 additions & 3 deletions src/plugin/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type PropertyItem = {
value: string;
};

export const GRADLE_PROPERTIES_PREFIX = "org.maplibre.reactnative.";

export const getGradleProperties = (
props: MapLibrePluginProps,
): PropertyItem[] => {
Expand All @@ -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(),
});
}
Expand All @@ -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);
Expand Down

0 comments on commit 31bf300

Please sign in to comment.