-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathmetro.config.js
More file actions
106 lines (88 loc) · 3.33 KB
/
metro.config.js
File metadata and controls
106 lines (88 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');
const fs = require('fs');
const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, '..');
const config = getDefaultConfig(projectRoot);
// 1. Watch all files within the monorepo
config.watchFolders = [workspaceRoot];
// 2. Let Metro handle the monorepo packages
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'node_modules'),
path.resolve(workspaceRoot, 'node_modules'),
];
// 3. Custom resolver to point to src instead of dist
config.resolver.resolveRequest = (context, moduleName, platform) => {
// Handle @rneui packages - redirect to src instead of dist
if (moduleName.startsWith('@rneui/base')) {
const packagePath = path.resolve(workspaceRoot, 'packages/base');
// Remove the package name prefix
let subpath = moduleName.replace('@rneui/base', '').replace(/^\//, '');
// Remove 'dist/' if it's in the path (e.g., '@rneui/base/dist/Badge/Badge')
subpath = subpath.replace(/^dist\//, '');
// Build the base path
const basePath = subpath
? path.join(packagePath, 'src', subpath)
: path.join(packagePath, 'src', 'index');
// Try different extensions for files
const extensions = ['.tsx', '.ts', '.native.tsx', '.native.ts', '.js', '.jsx'];
for (const ext of extensions) {
const filePath = basePath + ext;
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
return {
type: 'sourceFile',
filePath: filePath,
};
}
}
// If no file found, try as directory with /index
if (fs.existsSync(basePath) && fs.statSync(basePath).isDirectory()) {
for (const ext of extensions) {
const filePath = path.join(basePath, 'index' + ext);
if (fs.existsSync(filePath)) {
return {
type: 'sourceFile',
filePath: filePath,
};
}
}
}
}
if (moduleName.startsWith('@rneui/themed')) {
const packagePath = path.resolve(workspaceRoot, 'packages/themed');
// Remove the package name prefix
let subpath = moduleName.replace('@rneui/themed', '').replace(/^\//, '');
// Remove 'dist/' if it's in the path
subpath = subpath.replace(/^dist\//, '');
// Build the base path
const basePath = subpath
? path.join(packagePath, 'src', subpath)
: path.join(packagePath, 'src', 'index');
// Try different extensions for files
const extensions = ['.tsx', '.ts', '.native.tsx', '.native.ts', '.js', '.jsx'];
for (const ext of extensions) {
const filePath = basePath + ext;
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
return {
type: 'sourceFile',
filePath: filePath,
};
}
}
// If no file found, try as directory with /index
if (fs.existsSync(basePath) && fs.statSync(basePath).isDirectory()) {
for (const ext of extensions) {
const filePath = path.join(basePath, 'index' + ext);
if (fs.existsSync(filePath)) {
return {
type: 'sourceFile',
filePath: filePath,
};
}
}
}
}
// Let the default resolver handle everything else
return context.resolveRequest(context, moduleName, platform);
};
module.exports = config;