1- const fs = require ( 'fs' ) ;
2- const path = require ( 'path' ) ;
3- const { getDefaultConfig, mergeConfig} = require ( '@react-native/metro-config' ) ;
4- // const exclusionList = require('metro-config/src/defaults/exclusionList');
5- // const escape = require('escape-string-regexp');
1+ const fs = require ( 'fs' )
2+ const path = require ( 'path' )
3+ const { getDefaultConfig, mergeConfig } = require ( '@react-native/metro-config' )
64const pak = require ( '../package.json' )
75
8- const root = path . resolve ( __dirname , '..' ) ;
9- const rootNodeModulesPath = path . join ( root , 'node_modules' ) ;
10- const exampleNodeModulesPath = path . join ( __dirname , 'node_modules' ) ;
11-
6+ const root = path . resolve ( __dirname , '..' )
127const modules = Object . keys ( { ...pak . peerDependencies } )
138
149function getPackageNames ( nodeModulesPath ) {
1510 if ( ! fs . existsSync ( nodeModulesPath ) ) {
16- return [ ] ;
11+ return [ ]
1712 }
1813
19- const allFiles = fs . readdirSync ( nodeModulesPath ) ;
14+ const allFiles = fs . readdirSync ( nodeModulesPath )
2015
2116 // Filter out only directories (package names)
22- const packageNames = allFiles . filter ( file => {
23- const filePath = path . join ( nodeModulesPath , file ) ;
24- return fs . statSync ( filePath ) . isDirectory ( ) ;
25- } ) ;
17+ const packageNames = allFiles . filter ( ( file ) => {
18+ const filePath = path . join ( nodeModulesPath , file )
19+ return fs . statSync ( filePath ) . isDirectory ( )
20+ } )
2621
2722 // Handle scoped packages (e.g., @scope/package)
2823 const scopedPackages = packageNames
29- . filter ( pkg => pkg . startsWith ( '@' ) )
30- . flatMap ( scope => {
31- const scopePath = path . join ( nodeModulesPath , scope ) ;
32- const scopedFiles = fs . readdirSync ( scopePath ) ;
33- return scopedFiles . map ( scopedFile => `${ scope } /${ scopedFile } ` ) ;
34- } ) ;
24+ . filter ( ( pkg ) => pkg . startsWith ( '@' ) )
25+ . flatMap ( ( scope ) => {
26+ const scopePath = path . join ( nodeModulesPath , scope )
27+ const scopedFiles = fs . readdirSync ( scopePath )
28+ return scopedFiles . map ( ( scopedFile ) => `${ scope } /${ scopedFile } ` )
29+ } )
3530
3631 // Return both regular and scoped package names
3732 return packageNames
38- . filter ( pkg => ! pkg . startsWith ( '@' ) )
39- . concat ( scopedPackages ) ;
33+ . filter ( ( pkg ) => ! pkg . startsWith ( '@' ) )
34+ . concat ( scopedPackages )
4035}
4136
42- const exampleNodeModules = getPackageNames ( exampleNodeModulesPath ) ;
43-
4437const config = {
4538 projectRoot : __dirname ,
4639 watchFolders : [ root ] ,
4740
4841 // We need to make sure that only one version is loaded for peerDependencies
4942 // So we blacklist them at the root, and alias them to the versions in example's node_modules
5043 resolver : {
51- // unstable_enableSymlinks: true,
52- // blockList: exclusionList(
53- // exampleNodeModules.map(
54- // m => new RegExp(`^${escape(path.join(rootNodeModulesPath, m))}\\/.*$`),
55- // ),
56- // ),
57-
5844 extraNodeModules : modules . reduce ( ( acc , name ) => {
5945 acc [ name ] = path . join ( __dirname , 'node_modules' , name )
6046 return acc
@@ -69,6 +55,6 @@ const config = {
6955 } ,
7056 } ) ,
7157 } ,
72- } ;
58+ }
7359
74- module . exports = mergeConfig ( getDefaultConfig ( __dirname ) , config ) ;
60+ module . exports = mergeConfig ( getDefaultConfig ( __dirname ) , config )
0 commit comments