Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ And then:

```sh
cd /my/new/react-native/project/
yarn link "@react-native-community/cli-platform-ios" "@react-native-community/cli-platform-android" "@react-native-community/cli" "@react-native-community/cli-server-api" "@react-native-community/cli-types" "@react-native-community/cli-tools" "@react-native-community/cli-clean" "@react-native-community/cli-doctor" "@react-native-community/cli-config" "@react-native-community/cli-platform-apple" "@react-native-community/cli-link-assets"
yarn link "@react-native-community/cli-platform-ios" "@react-native-community/cli-platform-android" "@react-native-community/cli" "@react-native-community/cli-server-api" "@react-native-community/cli-types" "@react-native-community/cli-tools" "@react-native-community/cli-clean" "@react-native-community/cli-doctor" "@react-native-community/cli-config" "@react-native-community/cli-config-android" "@react-native-community/cli-platform-apple" "@react-native-community/cli-config-apple" "@react-native-community/cli-link-assets"
```

Once you're done with testing and you'd like to get back to regular setup, run `yarn unlink` instead of `yarn link` from above command. Then `yarn install --force`.
Expand Down
70 changes: 70 additions & 0 deletions packages/cli-config-apple/src/__tests__/installPods.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import path from 'path';
import {cleanup, getTempDirectory, writeFiles} from '../../../../jest/helpers';
import installPods from '../tools/installPods';
import {execaPod} from '../tools/pods';

jest.mock('../tools/pods', () => ({
execaPod: jest.fn(),
}));

jest.mock('../tools/runBundleInstall', () => jest.fn());

const DIR = getTempDirectory('install_pods_test');
const IOS_DIR = path.join(DIR, 'ios');
const originalCwd = process.cwd();

beforeEach(() => {
cleanup(DIR);
jest.resetAllMocks();
process.chdir(originalCwd);

writeFiles(DIR, {
Gemfile: "source 'https://rubygems.org'",
'ios/Podfile': 'platform :ios, "13.0"',
});
});

afterEach(() => {
process.chdir(originalCwd);
});

describe('installPods', () => {
it('omits RCT_NEW_ARCH_ENABLED when new architecture value is unknown', async () => {
(execaPod as jest.Mock).mockResolvedValue(undefined);

await installPods(undefined, {
iosFolderPath: IOS_DIR,
skipBundleInstall: true,
});

expect(execaPod).toHaveBeenNthCalledWith(
2,
['install'],
expect.objectContaining({
env: expect.not.objectContaining({
RCT_NEW_ARCH_ENABLED: expect.anything(),
}),
}),
);
});

it('keeps RCT_NEW_ARCH_ENABLED when new architecture value is known', async () => {
(execaPod as jest.Mock).mockResolvedValue(undefined);

await installPods(undefined, {
iosFolderPath: IOS_DIR,
skipBundleInstall: true,
newArchEnabled: true,
});

expect(execaPod).toHaveBeenNthCalledWith(
2,
['install'],
expect.objectContaining({
env: expect.objectContaining({
RCT_NEW_ARCH_ENABLED: '1',
}),
}),
);
});
});
16 changes: 16 additions & 0 deletions packages/cli-config-apple/src/__tests__/pods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ describe('resolvePods', () => {
expect(installPods).toHaveBeenCalled();
});

it('passes new architecture flag when force option is set', async () => {
createTempFiles();

await resolvePods(DIR, path.join(DIR, 'ios'), {}, 'ios', '', {
forceInstall: true,
newArchEnabled: true,
});

expect(installPods).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
newArchEnabled: true,
}),
);
});

it('should install pods when there is no cached hash of dependencies', async () => {
createTempFiles();

Expand Down
4 changes: 3 additions & 1 deletion packages/cli-config-apple/src/tools/installPods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {

await execaPod(['install'], {
env: {
RCT_NEW_ARCH_ENABLED: options?.newArchEnabled ? '1' : '0',
...(options?.newArchEnabled !== undefined && {
RCT_NEW_ARCH_ENABLED: options.newArchEnabled ? '1' : '0',
}), // Skip forcing when architecture is unknown (e.g. first pod install)
RCT_IGNORE_PODS_DEPRECATION: '1', // From React Native 0.79 onwards, users shouldn't install CocoaPods manually.
...(process.env.USE_THIRD_PARTY_JSC && {
USE_THIRD_PARTY_JSC: process.env.USE_THIRD_PARTY_JSC,
Expand Down
3 changes: 3 additions & 0 deletions packages/cli-config-apple/src/tools/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async function install(
platform: string,
root: string,
reactNativePath: string,
newArchEnabled?: boolean,
) {
const loader = getLoader('Installing CocoaPods...');
try {
Expand All @@ -105,6 +106,7 @@ async function install(
});
await installPods(loader, {
skipBundleInstall: !!cachedDependenciesHash,
newArchEnabled,
iosFolderPath,
});
cacheManager.set(packageJson.name, 'dependencies', currentDependenciesHash);
Expand Down Expand Up @@ -169,6 +171,7 @@ export default async function resolvePods(
platformName,
root,
reactNativePath,
options?.newArchEnabled,
);
} else if (
arePodsInstalled &&
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-doctor/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const info = async function getInfo(_argv: Array<string>, ctx: Config) {
ctx.project.ios.sourceDir,
);

platforms.iOS.newArchEnabled = isNewArchitecture;
platforms.iOS.newArchEnabled = isNewArchitecture ?? notFound;
} catch {
platforms.iOS.newArchEnabled = notFound;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'path';
import {
cleanup,
getTempDirectory,
writeFiles,
} from '../../../../../jest/helpers';
import getArchitecture from '../getArchitecture';

const DIR = getTempDirectory('get_architecture_test');

beforeEach(() => {
cleanup(DIR);
});

describe('getArchitecture', () => {
it('returns undefined when Pods project does not exist', async () => {
const result = await getArchitecture(path.join(DIR, 'ios'));

expect(result).toBeUndefined();
});

it('returns true when Pods project is configured with new architecture', async () => {
writeFiles(DIR, {
'ios/Pods/Pods.xcodeproj/project.pbxproj': '-DRCT_NEW_ARCH_ENABLED=1',
});

const result = await getArchitecture(path.join(DIR, 'ios'));

expect(result).toBe(true);
});

it('returns false when Pods project does not include new architecture flag', async () => {
writeFiles(DIR, {
'ios/Pods/Pods.xcodeproj/project.pbxproj': 'SOME_OTHER_FLAG=1',
});

const result = await getArchitecture(path.join(DIR, 'ios'));

expect(result).toBe(false);
});
});
2 changes: 1 addition & 1 deletion packages/cli-platform-apple/src/tools/getArchitecture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default async function getArchitecture(iosSourceDir: string) {

return project.includes('-DRCT_NEW_ARCH_ENABLED=1');
} catch {
return false;
return undefined;
}
}
Loading