Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. vscode was also changing this property for me 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it then and not fight 😅

},
"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
Loading