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

feat(0.79): generate codegen before pod install #2600

Merged
Merged
Show file tree
Hide file tree
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
38 changes: 36 additions & 2 deletions packages/cli-config-apple/src/tools/installPods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,55 @@ import {
runSudo,
} from '@react-native-community/cli-tools';
import runBundleInstall from './runBundleInstall';
import path from 'path';

interface PodInstallOptions {
skipBundleInstall?: boolean;
newArchEnabled?: boolean;
iosFolderPath?: string;
platform: string;
root: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the location of the xcodeproj file. f that's the case, we are good to go.

Copy link
Member

Choose a reason for hiding this comment

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

@szymonrybczak let's call this cariable sourceDir instead of root then and pass proper value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

}

interface RunPodInstallOptions {
root: string;
platform: string;
shouldHandleRepoUpdate?: boolean;
newArchEnabled?: boolean;
}

async function runPodInstall(loader: Ora, options?: RunPodInstallOptions) {
async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
try {
if (fs.existsSync('build')) {
fs.rmSync('build', {recursive: true});
}

loader.start(
`Installing CocoaPods dependencies ${chalk.bold(
options?.newArchEnabled ? 'with New Architecture' : '',
)} ${chalk.dim('(this may take a few minutes)')}`,
);

const reactNativePath = path.dirname(
require.resolve('react-native', {paths: [process.cwd()]}),
);
const codegenScript = path.join(
reactNativePath,
'scripts',
'generate-codegen-artifacts.js',
);

execa.sync('node', [
codegenScript,
'-p',
options.root,
'-o',
process.cwd(),
'-t',
options.platform,
]);

await execa('bundle', ['exec', 'pod', 'install'], {
env: {
RCT_NEW_ARCH_ENABLED: options?.newArchEnabled ? '1' : '0',
Expand All @@ -53,6 +81,8 @@ async function runPodInstall(loader: Ora, options?: RunPodInstallOptions) {
await runPodInstall(loader, {
shouldHandleRepoUpdate: false,
newArchEnabled: options?.newArchEnabled,
platform: options.platform,
root: options.root,
});
} else {
loader.fail();
Expand Down Expand Up @@ -156,7 +186,11 @@ async function installPods(loader?: Ora, options?: PodInstallOptions) {
await installCocoaPods(loader);
}

await runPodInstall(loader, {newArchEnabled: options?.newArchEnabled});
await runPodInstall(loader, {
newArchEnabled: options?.newArchEnabled,
platform: options?.platform ?? 'ios',
root: options?.root ?? process.cwd(),
});
} finally {
process.chdir('..');
}
Expand Down
8 changes: 8 additions & 0 deletions packages/cli-config-apple/src/tools/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ async function install(
cachedDependenciesHash: string | undefined,
currentDependenciesHash: string,
iosFolderPath: string,
platform: string,
root: string,
) {
const loader = getLoader('Installing CocoaPods...');
try {
await installPods(loader, {
skipBundleInstall: !!cachedDependenciesHash,
iosFolderPath,
platform,
root,
});
cacheManager.set(packageJson.name, 'dependencies', currentDependenciesHash);
loader.succeed();
Expand Down Expand Up @@ -154,6 +158,8 @@ export default async function resolvePods(
cachedDependenciesHash,
currentDependenciesHash,
platformFolderPath,
platformName,
root,
);
} else if (
arePodsInstalled &&
Expand All @@ -175,6 +181,8 @@ export default async function resolvePods(
skipBundleInstall: !!cachedDependenciesHash,
newArchEnabled: options?.newArchEnabled,
iosFolderPath: platformFolderPath,
platform: platformName,
root,
});
cacheManager.set(
packageJson.name,
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ async function createFromTemplate({
try {
if (installPodsValue === 'true') {
didInstallPods = true;
await installPods(loader);
await installPods(loader, {
platform: 'ios',
root: projectDirectory,
});
loader.succeed();
setEmptyHashForCachedDependencies(projectName);
} else if (installPodsValue === 'undefined') {
Expand All @@ -298,7 +301,11 @@ async function createFromTemplate({
didInstallPods = installCocoapods;

if (installCocoapods) {
await installPods(loader, {newArchEnabled: true});
await installPods(loader, {
newArchEnabled: true,
platform: 'ios',
root: projectDirectory,
});
loader.succeed();
setEmptyHashForCachedDependencies(projectName);
}
Expand Down
Loading