|
| 1 | +diff --git a/index.js b/index.js |
| 2 | +index 4dc070a2a6ca0ef3fe4e929509f9d9108debd643..f66a3359800b6720ef848d8b76783ff5d3dfd7e7 100644 |
| 3 | +--- a/index.js |
| 4 | ++++ b/index.js |
| 5 | +@@ -133,14 +133,6 @@ export function withMetroConfig(baseConfig, { root, dirname, workspaces }) { |
| 6 | + (m, i, self) => self.lastIndexOf(m) === i // Remove duplicates |
| 7 | + ); |
| 8 | + |
| 9 | +- // We need to exclude the peerDependencies we've collected in packages' node_modules |
| 10 | +- // Otherwise duplicate versions of the same package will be loaded |
| 11 | +- const blockList = Object.values(packages).flatMap((dir) => |
| 12 | +- peers.map( |
| 13 | +- (m) => new RegExp(`^${escape(path.join(dir, 'node_modules', m))}[\/\\\\]`) |
| 14 | +- ) |
| 15 | +- ); |
| 16 | +- |
| 17 | + // When we import a package from the monorepo, metro may not be able to find the deps in blockList |
| 18 | + // We need to specify them in `extraNodeModules` to tell metro where to find them |
| 19 | + const extraNodeModules = peers.reduce((acc, name) => { |
| 20 | +@@ -153,6 +145,20 @@ export function withMetroConfig(baseConfig, { root, dirname, workspaces }) { |
| 21 | + return acc; |
| 22 | + }, {}); |
| 23 | + |
| 24 | ++ // We need to exclude the peerDependencies we've collected in packages' node_modules |
| 25 | ++ // Otherwise duplicate versions of the same package will be loaded |
| 26 | ++ const blockList = Object.values(packages).flatMap((dir) => |
| 27 | ++ peers.map((m) => { |
| 28 | ++ // Skip blocking items that we've specified in extraNodeModules |
| 29 | ++ const peerPath = path.join(dir, 'node_modules', m) |
| 30 | ++ if(extraNodeModules[m] === peerPath) { |
| 31 | ++ return null; |
| 32 | ++ } |
| 33 | ++ return new RegExp(`^${escape(path.join(dir, 'node_modules', m))}[\/\\\\]`) |
| 34 | ++ } |
| 35 | ++ ) |
| 36 | ++ ).filter((value) => value != null); |
| 37 | ++ |
| 38 | + // If monorepo root is a package, add it to extraNodeModules so metro can find it |
| 39 | + // Normally monorepo packages are symlinked to node_modules, but the root is not |
| 40 | + // So we need to add it manually |
0 commit comments