Skip to content

Commit f1de95b

Browse files
fix: adjust doctor command to work with custom ios/ folder location (#1998)
* fix: adjust `doctor` command to work with custom `ios/` folder location * chore: delete useless type check
1 parent 78485dd commit f1de95b

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import {promisify} from 'util';
99
import {HealthCheckInterface} from '../../types';
1010

1111
const xcodeEnvFile = '.xcode.env';
12-
const pathSeparator = '/';
1312

1413
function removeLastPathComponent(pathString: string): string {
1514
return path.dirname(pathString);
1615
}
1716

1817
function 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

Comments
 (0)