Skip to content

Commit 2fe008b

Browse files
cipolleschimeta-codesync[bot]
authored andcommitted
Add configure iOS prebuilds (hermes and dependencies) (#53671)
Summary: Pull Request resolved: #53671 ## 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 prepares the prebuilds for ios so we can leverage them when building from source ## Changelog: [Internal] - Reviewed By: cortinico Differential Revision: D81778467 fbshipit-source-id: bacfcfd3d646bfa27dcd800417e4787308a51a86
1 parent a1575d0 commit 2fe008b

2 files changed

Lines changed: 186 additions & 0 deletions

File tree

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

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
const {
1414
findXcodeProjectDirectory,
15+
runIosPrebuild,
1516
runPodDeintegrate,
1617
} = require('../prepare-app-utils');
1718

@@ -174,6 +175,165 @@ describe('findXcodeProjectDirectory', () => {
174175
});
175176
});
176177

178+
describe('runIosPrebuild', () => {
179+
let mockExecSync;
180+
let mockConsoleLog;
181+
let originalProcessEnv;
182+
183+
beforeEach(() => {
184+
// Setup mocks
185+
const childProcess = require('child_process');
186+
mockExecSync = childProcess.execSync;
187+
188+
mockConsoleLog = console.log;
189+
190+
// Store original process.env to restore later
191+
originalProcessEnv = process.env;
192+
193+
// Reset all mocks
194+
jest.clearAllMocks();
195+
});
196+
197+
afterEach(() => {
198+
// Restore original process.env
199+
process.env = originalProcessEnv;
200+
});
201+
202+
it('should run iOS prebuild successfully with nightly versions', async () => {
203+
// Setup
204+
const reactNativePath = '/path/to/react-native';
205+
206+
mockExecSync.mockReturnValue(undefined);
207+
208+
// Execute
209+
await runIosPrebuild(reactNativePath);
210+
211+
// Assert
212+
expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', {
213+
cwd: reactNativePath,
214+
env: {
215+
...originalProcessEnv,
216+
RN_DEP_VERSION: 'nightly',
217+
HERMES_VERSION: 'nightly',
218+
},
219+
stdio: 'inherit',
220+
});
221+
expect(mockExecSync).toHaveBeenCalledTimes(1);
222+
expect(mockConsoleLog).toHaveBeenCalledWith(
223+
'Running iOS prebuild with nightly versions...',
224+
);
225+
expect(mockConsoleLog).toHaveBeenCalledWith('✓ iOS prebuild completed');
226+
expect(mockConsoleLog).toHaveBeenCalledTimes(2);
227+
});
228+
229+
it('should handle different React Native paths', async () => {
230+
// Setup
231+
const reactNativePath = '/Users/developer/react-native';
232+
233+
mockExecSync.mockReturnValue(undefined);
234+
235+
// Execute
236+
await runIosPrebuild(reactNativePath);
237+
238+
// Assert
239+
expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', {
240+
cwd: reactNativePath,
241+
env: {
242+
...originalProcessEnv,
243+
RN_DEP_VERSION: 'nightly',
244+
HERMES_VERSION: 'nightly',
245+
},
246+
stdio: 'inherit',
247+
});
248+
});
249+
250+
it('should handle paths with spaces correctly', async () => {
251+
// Setup
252+
const reactNativePath = '/path/to/react native project';
253+
254+
mockExecSync.mockReturnValue(undefined);
255+
256+
// Execute
257+
await runIosPrebuild(reactNativePath);
258+
259+
// Assert
260+
expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', {
261+
cwd: reactNativePath,
262+
env: {
263+
...originalProcessEnv,
264+
RN_DEP_VERSION: 'nightly',
265+
HERMES_VERSION: 'nightly',
266+
},
267+
stdio: 'inherit',
268+
});
269+
});
270+
271+
it('should throw error when iOS prebuild fails', async () => {
272+
// Setup
273+
const reactNativePath = '/path/to/react-native';
274+
const mockError = new Error('Build failed');
275+
276+
mockExecSync.mockImplementation(() => {
277+
throw mockError;
278+
});
279+
280+
// Execute & Assert
281+
await expect(runIosPrebuild(reactNativePath)).rejects.toThrow(
282+
'iOS prebuild failed: Build failed',
283+
);
284+
285+
expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', {
286+
cwd: reactNativePath,
287+
env: {
288+
...originalProcessEnv,
289+
RN_DEP_VERSION: 'nightly',
290+
HERMES_VERSION: 'nightly',
291+
},
292+
stdio: 'inherit',
293+
});
294+
expect(mockConsoleLog).toHaveBeenCalledWith(
295+
'Running iOS prebuild with nightly versions...',
296+
);
297+
expect(mockConsoleLog).not.toHaveBeenCalledWith('✓ iOS prebuild completed');
298+
});
299+
300+
it('should handle script not found error', async () => {
301+
// Setup
302+
const reactNativePath = '/path/to/react-native';
303+
const mockError = new Error('Cannot find module scripts/ios-prebuild');
304+
305+
mockExecSync.mockImplementation(() => {
306+
throw mockError;
307+
});
308+
309+
// Execute & Assert
310+
await expect(runIosPrebuild(reactNativePath)).rejects.toThrow(
311+
'iOS prebuild failed: Cannot find module scripts/ios-prebuild',
312+
);
313+
});
314+
315+
it('should handle root directory path', async () => {
316+
// Setup
317+
const reactNativePath = '/';
318+
319+
mockExecSync.mockReturnValue(undefined);
320+
321+
// Execute
322+
await runIosPrebuild(reactNativePath);
323+
324+
// Assert
325+
expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', {
326+
cwd: '/',
327+
env: {
328+
...originalProcessEnv,
329+
RN_DEP_VERSION: 'nightly',
330+
HERMES_VERSION: 'nightly',
331+
},
332+
stdio: 'inherit',
333+
});
334+
});
335+
});
336+
177337
describe('runPodDeintegrate', () => {
178338
let mockExecSync;
179339
let mockConsoleLog;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,33 @@ async function runPodDeintegrate(
6060
}
6161
}
6262

63+
/**
64+
* Run iOS prebuild with environment variables
65+
*/
66+
async function runIosPrebuild(
67+
reactNativePath /*: string */,
68+
) /*: Promise<void> */ {
69+
console.log('Running iOS prebuild with nightly versions...');
70+
71+
const env = {
72+
...process.env,
73+
RN_DEP_VERSION: 'nightly',
74+
HERMES_VERSION: 'nightly',
75+
};
76+
77+
try {
78+
execSync('node scripts/ios-prebuild -s', {
79+
cwd: reactNativePath,
80+
env: env,
81+
stdio: 'inherit',
82+
});
83+
console.log('✓ iOS prebuild completed');
84+
} catch (error) {
85+
throw new Error(`iOS prebuild failed: ${error.message}`);
86+
}
87+
}
6388
module.exports = {
6489
findXcodeProjectDirectory,
6590
runPodDeintegrate,
91+
runIosPrebuild,
6692
};

0 commit comments

Comments
 (0)