Skip to content

Commit 3152bc2

Browse files
committed
throw when overriding platform-specific base values
1 parent 3a4f205 commit 3152bc2

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

.claude/settings.local.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/eas-json/src/__tests__/buildProfiles-test.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { EasJson } from '../types';
1010

1111
jest.mock('fs');
1212

13+
type DeepPartial<T> = T extends object
14+
? {
15+
[P in keyof T]?: DeepPartial<T[P]>;
16+
}
17+
: T;
18+
1319
beforeEach(async () => {
1420
vol.reset();
1521
await fs.mkdirp('/project');
@@ -936,13 +942,39 @@ test('invalid build profile with caching with both paths and customPaths - error
936942
}).rejects.toThrow(expectedError);
937943
});
938944

939-
describe('extensions can disable cache which is present in base', () => {
940-
type DeepPartial<T> = T extends object
941-
? {
942-
[P in keyof T]?: DeepPartial<T[P]>;
943-
}
944-
: T;
945+
it.each([
946+
{
947+
testName: 'platform-specific setting from base can _not_ be overridden',
948+
baseConfig: {
949+
ios: {
950+
prebuildCommand: 'ios prebuild',
951+
},
952+
android: {
953+
prebuildCommand: 'android prebuild',
954+
},
955+
},
956+
},
957+
])('$testName', async ({ baseConfig }) => {
958+
await fs.writeJson('/project/eas.json', {
959+
build: {
960+
base: baseConfig,
961+
extension1: {
962+
extends: 'base',
963+
prebuildCommand: 'new great prebuild',
964+
},
965+
},
966+
} satisfies DeepPartial<EasJson>);
945967

968+
const accessor = EasJsonAccessor.fromProjectPath('/project');
969+
970+
await expect(() =>
971+
EasJsonUtils.getBuildProfileAsync(accessor, Platform.ANDROID, 'extension1')
972+
).rejects.toThrow(
973+
'Cannot override platform-specific base value "android prebuild" by value "new great prebuild" for key "prebuildCommand". Move the entry out of the "android" object, into the common properties, if you want to override it.'
974+
);
975+
});
976+
977+
describe('extensions can disable cache which is present in base', () => {
946978
it.each([
947979
{
948980
testName: 'platform-specific setting can be disabled',

packages/eas-json/src/build/resolver.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ function mergeProfiles(
9696
} as CommonBuildProfile['cache'];
9797
}
9898

99+
for (const [key, newValue] of Object.entries(update ?? [])) {
100+
for (const platform of ['android', 'ios']) {
101+
// @ts-expect-error indexing issues
102+
const existingValue = base?.[platform]?.[key];
103+
if (existingValue !== undefined) {
104+
throw new Error(
105+
`Cannot override platform-specific base value ${JSON.stringify(
106+
existingValue
107+
)} by value ${JSON.stringify(
108+
newValue
109+
)} for key "${key}". Move the entry out of the "${platform}" object, into the common properties, if you want to override it.`
110+
);
111+
}
112+
}
113+
}
114+
99115
if (base.android && update.android) {
100116
result.android = mergeProfiles(
101117
base.android as EasJsonBuildProfileResolved,

0 commit comments

Comments
 (0)