react-native-monorepo-config 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/index.js +5 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,8 +63,8 @@ module.exports = {
|
|
|
63
63
|
resolver: {
|
|
64
64
|
...monoRepoConfig.resolver,
|
|
65
65
|
|
|
66
|
-
assetExts: resolver.assetExts.filter((ext) => ext !== 'svg'),
|
|
67
|
-
sourceExts: [...resolver.sourceExts, 'svg'],
|
|
66
|
+
assetExts: monoRepoConfig.resolver.assetExts.filter((ext) => ext !== 'svg'),
|
|
67
|
+
sourceExts: [...monoRepoConfig.resolver.sourceExts, 'svg'],
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
70
|
```
|
|
@@ -106,12 +106,12 @@ This configuration will setup a few things:
|
|
|
106
106
|
};
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
- Block packages defined in `peerDependencies` of other packages in the monorepo to avoid duplicate versions from being loaded. They must be added under `dependencies` or `devDependencies` in the app's `package.json
|
|
109
|
+
- Block packages defined in `peerDependencies` of other packages in the monorepo to avoid duplicate versions from being loaded. They must be added under `dependencies` or `devDependencies` in the app's `package.json` to be resolved correctly.
|
|
110
110
|
|
|
111
111
|
Loading duplicate versions of some packages such as `react` can cause issues. So this way multiple versions are not loaded. Make sure to specify `peerDependencies` for your packages appropriately.
|
|
112
112
|
|
|
113
113
|
- If the packages defined in `peerDependencies` have been hoisted to the monorepo root, point Metro to them so they can be found.
|
|
114
|
-
- Configure Metro's
|
|
114
|
+
- Configure Metro's resolver to prioritize `package.json#source` or the `source` condition in `package.json#exports` so that the app can import source code directly from other packages in the monorepo.
|
|
115
115
|
|
|
116
116
|
To utilize this, make sure to add the `source` field to the `package.json` of the packages you want to import from, e.g.:
|
|
117
117
|
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import path from 'node:path';
|
|
|
10
10
|
* @param {import('metro-config').MetroConfig} baseConfig Base Metro config to extend.
|
|
11
11
|
* @param {string} options.root Root directory path of the monorepo.
|
|
12
12
|
* @param {string} options.dirname Directory path of the current package.
|
|
13
|
+
* @param {Object} [options.workspaces] Optional list of workspace patterns. By default, `workspaces` field in the `package.json` at root is used.
|
|
13
14
|
*
|
|
14
15
|
* @returns {import('metro-config').MetroConfig}
|
|
15
16
|
*/
|
|
@@ -135,16 +136,10 @@ export function withMetroConfig(baseConfig, { root, dirname, workspaces }) {
|
|
|
135
136
|
|
|
136
137
|
// We need to exclude the peerDependencies we've collected in packages' node_modules
|
|
137
138
|
// Otherwise duplicate versions of the same package will be loaded
|
|
138
|
-
const blockList =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
peers.map(
|
|
143
|
-
(m) => `^${escape(path.join(dir, 'node_modules', m))}\\/.*$`
|
|
144
|
-
)
|
|
145
|
-
)
|
|
146
|
-
.join('|') +
|
|
147
|
-
')$'
|
|
139
|
+
const blockList = Object.values(packages).flatMap((dir) =>
|
|
140
|
+
peers.map(
|
|
141
|
+
(m) => new RegExp(`^${escape(path.join(dir, 'node_modules', m))}[\/\\\\]`)
|
|
142
|
+
)
|
|
148
143
|
);
|
|
149
144
|
|
|
150
145
|
// When we import a package from the monorepo, metro may not be able to find the deps in blockList
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-monorepo-config",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Configure Metro for a React Native app in a monorepo",
|
|
5
5
|
"repository": "https://github.com/satya164/react-native-monorepo-config",
|
|
6
6
|
"author": "Satyajit Sahoo <satyajit.happy@gmail.com> (https://github.com/satya164/)",
|