-
Notifications
You must be signed in to change notification settings - Fork 905
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
[Feat] Add support for .xcode.env file in init and doctor commands #1585
Conversation
5d2ce3b
to
839cbc8
Compare
The CI is failing on two tasks related to Android (they are related to |
description: 'File to customize Xcode environment', | ||
getDiagnostics: async () => { | ||
return { | ||
needsToBeFixed: fs.existsSync('./ios/.xcode.env'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is making assumptions on where the iOS project lives. Should we use the config to figure out where the closest Podfile
is? And what about macOS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it using findProjectRoot
. I'm not sure that findPodfilePath
is the right approach, because for macOS project we have an ios
folder and a macos
folder, both of which have their own Podfile
.
$ ls -all ios
total 48
drwxr-xr-x 10 cipolleschi staff 320 6 Apr 17:00 .
drwxr-xr-x 24 cipolleschi staff 768 6 Apr 17:03 ..
-rw-r--r-- 1 cipolleschi staff 1106 6 Apr 16:59 Podfile
// ... other files here ...
$ ls -all macos
total 56
drwxr-xr-x 10 cipolleschi staff 320 6 Apr 17:06 .
drwxr-xr-x 24 cipolleschi staff 768 6 Apr 17:03 ..
-rw-r--r-- 1 cipolleschi staff 1086 6 Apr 17:03 Podfile
c4cc9fa
to
6da4683
Compare
label: '.xcode.env', | ||
description: 'File to customize Xcode environment', | ||
getDiagnostics: async () => { | ||
const projectRoot = findProjectRoot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat unrelated (and definitely not to be fixed in this PR), I looked briefly at the options that are passed to all CLI commands and it looks like they include this information. However, it doesn't look like they are properly forwarded to the individual fixers. It's a bit silly that we have to duplicate the effort to find this info again. Do we have an issue tracking this? cc @mikehardy @thymikee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we track this. Would make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #1588
const src = | ||
projectRoot + | ||
'/node_modules/react-native/template/ios/' + | ||
templateFilePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assuming the installation path of react-native
. We should probably use require.resolve
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope I used it properly. Let me know if I have to update the call.
applePlatformFolders.forEach(async (folder) => { | ||
const destFolder = projectRoot + folder; | ||
const destFilePath = destFolder + '/' + xcodeEnvFile; | ||
if (fs.existsSync(destFolder) && !fs.existsSync(destFilePath)) { | ||
await copyFileAsync(src, destFilePath); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assuming the location of the .xcworkspace
. I've seen many differing setups including:
<project-root>/ios/MyApp.xcworkspace
<project-root>/MyApp.xcworkspace
<project-root>/example/ios/MyApp.xcworkspace
<project-root>/apps/ios/src/MyApp.xcworkspace
Can we refactor findPodfilePath
to return all found Podfile
s and add a .xcode.env
next to them? I think that will be more accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or introduce a findAllPodfilePaths
helper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
096e572
to
e46b6be
Compare
import path from 'path'; | ||
import {promisify} from 'util'; | ||
import {findProjectRoot} from '@react-native-community/cli-tools'; | ||
import findAllPodfilePaths from '@react-native-community/cli-platform-ios/src/config/findAllPodfilePaths'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't import from src
since we transform the code before publishing and put it into build
directory; src
is not there in published files. We either need to export findAllPodfilePaths
from @react-native-community/cli-platform-ios
– and add a dependency on it for cli-doctor
and update "references"
in its tsconfig.json
– or move this helper to the cli-tools
package (and add a dependency on glob
). I'd go with the former for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI we have a yarn watch
script that builds files on the go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @thymikee, thanks for the review.
I updated the PR with your suggestion. Let me know if it's ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! One thing to address and we're good :)
e46b6be
to
d5b49d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏼
d5b49d1
to
414d4e6
Compare
f569596
to
eb1b479
Compare
Summary:
This PR adds the support for
.xcode.env
file in theinit
anddoctor
commands.This PR depends on this other one: facebook/react-native#33546
Test Plan:
This PR is quite similar to 1530. I would rely on the same tests.
If anyone has suggestions about how to test this, I will be more than happy to implement them.