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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/cli-config-apple/src/__tests__/pods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jest.mock('@react-native-community/cli-tools', () => ({
},
}));
jest.mock('../tools/installPods', () => jest.fn());
jest.mock('../tools/runCodegen', () => jest.fn());
const dependencyHash = 'd41d8cd98f00b204e9800998ecf8427e';

const packageJson = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-config-apple/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export {
getProjectConfig,
findPodfilePaths,
} from './config';

export {default as runCodegen} from './tools/runCodegen';
export {default as installPods} from './tools/installPods';
export {default as resolvePods} from './tools/pods';
export {default as findXcodeProject} from './config/findXcodeProject';
Expand Down
7 changes: 4 additions & 3 deletions packages/cli-config-apple/src/tools/installPods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface RunPodInstallOptions {
newArchEnabled?: boolean;
}

async function runPodInstall(loader: Ora, options?: RunPodInstallOptions) {
async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
try {
loader.start(
Expand Down Expand Up @@ -155,8 +155,9 @@ async function installPods(loader?: Ora, options?: PodInstallOptions) {
loader.info();
await installCocoaPods(loader);
}

await runPodInstall(loader, {newArchEnabled: options?.newArchEnabled});
await runPodInstall(loader, {
newArchEnabled: options?.newArchEnabled,
});
} finally {
process.chdir('..');
}
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-config-apple/src/tools/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IOSDependencyConfig,
} from '@react-native-community/cli-types';
import {ApplePlatform} from '../types';
import runCodegen from './runCodegen';

interface ResolvePodsOptions {
forceInstall?: boolean;
Expand Down Expand Up @@ -89,9 +90,15 @@ async function install(
cachedDependenciesHash: string | undefined,
currentDependenciesHash: string,
iosFolderPath: string,
platform: string,
root: string,
) {
const loader = getLoader('Installing CocoaPods...');
try {
await runCodegen({
root,
platform,
});
await installPods(loader, {
skipBundleInstall: !!cachedDependenciesHash,
iosFolderPath,
Expand Down Expand Up @@ -154,6 +161,8 @@ export default async function resolvePods(
cachedDependenciesHash,
currentDependenciesHash,
platformFolderPath,
platformName,
root,
);
} else if (
arePodsInstalled &&
Expand Down
35 changes: 35 additions & 0 deletions packages/cli-config-apple/src/tools/runCodegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fs from 'fs';
import path from 'path';
import execa from 'execa';

interface CodegenOptions {
root: string;
platform: string;
}

async function runCodegen(options: CodegenOptions): Promise<void> {
if (fs.existsSync('build')) {
fs.rmSync('build', {recursive: true});
}

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

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

export default runCodegen;
13 changes: 11 additions & 2 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError';
import {createTemplateUri} from './version';
import {TEMPLATE_COMMUNITY_REACT_NATIVE_VERSION} from './constants';
import type {Options} from './types';
import {runCodegen} from '@react-native-community/cli-config-apple';

const DEFAULT_VERSION = 'latest';

Expand Down Expand Up @@ -284,7 +285,11 @@ async function createFromTemplate({
try {
if (installPodsValue === 'true') {
didInstallPods = true;
await installPods(loader);
await runCodegen({
root: projectDirectory,
platform: 'ios',
});
await installPods(loader, {});
loader.succeed();
setEmptyHashForCachedDependencies(projectName);
} else if (installPodsValue === 'undefined') {
Expand All @@ -298,7 +303,11 @@ async function createFromTemplate({
didInstallPods = installCocoapods;

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