@@ -9,14 +9,13 @@ import {promisify} from 'util';
99import { HealthCheckInterface } from '../../types' ;
1010
1111const xcodeEnvFile = '.xcode.env' ;
12- const pathSeparator = '/' ;
1312
1413function removeLastPathComponent ( pathString : string ) : string {
1514 return path . dirname ( pathString ) ;
1615}
1716
1817function pathHasXcodeEnvFile ( pathString : string ) : boolean {
19- const xcodeEnvPath = pathString + pathSeparator + xcodeEnvFile ;
18+ const xcodeEnvPath = path . join ( pathString , xcodeEnvFile ) ;
2019 return fs . existsSync ( xcodeEnvPath ) ;
2120}
2221
@@ -29,11 +28,16 @@ export default {
2928 description : 'File to customize Xcode environment' ,
3029 getDiagnostics : async ( _ , config ) => {
3130 try {
32- const projectRoot = config ?. root ?? findProjectRoot ( ) ;
33- const missingXcodeEnvFile = findPodfilePaths ( projectRoot ) . some ( ( p ) => {
34- const basePath = path . dirname ( p ) ;
35- return ! pathHasXcodeEnvFile ( basePath ) ;
36- } ) ;
31+ const iosFolderPath = config ?. project . ios ?. sourceDir ?? '' ;
32+
33+ const missingXcodeEnvFile = findPodfilePaths ( iosFolderPath ) . some (
34+ ( podfilePath ) => {
35+ return ! pathHasXcodeEnvFile (
36+ removeLastPathComponent ( path . join ( iosFolderPath , podfilePath ) ) ,
37+ ) ;
38+ } ,
39+ ) ;
40+
3741 return {
3842 needsToBeFixed : missingXcodeEnvFile ,
3943 } ;
@@ -52,15 +56,19 @@ export default {
5256 projectRoot ,
5357 'react-native/template/ios' ,
5458 ) ;
55- const src = templateIosPath + pathSeparator + templateXcodeEnv ;
59+ const src = path . join ( templateIosPath , templateXcodeEnv ) ;
5660 const copyFileAsync = promisify ( fs . copyFile ) ;
5761
58- findPodfilePaths ( projectRoot )
59- . map ( removeLastPathComponent )
62+ const iosFolderPath = config ?. project . ios ?. sourceDir ?? '' ;
63+
64+ findPodfilePaths ( iosFolderPath )
65+ . map ( ( podfilePath ) =>
66+ removeLastPathComponent ( path . join ( iosFolderPath , podfilePath ) ) ,
67+ )
6068 // avoid overriding existing .xcode.env
6169 . filter ( pathDoesNotHaveXcodeEnvFile )
6270 . forEach ( async ( pathString : string ) => {
63- const destFilePath = pathString + pathSeparator + xcodeEnvFile ;
71+ const destFilePath = path . join ( pathString , xcodeEnvFile ) ;
6472 await copyFileAsync ( src , destFilePath ) ;
6573 } ) ;
6674 loader . succeed ( '.xcode.env file have been created!' ) ;
0 commit comments