|
| 1 | +const { getDefaultConfig } = require('expo/metro-config'); |
| 2 | + |
1 | 3 | const path = require('path'); |
2 | 4 | const fs = require('fs'); |
3 | | -const { getDefaultConfig } = require('expo/metro-config'); |
4 | 5 |
|
5 | | -const packagesRoot = path.resolve(__dirname, '../../packages'); |
6 | | -const docToolsRoot = path.resolve(__dirname, '../../doc-tools'); |
| 6 | +const projectRoot = __dirname; |
| 7 | +const workspaceRoot = path.resolve(projectRoot, '../..'); |
| 8 | +const packagesRoot = path.resolve(projectRoot, '../../packages'); |
| 9 | +const docToolsRoot = path.resolve(projectRoot, '../../doc-tools'); |
| 10 | + |
| 11 | +const packagesDirs = fs.readdirSync(packagesRoot); |
| 12 | +const docToolsDirs = fs.readdirSync(docToolsRoot); |
| 13 | + |
| 14 | +const config = getDefaultConfig(projectRoot); |
7 | 15 |
|
8 | | -const localPkgs = fs.readdirSync(packagesRoot); |
9 | | -const docToolksPkgs = fs.readdirSync(docToolsRoot); |
| 16 | +// Watch folders for monorepo packages |
| 17 | +config.watchFolders = [ |
| 18 | + projectRoot, |
| 19 | + packagesRoot, |
| 20 | + ...packagesDirs.map((d) => path.resolve(packagesRoot, d)), |
| 21 | + ...docToolsDirs.map((d) => path.resolve(docToolsRoot, d)) |
| 22 | +]; |
10 | 23 |
|
11 | | -const watchFolders = localPkgs |
12 | | - .map((f) => path.join(packagesRoot, f)) |
13 | | - .concat(docToolksPkgs.map((f) => path.join(docToolsRoot, f))); |
| 24 | +config.resolver = { |
| 25 | + ...config.resolver, |
| 26 | + extraNodeModules: { |
| 27 | + // Deduplicate React and React-Native to avoid "Invalid hook call" errors |
| 28 | + 'react': path.resolve(projectRoot, 'node_modules/react'), |
| 29 | + 'react-dom': path.resolve(projectRoot, 'node_modules/react-dom'), |
| 30 | + 'react-native': path.resolve(projectRoot, 'node_modules/react-native'), |
| 31 | + // Map workspace packages to their source directories |
| 32 | + 'react-native-render-html': path.resolve(packagesRoot, 'render-html/src'), |
| 33 | + '@native-html/transient-render-engine': path.resolve(packagesRoot, 'transient-render-engine/src'), |
| 34 | + '@native-html/css-processor': path.resolve(packagesRoot, 'css-processor/src'), |
| 35 | + // Map dependencies from workspace root |
| 36 | + '@jsamr/counter-style': path.resolve(workspaceRoot, 'node_modules/@jsamr/counter-style'), |
| 37 | + '@jsamr/react-native-li': path.resolve(workspaceRoot, 'node_modules/@jsamr/react-native-li'), |
| 38 | + 'csstype': path.resolve(workspaceRoot, 'node_modules/csstype'), |
| 39 | + 'domelementtype': path.resolve(workspaceRoot, 'node_modules/domelementtype'), |
| 40 | + 'domhandler': path.resolve(workspaceRoot, 'node_modules/domhandler'), |
| 41 | + 'domutils': path.resolve(workspaceRoot, 'node_modules/domutils'), |
| 42 | + 'htmlparser2': path.resolve(workspaceRoot, 'node_modules/htmlparser2'), |
| 43 | + 'ramda': path.resolve(workspaceRoot, 'node_modules/ramda'), |
| 44 | + 'css-to-react-native': path.resolve(workspaceRoot, 'node_modules/css-to-react-native'), |
| 45 | + 'urijs': path.resolve(workspaceRoot, 'node_modules/urijs'), |
| 46 | + }, |
| 47 | + nodeModulesPaths: [ |
| 48 | + path.resolve(projectRoot, 'node_modules'), |
| 49 | + path.resolve(workspaceRoot, 'node_modules'), // Add root monorepo node_modules |
| 50 | + ...packagesDirs.map((d) => |
| 51 | + path.resolve(packagesRoot, d, 'node_modules') |
| 52 | + ), |
| 53 | + ...docToolsDirs.map((d) => |
| 54 | + path.resolve(docToolsRoot, d, 'node_modules') |
| 55 | + ) |
| 56 | + ] |
| 57 | +}; |
14 | 58 |
|
15 | | -module.exports = (async () => { |
16 | | - const config = await getDefaultConfig(__dirname); |
17 | | - return { |
18 | | - ...config, |
19 | | - watchFolders, |
20 | | - resolver: { |
21 | | - extraNodeModules: new Proxy( |
22 | | - {}, |
23 | | - { |
24 | | - get: (target, name) => path.join(__dirname, `node_modules/${name}`) |
25 | | - } |
26 | | - ) |
27 | | - } |
28 | | - }; |
29 | | -})(); |
| 59 | +module.exports = config; |
0 commit comments