Skip to content

Commit a1575d0

Browse files
cipolleschimeta-codesync[bot]
authored andcommitted
Add function to run pod deintegrate (#53706)
Summary: Pull Request resolved: #53706 ## Context When configuring an app to build with SwiftPM from source, there is a sequence of operations we need to run in order to prepare the project correctly. ## Changed Add a function that runs `pod deintegrate` to remove remainings of cocoapods ## Changelog: [Internal] - Reviewed By: cortinico Differential Revision: D81778468 fbshipit-source-id: 20e1cfefcef8318d63d4a6ff92050ced0f91ef53
1 parent f0725f7 commit a1575d0

2 files changed

Lines changed: 174 additions & 1 deletion

File tree

packages/react-native/scripts/swiftpm/__tests__/prepare-app-utils-test.js

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,29 @@
1010

1111
'use strict';
1212

13-
const {findXcodeProjectDirectory} = require('../prepare-app-utils');
13+
const {
14+
findXcodeProjectDirectory,
15+
runPodDeintegrate,
16+
} = require('../prepare-app-utils');
1417

1518
// Mock child_process module
1619
jest.mock('child_process');
1720

21+
// Mock console methods - disable React Native's strict console checking
22+
const originalConsole = global.console;
23+
24+
beforeAll(() => {
25+
global.console = {
26+
...originalConsole,
27+
log: jest.fn(),
28+
warn: jest.fn(),
29+
};
30+
});
31+
32+
afterAll(() => {
33+
global.console = originalConsole;
34+
});
35+
1836
describe('findXcodeProjectDirectory', () => {
1937
let mockExecSync;
2038

@@ -155,3 +173,138 @@ describe('findXcodeProjectDirectory', () => {
155173
);
156174
});
157175
});
176+
177+
describe('runPodDeintegrate', () => {
178+
let mockExecSync;
179+
let mockConsoleLog;
180+
let mockConsoleWarn;
181+
182+
beforeEach(() => {
183+
// Setup mocks
184+
const childProcess = require('child_process');
185+
mockExecSync = childProcess.execSync;
186+
187+
mockConsoleLog = console.log;
188+
mockConsoleWarn = console.warn;
189+
190+
// Reset all mocks
191+
jest.clearAllMocks();
192+
});
193+
194+
it('should run pod deintegrate successfully', async () => {
195+
// Setup
196+
const appIosPath = '/path/to/app/ios';
197+
198+
mockExecSync.mockReturnValue(undefined);
199+
200+
// Execute
201+
await runPodDeintegrate(appIosPath);
202+
203+
// Assert
204+
expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', {
205+
cwd: appIosPath,
206+
stdio: 'inherit',
207+
});
208+
expect(mockExecSync).toHaveBeenCalledTimes(1);
209+
expect(mockConsoleLog).toHaveBeenCalledWith(
210+
'Running pod deintegrate in: /path/to/app/ios',
211+
);
212+
expect(mockConsoleLog).toHaveBeenCalledWith('✓ Pod deintegrate completed');
213+
expect(mockConsoleLog).toHaveBeenCalledTimes(2);
214+
expect(mockConsoleWarn).not.toHaveBeenCalled();
215+
});
216+
217+
it('should handle different iOS directory paths', async () => {
218+
// Setup
219+
const appIosPath = '/Users/developer/MyApp/ios';
220+
221+
mockExecSync.mockReturnValue(undefined);
222+
223+
// Execute
224+
await runPodDeintegrate(appIosPath);
225+
226+
// Assert
227+
expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', {
228+
cwd: appIosPath,
229+
stdio: 'inherit',
230+
});
231+
expect(mockConsoleLog).toHaveBeenCalledWith(
232+
'Running pod deintegrate in: /Users/developer/MyApp/ios',
233+
);
234+
expect(mockConsoleLog).toHaveBeenCalledWith('✓ Pod deintegrate completed');
235+
});
236+
237+
it('should handle paths with spaces correctly', async () => {
238+
// Setup
239+
const appIosPath = '/path/to/my app/ios folder';
240+
241+
mockExecSync.mockReturnValue(undefined);
242+
243+
// Execute
244+
await runPodDeintegrate(appIosPath);
245+
246+
// Assert
247+
expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', {
248+
cwd: appIosPath,
249+
stdio: 'inherit',
250+
});
251+
expect(mockConsoleLog).toHaveBeenCalledWith(
252+
'Running pod deintegrate in: /path/to/my app/ios folder',
253+
);
254+
expect(mockConsoleLog).toHaveBeenCalledWith('✓ Pod deintegrate completed');
255+
});
256+
257+
it('should handle pod deintegrate command failure gracefully', async () => {
258+
// Setup
259+
const appIosPath = '/path/to/app/ios';
260+
const mockError = new Error('No Podfile.lock found');
261+
262+
mockExecSync.mockImplementation(() => {
263+
throw mockError;
264+
});
265+
266+
// Execute
267+
await runPodDeintegrate(appIosPath);
268+
269+
// Assert
270+
expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', {
271+
cwd: appIosPath,
272+
stdio: 'inherit',
273+
});
274+
expect(mockConsoleLog).toHaveBeenCalledWith(
275+
'Running pod deintegrate in: /path/to/app/ios',
276+
);
277+
expect(mockConsoleLog).not.toHaveBeenCalledWith(
278+
'✓ Pod deintegrate completed',
279+
);
280+
expect(mockConsoleWarn).toHaveBeenCalledWith(
281+
'⚠️ Pod deintegrate failed (this might be expected if no Podfile.lock exists)',
282+
);
283+
expect(mockConsoleWarn).toHaveBeenCalledTimes(1);
284+
});
285+
286+
it('should handle command not found error', async () => {
287+
// Setup
288+
const appIosPath = '/path/to/app/ios';
289+
const mockError = new Error('command not found: pod');
290+
291+
mockExecSync.mockImplementation(() => {
292+
throw mockError;
293+
});
294+
295+
// Execute
296+
await runPodDeintegrate(appIosPath);
297+
298+
// Assert
299+
expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', {
300+
cwd: appIosPath,
301+
stdio: 'inherit',
302+
});
303+
expect(mockConsoleLog).toHaveBeenCalledWith(
304+
'Running pod deintegrate in: /path/to/app/ios',
305+
);
306+
expect(mockConsoleWarn).toHaveBeenCalledWith(
307+
'⚠️ Pod deintegrate failed (this might be expected if no Podfile.lock exists)',
308+
);
309+
});
310+
});

packages/react-native/scripts/swiftpm/prepare-app-utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,27 @@ function findXcodeProjectDirectory(
4040
);
4141
}
4242
}
43+
/**
44+
* Run pod deintegrate from app directory
45+
*/
46+
async function runPodDeintegrate(
47+
appIosPath /*: string */,
48+
) /*: Promise<void> */ {
49+
try {
50+
console.log(`Running pod deintegrate in: ${appIosPath}`);
51+
execSync('pod deintegrate', {
52+
cwd: appIosPath,
53+
stdio: 'inherit',
54+
});
55+
console.log('✓ Pod deintegrate completed');
56+
} catch (error) {
57+
console.warn(
58+
'⚠️ Pod deintegrate failed (this might be expected if no Podfile.lock exists)',
59+
);
60+
}
61+
}
4362

4463
module.exports = {
4564
findXcodeProjectDirectory,
65+
runPodDeintegrate,
4666
};

0 commit comments

Comments
 (0)