Skip to content

Commit d011058

Browse files
refactor: move pods installation from init to ios-specific commands (#2077)
* remove pod installation from init process * create dependency hashes and store it in cache * move installPods from doctor to platform-ios * install pods on run-ios and build-ios * add --force-pods flag to run-ios * add tests * add tests for pods installation * use crypto and rename releaseCacheManager to cacheManager * move run sudo to cli-tools * use findPodfilePath * resolve only native dependencies for pod check * update pod installation tests * add version property to dependency config & use it to hash dependencies * cr updates * add pod installation prompt to init * better error handling when package.json not found * add --install-pods flag to init * update tests * fix config tests * set hash in cache when initializing new project * try/catch require package.json * update type for installCocoaPods
1 parent 520c90f commit d011058

File tree

30 files changed

+399
-47
lines changed

30 files changed

+399
-47
lines changed

__e2e__/config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ beforeAll(() => {
4949

5050
// Initialise React Native project
5151

52-
runCLI(DIR, ['init', 'TestProject']);
52+
runCLI(DIR, ['init', 'TestProject', '--install-pods']);
5353

5454
// Link CLI to the project
5555
const pkgs = [

__e2e__/init.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ test('init fails if the directory already exists', () => {
6161

6262
test('init should prompt for the project name', () => {
6363
createCustomTemplateFiles();
64-
const {stdout} = runCLI(DIR, ['init', 'test', '--template', templatePath]);
64+
const {stdout} = runCLI(DIR, [
65+
'init',
66+
'test',
67+
'--template',
68+
templatePath,
69+
'--install-pods',
70+
'false',
71+
]);
6572

6673
(prompts as jest.MockedFunction<typeof prompts>).mockReturnValue(
6774
Promise.resolve({
@@ -79,6 +86,8 @@ test('init --template filepath', () => {
7986
'--template',
8087
templatePath,
8188
'TestInit',
89+
'--install-pods',
90+
'false',
8291
]);
8392

8493
expect(stdout).toContain('Run instructions');
@@ -103,6 +112,8 @@ test('init --template file with custom directory', () => {
103112
projectName,
104113
'--directory',
105114
'custom-path',
115+
'--install-pods',
116+
'false',
106117
]);
107118

108119
// make sure --directory option is used in run instructions
@@ -149,6 +160,8 @@ test('init uses npm as the package manager with --npm', () => {
149160
templatePath,
150161
'TestInit',
151162
'--npm',
163+
'--install-pods',
164+
'false',
152165
]);
153166

154167
expect(stdout).toContain('Run instructions');

__e2e__/root.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ beforeAll(() => {
2323
writeFiles(cwd, {});
2424

2525
// Initialise React Native project
26-
runCLI(cwd, ['init', 'TestProject']);
27-
26+
runCLI(cwd, ['init', 'TestProject', '--install-pods']);
2827
// Link CLI to the project
2928
const pkgs = [
3029
'@react-native-community/cli-platform-ios',

docs/commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ module.exports = {
9696

9797
Skip dependencies installation
9898

99+
#### `--install-pods [boolean]`
100+
101+
Determine if CocoaPods should be installed when initializing a project. If set to `true` it will install pods, if set to `false`, it will skip the step entirely. If not used, prompt will be displayed
102+
99103
#### `--npm`
100104
> [!WARNING]
101105
> `--npm` is deprecated and will be removed in the future. Please use `--pm npm` instead.

docs/platforms.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ On Android and iOS, this function returns a dependency configuration for:
111111
```ts
112112
type IOSDependencyConfig = {
113113
podspecPath: string;
114+
version: string;
114115
scriptPhases: Array<IOSScriptPhase>;
115116
configurations: string[];
116117
};

packages/cli-config/src/__tests__/__snapshots__/index-test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Object {
1111
],
1212
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
1313
"scriptPhases": Array [],
14+
"version": "unresolved",
1415
},
1516
},
1617
"root": "<<REPLACED>>/node_modules/react-native-test",
@@ -57,6 +58,7 @@ Object {
5758
"path": "./phase.sh",
5859
},
5960
],
61+
"version": "unresolved",
6062
},
6163
},
6264
"root": "<<REPLACED>>/node_modules/react-native-test",
@@ -107,6 +109,7 @@ Object {
107109
"show_env_vars_in_log": false,
108110
},
109111
],
112+
"version": "unresolved",
110113
},
111114
},
112115
"root": "<<REPLACED>>/node_modules/react-native-test",
@@ -131,6 +134,7 @@ Object {
131134
"configurations": Array [],
132135
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
133136
"scriptPhases": Array [],
137+
"version": "unresolved",
134138
},
135139
},
136140
"root": "<<REPLACED>>/node_modules/react-native-test",
@@ -149,6 +153,7 @@ Object {
149153
],
150154
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
151155
"scriptPhases": Array [],
156+
"version": "unresolved",
152157
},
153158
},
154159
"root": "<<REPLACED>>/node_modules/react-native-test",

packages/cli-config/src/__tests__/index-test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ test('supports dependencies from user configuration with custom root and propert
241241
writeFiles(DIR, {
242242
...REACT_NATIVE_MOCK,
243243
'native-libs/local-lib/LocalRNLibrary.podspec': '',
244+
'native-libs/local-lib/package.json': `
245+
{
246+
"name": "local-lib",
247+
"version": "0.0.1",
248+
"dependencies": {
249+
"react-native": "0.0.1"
250+
}
251+
}`,
244252
'react-native.config.js': `
245253
const path = require('path');
246254
const root = path.resolve('${escapePathSeparator(
@@ -276,6 +284,7 @@ module.exports = {
276284
"configurations": Array [],
277285
"podspecPath": "custom-path",
278286
"scriptPhases": Array [],
287+
"version": "0.0.1",
279288
},
280289
},
281290
"root": "<<REPLACED>>/native-libs/local-lib",

packages/cli-config/src/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const projectConfig = t
122122
// IOSDependencyConfig
123123
.object({
124124
podspecPath: t.string(),
125+
version: t.string(),
125126
configurations: t.array().items(t.string()).default([]),
126127
scriptPhases: t.array().items(t.object()).default([]),
127128
})

packages/cli-doctor/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"prompts": "^2.4.2",
2525
"semver": "^7.5.2",
2626
"strip-ansi": "^5.2.0",
27-
"sudo-prompt": "^9.0.0",
2827
"wcwidth": "^1.0.1",
2928
"yaml": "^2.2.1"
3029
},

packages/cli-doctor/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ export const commands = {info, doctor};
99
* refactor the init in order to remove that connection.
1010
*/
1111
export {default as versionRanges} from './tools/versionRanges';
12-
export {default as installPods} from './tools/installPods';

0 commit comments

Comments
 (0)