From f7999efaf312532de068889acb428e43ac36e292 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Wed, 10 Apr 2019 15:24:57 +0200 Subject: [PATCH] Dont apply config automaitcaly --- .../__snapshots__/index-test.js.snap | 9 +++++++++ .../src/tools/config/__tests__/index-test.js | 19 +++++++++++++++++++ packages/cli/src/tools/config/index.js | 14 +++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap b/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap index 7479bcbbe..d695d85b0 100644 --- a/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap +++ b/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap @@ -83,6 +83,15 @@ Object { } `; +exports[`should not add default React Native config when one present 1`] = ` +Array [ + Object { + "func": [Function], + "name": "test", + }, +] +`; + exports[`should read \`rnpm\` config from a dependency and transform it to a new format 1`] = ` Object { "assets": Array [], diff --git a/packages/cli/src/tools/config/__tests__/index-test.js b/packages/cli/src/tools/config/__tests__/index-test.js index 5ea4965f2..cba33e1a2 100644 --- a/packages/cli/src/tools/config/__tests__/index-test.js +++ b/packages/cli/src/tools/config/__tests__/index-test.js @@ -217,3 +217,22 @@ test('should automatically put "react-native" into haste config', () => { const {haste} = loadConfig(DIR); expect(haste).toMatchSnapshot(); }); + +test('should not add default React Native config when one present', () => { + writeFiles(DIR, { + 'node_modules/react-native/package.json': '{}', + 'node_modules/react-native/react-native.config.js': `module.exports = { + commands: [{ + name: 'test', + func: () => {}, + }] + }`, + 'package.json': `{ + "dependencies": { + "react-native": "0.0.1" + } + }`, + }); + const {commands} = loadConfig(DIR); + expect(commands).toMatchSnapshot(); +}); diff --git a/packages/cli/src/tools/config/index.js b/packages/cli/src/tools/config/index.js index 6f9bb880b..d1e31efde 100644 --- a/packages/cli/src/tools/config/index.js +++ b/packages/cli/src/tools/config/index.js @@ -38,10 +38,18 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT { readLegacyDependencyConfigFromDisk(root) || readDependencyConfigFromDisk(root); - // @todo: Move this to React Native in the future + /** + * This workaround is neccessary for development only before + * first 0.60.0-rc.0 gets released and we can switch to it + * while testing. + */ if (dependencyName === 'react-native') { - config.platforms = {ios, android}; - config.commands = [...ios.commands, ...android.commands]; + if (Object.keys(config.platforms).length === 0) { + config.platforms = {ios, android}; + } + if (config.commands.length === 0) { + config.commands = [...ios.commands, ...android.commands]; + } } const isPlatform = Object.keys(config.platforms).length > 0;