-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmetro.config.js
More file actions
66 lines (55 loc) · 2.45 KB
/
Copy pathmetro.config.js
File metadata and controls
66 lines (55 loc) · 2.45 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
const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');
const config = getDefaultConfig(__dirname);
const mobileNodeModules = path.resolve(__dirname, 'node_modules');
// Honor the "exports" conditional-resolution field. Needed for ESM-only
// transitive deps like multiformats@13 that have no CJS main entry.
config.resolver.unstable_enablePackageExports = true;
// Packages that must resolve to a single instance app-wide. Duplicate
// copies pulled in transitively would break React Context (react,
// @tanstack/react-query) or crash native module registration
// (react-native-safe-area-context's RNCSafeAreaProvider view).
const SINGLE_INSTANCE_PACKAGES = new Set([
'react',
'react-dom',
'react-native',
'@tanstack/react-query',
'react-native-safe-area-context',
]);
// Hard-redirect every import of those packages to the mobile project's copy.
// resolveRequest runs after Metro has already done its own walk-up and
// supersedes whatever it would have picked, including any nested copy.
// The fallback to context.resolveRequest preserves Metro's default behavior
// for every other request.
const defaultResolveRequest = config.resolver.resolveRequest;
config.resolver.resolveRequest = (context, moduleName, platform) => {
// Match either the bare package name ("react") or a deep import
// ("@tanstack/react-query/persistQueryClient").
const firstSegment = moduleName.startsWith('@')
? moduleName.split('/').slice(0, 2).join('/')
: moduleName.split('/')[0];
if (SINGLE_INSTANCE_PACKAGES.has(firstSegment)) {
const subpath = moduleName.slice(firstSegment.length);
return context.resolveRequest(
context,
path.join(mobileNodeModules, firstSegment + subpath),
platform,
);
}
return defaultResolveRequest
? defaultResolveRequest(context, moduleName, platform)
: context.resolveRequest(context, moduleName, platform);
};
config.resolver.nodeModulesPaths = [mobileNodeModules];
// Standard nested-node-modules blocklist.
config.resolver.blockList = [
/node_modules\/quorum-crypto\/node_modules\/.*/,
];
// Windows-only: use Metro's Node crawler instead of Watchman.
// Watchman's IPC pipe is built from the Windows account name; a non-ASCII
// account name makes the fb-watchman client hang forever on "watch-project"
// (facebook/watchman#572, #543). macOS/Linux/CI keep using Watchman.
if (process.platform === 'win32') {
config.resolver.useWatchman = false;
}
module.exports = config;