|
1 | | -const { getDefaultConfig } = require('@react-native/metro-config'); |
2 | | -const { exclusionList, resolveUniqueModule } = require('@rnx-kit/metro-config'); |
| 1 | +const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); |
3 | 2 |
|
4 | 3 | /** |
5 | 4 | * Metro configuration |
6 | 5 | * https://reactnative.dev/docs/metro |
7 | 6 | * |
8 | 7 | * @type {import('@react-native/metro-config').MetroConfig} |
9 | 8 | */ |
10 | | -const config = getDefaultConfig(__dirname); |
| 9 | +const config = {}; |
11 | 10 |
|
12 | | -const PATH = require('path'); |
13 | | -const packageDirPath = PATH.resolve(__dirname, '../../package'); |
14 | | -const nativePackageDirPath = PATH.resolve(__dirname, '../../package/native-package'); |
15 | | - |
16 | | -const symlinked = { |
17 | | - 'stream-chat-react-native': nativePackageDirPath, |
18 | | - 'stream-chat-react-native-core': packageDirPath, |
19 | | -}; |
20 | | - |
21 | | -// find what all modules need to be unique for the app (mainly react and react-native) |
22 | | -// note: we filter the symlinked modules as they are already unique |
23 | | -// and as they dont follow the workspace pattern the auto-generated path to the module is incorrect |
24 | | -const dependencyPackageNames = Object.keys(require('./package.json').dependencies); |
25 | | - |
26 | | -const uniqueModules = dependencyPackageNames.map((packageName) => { |
27 | | - if (symlinked[packageName]) { |
28 | | - const modulePath = symlinked[packageName]; |
29 | | - const escapedPackageName = PATH.normalize(packageName).replace(/\\/g, '\\\\'); |
30 | | - |
31 | | - // exclude the symlinked package from being resolved from node_modules |
32 | | - // example: .*\/node_modules\/stream-chat-react-native-core\/.* |
33 | | - // the above would avoid native-package to resolve core from its own node_modules |
34 | | - const exclusionRE = new RegExp( |
35 | | - `.*${PATH.sep}node_modules\\${PATH.sep}${escapedPackageName}\\${PATH.sep}.*`, |
36 | | - ); |
37 | | - |
38 | | - return { |
39 | | - packageName, // name of the package |
40 | | - modulePath, |
41 | | - blockPattern: exclusionRE, // paths that match this pattern will be blocked from being resolved |
42 | | - }; |
43 | | - } |
44 | | - const [modulePath, blockPattern] = resolveUniqueModule(packageName, __dirname); |
45 | | - return { |
46 | | - packageName, // name of the package |
47 | | - modulePath, // actual path to the module in the project's node modules |
48 | | - blockPattern, // paths that match this pattern will be blocked from being resolved |
49 | | - }; |
50 | | -}); |
51 | | - |
52 | | -// block the other paths for unique modules from being resolved |
53 | | -const blockList = uniqueModules.map(({ blockPattern }) => blockPattern); |
54 | | - |
55 | | -// provide the path for the unique modules |
56 | | -const extraNodeModules = uniqueModules.reduce((acc, item) => { |
57 | | - acc[item.packageName] = item.modulePath; |
58 | | - return acc; |
59 | | -}, {}); |
60 | | - |
61 | | -config.resolver.blockList = exclusionList(blockList); |
62 | | -config.resolver.extraNodeModules = extraNodeModules; |
63 | | - |
64 | | -config.resolver.nodeModulesPaths = [PATH.resolve(__dirname, 'node_modules')]; |
65 | | - |
66 | | -// add the package dir for metro to access the package folder |
67 | | -config.watchFolders = [packageDirPath]; |
68 | | - |
69 | | -module.exports = config; |
| 11 | +module.exports = mergeConfig(getDefaultConfig(__dirname), config); |
0 commit comments