Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly create .xcode.env file with doctors auto fix #1668

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {HealthCheckInterface} from '../../types';
import fs from 'fs';
import path from 'path';
import {promisify} from 'util';
import {findProjectRoot} from '@react-native-community/cli-tools';
import {
findProjectRoot,
resolveNodeModuleDir,
} from '@react-native-community/cli-tools';
import {findPodfilePaths} from '@react-native-community/cli-platform-ios';

const xcodeEnvFile = '.xcode.env';
Expand All @@ -29,33 +31,37 @@ export default {
getDiagnostics: async () => {
const projectRoot = findProjectRoot();
const allPathsHasXcodeEnvFile = findPodfilePaths(projectRoot)
.map((pathString) => {
.map((pathString: string) => {
const basePath = removeLastPathComponent(pathString);
return pathHasXcodeEnvFile(basePath);
})
.reduce((previousValue, currentValue) => previousValue && currentValue);
.reduce(
(previousValue: boolean, currentValue: boolean) =>
previousValue && currentValue,
);
return {
needsToBeFixed: !allPathsHasXcodeEnvFile,
};
},
runAutomaticFix: async () => {
runAutomaticFix: async ({loader}) => {
loader.stop();
const templateXcodeEnv = '_xcode.env';
const projectRoot = findProjectRoot();

const templateIosPath = path.dirname(
require.resolve('react-native/template/ios'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this silently failed, can we make sure the runAutomaticFix has a proper error handler that surfaces to the exit code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! 👍

const templateIosPath = resolveNodeModuleDir(
projectRoot,
'react-native/template/ios',
);

const src = templateIosPath + templateXcodeEnv;
const src = templateIosPath + pathSeparator + templateXcodeEnv;
const copyFileAsync = promisify(fs.copyFile);

findPodfilePaths(projectRoot)
.map(removeLastPathComponent)
// avoid overriding existing .xcode.env
.filter(pathDoesNotHaveXcodeEnvFile)
.forEach(async (pathString) => {
.forEach(async (pathString: string) => {
const destFilePath = pathString + pathSeparator + xcodeEnvFile;
await copyFileAsync(src, destFilePath);
});
loader.succeed();
},
} as HealthCheckInterface;