-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetro.config.js
More file actions
65 lines (60 loc) · 2.36 KB
/
metro.config.js
File metadata and controls
65 lines (60 loc) · 2.36 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
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const path = require('path');
const fs = require('fs');
/**
* Metro configuration
* https://reactnative.dev/docs/metro
*
* @type {import('@react-native/metro-config').MetroConfig}
*/
const projectRoot = __dirname;
const sdkRoot = path.resolve(projectRoot, '..');
const config = {
projectRoot,
watchFolders: [sdkRoot],
resolver: {
// Prioritize example app's node_modules first to ensure single React instance
nodeModulesPaths: [
path.resolve(projectRoot, 'node_modules'),
path.resolve(sdkRoot, 'node_modules'),
],
extraNodeModules: {
'@kailyai/react-native-sdk': sdkRoot,
// Force React and React Native to always resolve from the example app's node_modules
// This prevents multiple React instances when the SDK has React in its node_modules
'react': path.resolve(projectRoot, 'node_modules/react'),
'react-native': path.resolve(projectRoot, 'node_modules/react-native'),
},
// Custom resolver to use source files directly for the SDK
resolveRequest: (context, moduleName, platform) => {
// If resolving the SDK package, prefer source files over compiled lib files
if (moduleName === '@kailyai/react-native-sdk') {
// Try to resolve to source index.ts first (for development)
const sourceIndex = path.resolve(sdkRoot, 'index.ts');
if (fs.existsSync(sourceIndex)) {
return {
filePath: sourceIndex,
type: 'sourceFile',
};
}
// Fallback to compiled lib/index.js
const libIndex = path.resolve(sdkRoot, 'lib', 'index.js');
if (fs.existsSync(libIndex)) {
return {
filePath: libIndex,
type: 'sourceFile',
};
}
}
// For sub-paths like '@kailyai/react-native-sdk/something', resolve normally
// Default resolution for other modules
return context.resolveRequest(context, moduleName, platform);
},
// Block resolving React from SDK's node_modules to prevent conflicts
blockList: [
new RegExp(`${sdkRoot.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/node_modules/react/.*`),
new RegExp(`${sdkRoot.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/node_modules/react-native/.*`),
],
},
};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);