1
+ /**
2
+ * @noflow
3
+ */
4
+
5
+ const fs = require ( 'fs' ) ;
6
+ const path = require ( 'path' ) ;
7
+ const blacklist = require ( 'metro/src/blacklist' ) ;
8
+
9
+ module . exports = {
10
+ getBlacklistRE ( ) {
11
+ return blacklist ( [
12
+ / r e a c t \- n a t i v e \- c u s t o m \- t a b s \/ n o d e _ m o d u l e s \/ r e a c t - n a t i v e \/ ( .* ) / ,
13
+ / r e a c t \- n a t i v e \- c u s t o m \- t a b s \/ n o d e _ m o d u l e s \/ r e a c t \/ ( .* ) / ,
14
+ ] ) ;
15
+ } ,
16
+ extraNodeModules : getNodeModulesForDirectory ( path . resolve ( '.' ) ) ,
17
+ } ;
18
+
19
+ function getNodeModulesForDirectory ( rootPath ) {
20
+ const nodeModulePath = path . join ( rootPath , 'node_modules' ) ;
21
+ const folders = fs . readdirSync ( nodeModulePath ) ;
22
+ return folders . reduce ( ( modules , folderName ) => {
23
+ const folderPath = path . join ( nodeModulePath , folderName ) ;
24
+ if ( folderName . startsWith ( '@' ) ) {
25
+ const scopedModuleFolders = fs . readdirSync ( folderPath ) ;
26
+ const scopedModules = scopedModuleFolders . reduce (
27
+ ( scopedModules , scopedFolderName ) => {
28
+ scopedModules [
29
+ `${ folderName } /${ scopedFolderName } `
30
+ ] = maybeResolveSymlink ( path . join ( folderPath , scopedFolderName ) ) ;
31
+ return scopedModules ;
32
+ } ,
33
+ { }
34
+ ) ;
35
+ return Object . assign ( { } , modules , scopedModules ) ;
36
+ }
37
+ modules [ folderName ] = maybeResolveSymlink ( folderPath ) ;
38
+ return modules ;
39
+ } , { } ) ;
40
+ }
41
+
42
+ function maybeResolveSymlink ( maybeSymlinkPath ) {
43
+ if ( fs . lstatSync ( maybeSymlinkPath ) . isSymbolicLink ( ) ) {
44
+ const resolved = path . resolve (
45
+ path . dirname ( maybeSymlinkPath ) ,
46
+ fs . readlinkSync ( maybeSymlinkPath )
47
+ ) ;
48
+ return resolved ;
49
+ }
50
+ return maybeSymlinkPath ;
51
+ }
0 commit comments