Skip to content

Commit

Permalink
fix: config with --platform flag to work with platforms defined in mu…
Browse files Browse the repository at this point in the history
…ltiple packages (#2562)
  • Loading branch information
thymikee authored Dec 12, 2024
1 parent 5075c8f commit fb78816
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"**/build": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"flow.useNPMPackagedFlow": true,
"javascript.validate.enable": false,
Expand Down
81 changes: 79 additions & 2 deletions packages/cli-config/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ const REACT_NATIVE_MOCK = {
module.exports = {
platforms: {
ios: {
linkConfig: ios.linkConfig,
projectConfig: ios.projectConfig,
dependencyConfig: ios.dependencyConfig,
},
android: {
linkConfig: android.linkConfig,
projectConfig: android.projectConfig,
dependencyConfig: android.dependencyConfig,
},
Expand All @@ -38,6 +36,21 @@ const REACT_NATIVE_MOCK = {
`,
};

const PLATFORM_MOCK = {
'node_modules/react-native-os/package.json': '{}',
'node_modules/react-native-os/react-native.config.js': `
const os = require("${iosPath}");
module.exports = {
platforms: {
os: {
projectConfig: os.projectConfig,
dependencyConfig: os.dependencyConfig,
},
},
};
`,
};

// Removes string from all key/values within an object
const removeString = (config, str) =>
JSON.parse(
Expand Down Expand Up @@ -373,6 +386,70 @@ test('should apply build types from dependency config', async () => {
).toMatchSnapshot();
});

test('should be able to read multiple platforms from many packages', async () => {
DIR = getTempDirectory('config_test_apply_dependency_config');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
...PLATFORM_MOCK,
'package.json': `{
"dependencies": {
"react-native": "0.0.1",
"react-native-os": "0.0.1"
}
}`,
});
const {platforms} = await loadConfigAsync({projectRoot: DIR});
expect(removeString(platforms, DIR)).toMatchInlineSnapshot(`
Object {
"android": Object {},
"ios": Object {},
"os": Object {},
}
`);
});

test('should be able to read only selected platform', async () => {
DIR = getTempDirectory('config_test_apply_dependency_config');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
...PLATFORM_MOCK,
'package.json': `{
"dependencies": {
"react-native": "0.0.1",
"react-native-os": "0.0.1"
}
}`,
});
const {platforms} = await loadConfigAsync({
projectRoot: DIR,
selectedPlatform: 'os',
});
expect(removeString(platforms, DIR)).toMatchInlineSnapshot(`
Object {
"os": Object {},
}
`);
});

test('should be able to read no platforms when non-existent selected', async () => {
DIR = getTempDirectory('config_test_apply_dependency_config');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
...PLATFORM_MOCK,
'package.json': `{
"dependencies": {
"react-native": "0.0.1",
"react-native-os": "0.0.1"
}
}`,
});
const {platforms} = await loadConfigAsync({
projectRoot: DIR,
selectedPlatform: 'macos',
});
expect(removeString(platforms, DIR)).toMatchInlineSnapshot(`Object {}`);
});

test('supports dependencies from user configuration with custom build type', async () => {
DIR = getTempDirectory('config_test_apply_custom_build_config');
writeFiles(DIR, {
Expand Down
8 changes: 6 additions & 2 deletions packages/cli-config/src/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export default function loadConfig({
...acc.platforms,
...(selectedPlatform && config.platforms[selectedPlatform]
? {[selectedPlatform]: config.platforms[selectedPlatform]}
: config.platforms),
: !selectedPlatform
? config.platforms
: undefined),
},
healthChecks: [...acc.healthChecks, ...config.healthChecks],
}) as Config;
Expand Down Expand Up @@ -267,7 +269,9 @@ export async function loadConfigAsync({
...acc.platforms,
...(selectedPlatform && config.platforms[selectedPlatform]
? {[selectedPlatform]: config.platforms[selectedPlatform]}
: config.platforms),
: !selectedPlatform
? config.platforms
: undefined),
},
healthChecks: [...acc.healthChecks, ...config.healthChecks],
}) as Config;
Expand Down

0 comments on commit fb78816

Please sign in to comment.