diff --git a/packages/cli/src/commands/init/__fixtures__/editTemplate/node_modules/PlaceholderName b/packages/cli/src/commands/init/__fixtures__/editTemplate/node_modules/PlaceholderName new file mode 100644 index 000000000..e69de29bb diff --git a/packages/cli/src/tools/config/__tests__/index-test.js b/packages/cli/src/tools/config/__tests__/index-test.js index d4a11b453..a3d75b472 100644 --- a/packages/cli/src/tools/config/__tests__/index-test.js +++ b/packages/cli/src/tools/config/__tests__/index-test.js @@ -23,16 +23,15 @@ const removeString = (config, str) => beforeEach(() => { cleanup(DIR); jest.resetModules(); + jest.clearAllMocks(); }); afterEach(() => cleanup(DIR)); test('should have a valid structure by default', () => { writeFiles(DIR, { - 'package.json': `{ - "react-native": { - "reactNativePath": "." - } + 'react-native.config.js': `module.exports = { + reactNativePath: "." }`, }); const config = loadConfig(DIR); @@ -59,14 +58,13 @@ test('should return dependencies from package.json', () => { test('should read a config of a dependency and use it to load other settings', () => { writeFiles(DIR, { 'node_modules/react-native/package.json': '{}', + 'node_modules/react-native-test/package.json': '{}', 'node_modules/react-native-test/ReactNativeTest.podspec': '', - 'node_modules/react-native-test/package.json': `{ - "react-native": { - "dependency": { - "platforms": { - "ios": { - "project": "./customLocation/customProject.xcodeproj" - } + 'node_modules/react-native-test/react-native.config.js': `module.exports = { + dependency: { + platforms: { + ios: { + project: "./customLocation/customProject.xcodeproj" } } } @@ -87,11 +85,10 @@ test('should read a config of a dependency and use it to load other settings', ( test('should merge project configuration with default values', () => { writeFiles(DIR, { 'node_modules/react-native/package.json': '{}', - 'node_modules/react-native-test/package.json': `{ - "react-native": { - "dependency": { - "assets": ["foo", "baz"] - } + 'node_modules/react-native-test/package.json': '{}', + 'node_modules/react-native-test/react-native.config.js': `module.exports = { + dependency: { + assets: ["foo", "baz"] } }`, 'node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj': @@ -100,18 +97,18 @@ test('should merge project configuration with default values', () => { "dependencies": { "react-native": "0.0.1", "react-native-test": "0.0.1" - }, - "react-native": { - "reactNativePath": ".", - "dependencies": { - "react-native-test": { - "platforms": { - "ios": { - "sourceDir": "./abc" - } - }, - "assets": ["foo"] - } + } + }`, + 'react-native.config.js': `module.exports = { + reactNativePath: ".", + dependencies: { + "react-native-test": { + platforms: { + ios: { + sourceDir: "./abc" + } + }, + assets: ["foo"] } } }`, @@ -266,3 +263,22 @@ test('should skip packages that have invalid configuration', () => { expect(dependencies).toMatchSnapshot('dependencies config'); expect(spy.mock.calls[0][0]).toMatchSnapshot('logged warning'); }); + +test('does not use restricted "react-native" key to resolve config from package.json', () => { + jest.resetModules(); + + writeFiles(DIR, { + 'node_modules/react-native-netinfo/package.json': `{ + "react-native": "src/index.js" + }`, + 'package.json': `{ + "dependencies": { + "react-native-netinfo": "0.0.1" + } + }`, + }); + const spy = jest.spyOn(logger, 'warn'); + const {dependencies} = loadConfig(DIR); + expect(dependencies).toHaveProperty('react-native-netinfo'); + expect(spy).not.toHaveBeenCalled(); +}); diff --git a/packages/cli/src/tools/config/readConfigFromDisk.js b/packages/cli/src/tools/config/readConfigFromDisk.js index ebf7cade2..130b37a04 100644 --- a/packages/cli/src/tools/config/readConfigFromDisk.js +++ b/packages/cli/src/tools/config/readConfigFromDisk.js @@ -23,7 +23,7 @@ import {logger} from '@react-native-community/cli-tools'; /** * Places to look for the new configuration */ -const searchPlaces = ['react-native.config.js', 'package.json']; +const searchPlaces = ['react-native.config.js']; /** * Reads a project configuration as defined by the user in the current