react-native-monorepo-config 0.1.10 → 0.2.1
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 +16 -0
- package/index.js +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,22 @@ module.exports = {
|
|
|
69
69
|
};
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
## Custom workspaces
|
|
73
|
+
|
|
74
|
+
By default, the workspaces are read from the `workspaces` field in the monorepo root's `package.json`. If you want to specify a custom list of workspaces, you can pass a `workspaces` array to the options:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
const monoRepoConfig = withMetroConfig(getDefaultConfig(__dirname), {
|
|
78
|
+
root: path.resolve(__dirname, '../..'),
|
|
79
|
+
dirname: __dirname,
|
|
80
|
+
workspaces: ['packages/a', 'packages/b'],
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The workspaces can contain globs or relative paths. They will be resolved relative to the monorepo root.
|
|
85
|
+
|
|
86
|
+
This can be useful if you're not using Yarn workspaces or if you want to include only specific packages to improve performance in large monorepos.
|
|
87
|
+
|
|
72
88
|
## How it works
|
|
73
89
|
|
|
74
90
|
This configuration will setup a few things:
|
package/index.js
CHANGED
|
@@ -13,30 +13,36 @@ import path from 'node:path';
|
|
|
13
13
|
*
|
|
14
14
|
* @returns {import('metro-config').MetroConfig}
|
|
15
15
|
*/
|
|
16
|
-
export function withMetroConfig(baseConfig, { root, dirname }) {
|
|
16
|
+
export function withMetroConfig(baseConfig, { root, dirname, workspaces }) {
|
|
17
17
|
const pkg = JSON.parse(
|
|
18
18
|
fs.readFileSync(path.join(root, 'package.json'), 'utf8')
|
|
19
19
|
);
|
|
20
20
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (workspaces == null) {
|
|
22
|
+
if (pkg.workspaces == null) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`No 'workspaces' field found in the 'package.json' at '${root}' and no 'workspaces' option was provided.`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
if (
|
|
29
|
+
!Array.isArray(pkg.workspaces) &&
|
|
30
|
+
!Array.isArray(pkg.workspaces.packages)
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`The 'workspaces' field in the 'package.json' at '${root}' must be an array.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
workspaces = pkg.workspaces.packages || pkg.workspaces;
|
|
38
|
+
} else if (!Array.isArray(workspaces)) {
|
|
39
|
+
throw new Error(`The 'workspaces' option must be an array.`);
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
// Get the list of monorepo packages except current package
|
|
37
43
|
// Yarn also supports workspaces as an object with a "packages" field
|
|
38
44
|
const packages = Object.fromEntries(
|
|
39
|
-
|
|
45
|
+
workspaces
|
|
40
46
|
.flatMap((pattern) =>
|
|
41
47
|
glob.sync(pattern, {
|
|
42
48
|
cwd: root,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-monorepo-config",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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/)",
|