react-native-monorepo-config 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/index.js +16 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -23,8 +23,14 @@ export function withMetroConfig(baseConfig, { root, dirname }) {
23
23
  );
24
24
  }
25
25
 
26
+ if (!Array.isArray(pkg.workspaces)) {
27
+ throw new Error(
28
+ `The 'workspaces' field in the 'package.json' at '${root}' must be an array.`
29
+ );
30
+ }
31
+
26
32
  // Get the list of monorepo packages except current package
27
- const packages = (pkg.workspaces.packages || pkg.workspaces)
33
+ const packages = pkg.workspaces
28
34
  .flatMap((pattern) =>
29
35
  glob.sync(pattern, {
30
36
  cwd: root,
@@ -70,11 +76,17 @@ export function withMetroConfig(baseConfig, { root, dirname }) {
70
76
  ')$'
71
77
  );
72
78
 
73
- // When we import a package from the monorepo, metro won't be able to find their deps if they are hoisted
79
+ // When we import a package from the monorepo, metro may not be able to find the deps in blockList
74
80
  // We need to specify them in `extraNodeModules` to tell metro where to find them
75
81
  const extraNodeModules = peers.reduce((acc, name) => {
76
- if (fs.existsSync(path.join(root, 'node_modules', name))) {
77
- acc[name] = path.join(root, 'node_modules', name);
82
+ // First, try to find the package in the current package's node_modules
83
+ // As a fallback, try to find it in the monorepo root
84
+ const dir = [dirname, root]
85
+ .map((d) => path.join(d, 'node_modules', name))
86
+ .find((d) => fs.existsSync(d));
87
+
88
+ if (dir) {
89
+ acc[name] = dir;
78
90
  }
79
91
 
80
92
  return acc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-monorepo-config",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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/)",