2026-07-01 03:24:43 +00:00
|
|
|
const path = require('path');
|
|
|
|
|
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Metro configuration for the example app.
|
|
|
|
|
*
|
2026-07-02 02:07:32 +00:00
|
|
|
* Key goal: in monorepo / "file:.." / npm link setups, ensure all peer dependencies with native/JSI/Fabric code
|
|
|
|
|
* resolve to exactly the one copy under **example/node_modules**.
|
2026-07-01 03:24:43 +00:00
|
|
|
*
|
2026-07-02 02:07:32 +00:00
|
|
|
* Duplicate resolution causes various "similar-looking" errors:
|
|
|
|
|
* - SkiaPictureView config getter is undefined
|
2026-07-01 03:24:43 +00:00
|
|
|
* - createAnimatedNode: Animated node[...] already exists (Reanimated)
|
2026-07-02 02:07:32 +00:00
|
|
|
* - Various View registration conflicts, Invalid hook calls, etc.
|
2026-07-01 03:24:43 +00:00
|
|
|
*
|
2026-07-02 02:07:32 +00:00
|
|
|
* Maintenance rule: any peerDependency listed in package.json that contains native code must be forced to a singleton here.
|
2026-07-01 03:24:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const parentRoot = path.resolve(__dirname, '..');
|
|
|
|
|
const exampleNodeModules = path.resolve(__dirname, 'node_modules');
|
|
|
|
|
|
2026-07-02 02:07:32 +00:00
|
|
|
// Singleton dependency list (from this library's peerDependencies + commonly conflicting packages).
|
|
|
|
|
// When adding new peer dependencies, remember to update this list.
|
2026-07-01 03:24:43 +00:00
|
|
|
const singletonPackages = [
|
|
|
|
|
'react',
|
|
|
|
|
'react-native',
|
|
|
|
|
'react-native-reanimated',
|
|
|
|
|
'@shopify/react-native-skia',
|
|
|
|
|
'react-native-gesture-handler',
|
|
|
|
|
'react-native-fast-opencv',
|
|
|
|
|
'react-native-safe-area-context',
|
|
|
|
|
'react-native-fs',
|
2026-07-02 02:07:32 +00:00
|
|
|
// Optional peer
|
2026-07-01 03:24:43 +00:00
|
|
|
'react-native-image-picker',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
|
watchFolders: [parentRoot],
|
|
|
|
|
resolver: {
|
|
|
|
|
nodeModulesPaths: [exampleNodeModules],
|
|
|
|
|
|
2026-07-02 02:07:32 +00:00
|
|
|
// Method 1 (strongest): extraNodeModules forces aliases
|
|
|
|
|
// so import 'xxx' always gets the instance in example/node_modules
|
2026-07-01 03:24:43 +00:00
|
|
|
extraNodeModules: singletonPackages.reduce((acc, pkg) => {
|
|
|
|
|
acc[pkg] = path.resolve(exampleNodeModules, pkg);
|
|
|
|
|
return acc;
|
|
|
|
|
}, {}),
|
|
|
|
|
|
2026-07-02 02:07:32 +00:00
|
|
|
// Method 2 (double safety): blockList completely prevents Metro from finding these packages in the parent node_modules
|
2026-07-01 03:24:43 +00:00
|
|
|
blockList: singletonPackages.map(
|
|
|
|
|
(pkg) => new RegExp(`/MaskSegmentApp/node_modules/${pkg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/`),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
|