diff --git a/.vscode/settings.json b/.vscode/settings.json index dff35f935..54243280d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,7 +8,7 @@ "**/build": true }, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "flow.useNPMPackagedFlow": true, "javascript.validate.enable": false, diff --git a/packages/cli-config/src/__tests__/index-test.ts b/packages/cli-config/src/__tests__/index-test.ts index c11f6e877..3740e8d1c 100644 --- a/packages/cli-config/src/__tests__/index-test.ts +++ b/packages/cli-config/src/__tests__/index-test.ts @@ -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, }, @@ -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( @@ -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, { diff --git a/packages/cli-config/src/loadConfig.ts b/packages/cli-config/src/loadConfig.ts index 9ebc71ee6..b01c2d03b 100644 --- a/packages/cli-config/src/loadConfig.ts +++ b/packages/cli-config/src/loadConfig.ts @@ -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; @@ -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;