-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
patch-xcode.js
54 lines (49 loc) · 1.46 KB
/
patch-xcode.js
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
/**
* External dependencies
*/
const fs = require( 'fs' );
const path = require( 'path' );
/**
* Temporary patch to fix all xCode 12 libs
*/
const nodeModulesDir = path.join( __dirname, '../', 'node_modules' );
const fetchRNPackageDirs = ( dir ) => {
const dirList = fs.readdirSync( dir, { withFileTypes: true } );
const packageDirs = [];
dirList
.filter( ( file ) => file.isDirectory() )
.map( ( file ) => file.name )
.forEach( ( packageName ) => {
const packageDir = path.join( dir, packageName );
if ( packageName.startsWith( '@' ) ) {
packageDirs.push( ...fetchRNPackageDirs( packageDir ) );
} else {
const files = fs.readdirSync( packageDir );
const podSpecs = files.filter( ( file ) =>
file.toLowerCase().endsWith( '.podspec' )
);
if ( podSpecs.length > 0 ) {
packageDirs.push( {
dir: packageDir,
files: podSpecs,
package: packageName,
} );
}
}
} );
return packageDirs;
};
const packagesWithPodspec = fetchRNPackageDirs( nodeModulesDir );
const dependencyRegex = /(s\.dependency +(?:'|"))React('|")/;
packagesWithPodspec.forEach( ( packageWithPodspec ) => {
packageWithPodspec.files.forEach( ( file ) => {
const filePath = path.join( packageWithPodspec.dir, file );
const fileContents = fs.readFileSync( filePath );
if ( `${ fileContents }`.match( dependencyRegex ) ) {
fs.writeFileSync(
filePath,
`${ fileContents }`.replace( dependencyRegex, '$1React-Core$2' )
);
}
} );
} );