Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/many-flies-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rock-js/plugin-brownfield-ios': minor
---

feat: copy React Native prebuilt frameworks
23 changes: 19 additions & 4 deletions packages/platform-apple-helpers/src/lib/utils/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,30 @@ async function runPodInstall(options: {
fs.rmSync('build', { recursive: true });
}

const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
const loader = spinner({ indicator: 'timer' });
loader.start('Installing CocoaPods dependencies');
const reactNativeVersion = await getReactNativeVersion(options.projectRoot);
const isReactNative81OrHigher =
versionCompare(reactNativeVersion, '0.81.0') >= 0;
const isReactNative84OrHigher =
versionCompare(reactNativeVersion, '0.84.0') >= 0;

// below: starting from RN 0.84, Apple prebuilts are used by default; before this version,
// they need to be explicitly enabled
// ref: https://github.com/facebook/react-native/commit/df9d31b2435255f799aa024ffb0f87bcdb665645
const usePrebuiltReactNative = Boolean(
!options.brownfield && isReactNative81OrHigher && options.usePrebuiltRNCore,
isReactNative81OrHigher &&
(options.usePrebuiltRNCore ?? isReactNative84OrHigher),
);

logger.info(
usePrebuiltReactNative
? 'Using prebuilt React Native'
: 'Building React Native from source',
);

const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
const loader = spinner({ indicator: 'timer' });
loader.start('Installing CocoaPods dependencies');

const command = options.useBundler ? 'bundle' : 'pod';
const args = options.useBundler ? ['exec', 'pod', 'install'] : ['install'];
try {
Expand Down
63 changes: 63 additions & 0 deletions packages/plugin-brownfield-ios/src/lib/copyReactXcframeworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import fs, { existsSync } from 'node:fs';
import path from 'node:path';
import { color, logger, spinner } from '@rock-js/tools';

export function copyReactXcframeworks({
sourceDir,
destinationDir,
}: {
sourceDir: string;
destinationDir: string;
}) {
const react = 'React.xcframework';
const reactNativeDependencies = 'ReactNativeDependencies.xcframework';
const loader = spinner();

const reactFrameworkSource = path.join(
sourceDir,
`Pods/React-Core-prebuilt/${react}`,
);

const reactNativeDepsSource = path.join(
sourceDir,
`Pods/ReactNativeDependencies/framework/packages/react-native/${reactNativeDependencies}`,
);

if (existsSync(reactFrameworkSource)) {
loader.start(`Copying ${color.bold(react)}`);
const reactDestination = path.join(destinationDir, react);

if (existsSync(reactDestination)) {
logger.debug(`Removing old ${react} copy`);
fs.rmSync(reactDestination, { recursive: true, force: true });
}

fs.cpSync(reactFrameworkSource, reactDestination, {
recursive: true,
force: true,
});

loader.stop(`Copied ${color.bold(react)}`);
}

if (existsSync(reactNativeDepsSource)) {
loader.start(`Copying ${color.bold(reactNativeDependencies)}`);

const reactNativeDepsDestination = path.join(
destinationDir,
reactNativeDependencies,
);

if (existsSync(reactNativeDepsDestination)) {
logger.debug(`Removing old ${reactNativeDependencies} copy`);
fs.rmSync(reactNativeDepsDestination, { recursive: true, force: true });
}

fs.cpSync(reactNativeDepsSource, reactNativeDepsDestination, {
recursive: true,
force: true,
});

loader.stop(`Copied ${color.bold(reactNativeDependencies)}`);
}
}
10 changes: 9 additions & 1 deletion packages/plugin-brownfield-ios/src/lib/pluginBrownfieldIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@rock-js/platform-apple-helpers';
import { colorLink, intro, logger, outro, relativeToCwd } from '@rock-js/tools';
import { copyHermesXcframework } from './copyHermesXcframework.js';
import { copyReactXcframeworks } from './copyReactXcframeworks.js';

const buildOptions = getBuildOptions({ platformName: 'ios' });

Expand All @@ -35,6 +36,7 @@ export const packageIosAction = async (
pluginConfig?: IOSProjectConfig,
) => {
intro('Packaging iOS project');
logger.setVerbose(args.verbose ?? false);

// 1) Build the project
const iosConfig = getValidProjectConfig('ios', projectRoot, pluginConfig);
Expand Down Expand Up @@ -116,7 +118,13 @@ export const packageIosAction = async (
reactNativeVersion,
});

// 5) Inform the user
// 5) Copy React and ReactNativeDependencies xcframeworks to the output path
copyReactXcframeworks({
sourceDir,
destinationDir: frameworkTargetOutputDir,
});

// 6) Inform the user
logger.log(
`XCFrameworks are available at: ${colorLink(
relativeToCwd(frameworkTargetOutputDir),
Expand Down
Loading