|
1 |
| -/** |
2 |
| - * This cli config is needed for the coexistance of react-native and other |
3 |
| - * out-of-tree implementations such react-native-macos. |
4 |
| - * The following issue is tracked by |
5 |
| - * https://github.com/react-native-community/discussions-and-proposals/issues/182 |
6 |
| - * |
7 |
| - * The work-around involves having a metro.config.js for each out-of-tree |
8 |
| - * platform, i.e. metro.config.js for react-native and |
9 |
| - * metro.config.macos.js for react-native-macos. |
10 |
| - * This react-native.config.js looks for a --use-react-native-macos |
11 |
| - * switch and when present pushes --config=metro.config.macos.js |
12 |
| - * and specifies reactNativePath: 'node_modules/react-native-macos'. |
13 |
| - * The metro.config.js has to blacklist 'node_modules/react-native-macos', |
14 |
| - * and conversely metro.config.macos.js has to blacklist 'node_modules/react-native'. |
15 |
| - */ |
16 |
| -'use strict'; |
17 |
| - |
| 1 | +const fs = require('fs'); |
18 | 2 | const path = require('path');
|
19 | 3 |
|
20 |
| -const dependencies = { |
21 |
| - '@react-native-async-storage/async-storage': { |
22 |
| - root: __dirname, |
23 |
| - // rn-cli incorrectly resolves node_modules path for the following platforms |
24 |
| - platforms: { |
25 |
| - ios: null, |
26 |
| - macos: null, |
| 4 | +const windowsProjectFile = path.join( |
| 5 | + 'node_modules', |
| 6 | + '.generated', |
| 7 | + 'windows', |
| 8 | + 'ReactTestApp', |
| 9 | + 'ReactTestApp.vcxproj' |
| 10 | +); |
| 11 | + |
| 12 | +module.exports = { |
| 13 | + dependencies: { |
| 14 | + '@react-native-async-storage/async-storage': { |
| 15 | + root: __dirname, |
| 16 | + // rn-cli incorrectly resolves node_modules path for the following platforms |
| 17 | + platforms: { |
| 18 | + ios: null, |
| 19 | + macos: null, |
| 20 | + }, |
27 | 21 | },
|
28 |
| - }, |
29 |
| - // Suppress warnings about bob not being a proper native module |
30 |
| - '@react-native-community/bob': { |
31 |
| - platforms: { |
32 |
| - android: null, |
33 |
| - ios: null, |
34 |
| - macos: null, |
35 |
| - windows: null, |
| 22 | + // Suppress warnings about bob not being a proper native module |
| 23 | + '@react-native-community/bob': { |
| 24 | + platforms: { |
| 25 | + android: null, |
| 26 | + ios: null, |
| 27 | + macos: null, |
| 28 | + windows: null, |
| 29 | + }, |
36 | 30 | },
|
37 |
| - }, |
38 |
| - // We don't use Expo in our test apps |
39 |
| - expo: { |
40 |
| - platforms: { |
41 |
| - android: null, |
42 |
| - ios: null, |
43 |
| - macos: null, |
44 |
| - windows: null, |
| 31 | + // We don't use Expo in our test apps |
| 32 | + expo: { |
| 33 | + platforms: { |
| 34 | + android: null, |
| 35 | + ios: null, |
| 36 | + macos: null, |
| 37 | + windows: null, |
| 38 | + }, |
45 | 39 | },
|
46 | 40 | },
|
47 |
| -}; |
| 41 | + project: { |
| 42 | + android: { |
| 43 | + sourceDir: path.join('example', 'android'), |
| 44 | + manifestPath: path.relative( |
| 45 | + path.join(__dirname, 'example', 'android'), |
| 46 | + path.join( |
| 47 | + path.dirname(require.resolve('react-native-test-app/package.json')), |
| 48 | + 'android', |
| 49 | + 'app', |
| 50 | + 'src', |
| 51 | + 'main', |
| 52 | + 'AndroidManifest.xml', |
| 53 | + ), |
| 54 | + ), |
| 55 | + }, |
| 56 | + ios: { |
| 57 | + project: (() => { |
| 58 | + const { |
| 59 | + packageSatisfiesVersionRange, |
| 60 | + } = require('react-native-test-app/scripts/configure'); |
| 61 | + if ( |
| 62 | + packageSatisfiesVersionRange( |
| 63 | + '@react-native-community/cli-platform-ios', |
| 64 | + '<5.0.2', |
| 65 | + ) |
| 66 | + ) { |
| 67 | + // Prior to @react-native-community/cli-platform-ios v5.0.0, |
| 68 | + // `project` was only used to infer `sourceDir` and `podfile`. |
| 69 | + return 'example/ios/ReactTestApp-Dummy.xcodeproj'; |
| 70 | + } |
48 | 71 |
|
49 |
| -if ( |
50 |
| - process.argv.includes('--use-react-native-windows') || |
51 |
| - process.argv.includes('autolink-windows') || |
52 |
| - process.argv.includes('run-windows') |
53 |
| -) { |
54 |
| - const sourceDir = path.join('example', 'windows'); |
55 |
| - module.exports = { |
56 |
| - dependencies, |
57 |
| - project: { |
58 |
| - // `@react-native-community/cli` mistakes |
59 |
| - // `windows/ReactNativeAsyncStorage.sln` and |
60 |
| - // `windows/ReactNativeAsyncStorage/ReactNativeAsyncStorage.vcxproj` for |
61 |
| - // being the main project files. We need to help it find the solution file |
62 |
| - // under `example/windows/` and the generated project files in |
63 |
| - // `node_modules/.generated/windows`. |
64 |
| - windows: { |
65 |
| - sourceDir, |
66 |
| - solutionFile: 'AsyncStorageExample.sln', |
67 |
| - project: { |
68 |
| - projectFile: path.relative( |
69 |
| - sourceDir, |
70 |
| - path.join( |
71 |
| - 'node_modules', |
72 |
| - '.generated', |
73 |
| - 'windows', |
74 |
| - 'ReactTestApp', |
75 |
| - 'ReactTestApp.vcxproj' |
76 |
| - ) |
77 |
| - ), |
78 |
| - }, |
| 72 | + // `sourceDir` and `podfile` detection was fixed in |
| 73 | + // @react-native-community/cli-platform-ios v5.0.2 (see |
| 74 | + // https://github.com/react-native-community/cli/pull/1444). |
| 75 | + return 'node_modules/.generated/ios/ReactTestApp.xcodeproj'; |
| 76 | + })(), |
| 77 | + }, |
| 78 | + windows: fs.existsSync(windowsProjectFile) && { |
| 79 | + sourceDir: path.join('example', 'windows'), |
| 80 | + solutionFile: 'AsyncStorageExample.sln', |
| 81 | + project: { |
| 82 | + projectFile: path.relative( |
| 83 | + path.join(__dirname, 'example', 'windows'), |
| 84 | + windowsProjectFile, |
| 85 | + ), |
79 | 86 | },
|
80 | 87 | },
|
81 |
| - reactNativePath: path.join('node_modules', 'react-native-windows'), |
82 |
| - }; |
83 |
| -} else { |
84 |
| - module.exports = { dependencies }; |
85 |
| -} |
| 88 | + }, |
| 89 | +}; |
0 commit comments