Skip to content

Commit b10faf6

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Create the orchestration function to coordinate the creation of the hard links (#53642)
Summary: Pull Request resolved: #53642 ## Context One of the quirk of SwiftPM is that the packages has to have access to the headers they need. Usually this is solved by properly setting the header_search_path. However, in SwiftPM, we are not allowed to use headers search path that escape the package itself (basically, header search path can't start with `../`). To work around this limitation we are recreating the correct Header structure by using hardlinks to the actual headers. ## Changed In this change we are adding a function that is used to orchestrate the helpers function defined in previous changes. ## Changelog: [Internal] - Reviewed By: cortinico Differential Revision: D81778457 fbshipit-source-id: b4ab8c902d6d7e6ca4b89ccbab75c1b5d84ce00a
1 parent c6395ec commit b10faf6

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ vendor/
133133
# Swift Package build folder
134134
/packages/react-native/.build
135135
/packages/react-native/.swiftpm
136+
/packages/react-native/React/includes/
136137

137138
# @react-native/codegen
138139
/packages/react-native/React/FBReactNativeSpec/

packages/react-native/scripts/swiftpm/prepare-app-dependencies-headers.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,99 @@
1010

1111
const {librariesMappings, reactMappings} = require('./headers-mappings');
1212
const {
13+
symlinkCodegenHeaders,
1314
symlinkHeadersFromPath,
1415
symlinkReactAppleHeaders,
1516
symlinkReactCommonHeaders,
17+
symlinkThirdPartyDependenciesHeaders,
1618
} = require('./headers-utils');
1719
const fs = require('fs');
1820
const path = require('path');
1921

22+
/*::
23+
type RequiredHeaders = 'react-native' | 'codegen' | 'third-party-dependencies' | 'all';
24+
*/
25+
26+
/**
27+
* Prepares app dependencies headers for SwiftPM integration
28+
* @param {string} reactNativePath - Path to the React Native directory
29+
* @param {string} iosAppPath - Path to the iOS app directory
30+
* @param {string} outputFolder - Path to the output folder where headers will be hard linked
31+
* @param {string} requiredHeaders - Type of headers to include: 'react-native', 'codegen', 'third-party-dependencies', or 'all'
32+
*/
33+
function prepareAppDependenciesHeaders(
34+
reactNativePath /*: string */,
35+
iosAppPath /*: string */,
36+
outputFolder /*: string */,
37+
requiredHeaders /*: RequiredHeaders */,
38+
) /*: void */ {
39+
// Validate parameters
40+
if (!reactNativePath || !iosAppPath || !outputFolder || !requiredHeaders) {
41+
throw new Error(
42+
'Missing required parameters. Usage: prepareAppDependenciesHeaders(reactNativePath, iosAppPath, outputFolder, requiredHeaders)',
43+
);
44+
}
45+
46+
if (
47+
!['react-native', 'codegen', 'third-party-dependencies', 'all'].includes(
48+
requiredHeaders,
49+
)
50+
) {
51+
throw new Error(
52+
"requiredHeaders must be one of: 'react-native', 'codegen', 'third-party-dependencies', 'all'",
53+
);
54+
}
55+
56+
// Validate paths exist
57+
if (!fs.existsSync(reactNativePath)) {
58+
throw new Error(`React Native path does not exist: ${reactNativePath}`);
59+
}
60+
61+
if (!fs.existsSync(iosAppPath)) {
62+
throw new Error(`iOS app path does not exist: ${iosAppPath}`);
63+
}
64+
65+
// Create output folder if it doesn't exist
66+
if (!fs.existsSync(outputFolder)) {
67+
fs.mkdirSync(outputFolder, {recursive: true});
68+
console.log(`Created output folder: ${outputFolder}`);
69+
}
70+
71+
console.log('Preparing app dependencies headers...');
72+
console.log(`React Native path: ${reactNativePath}`);
73+
console.log(`iOS app path: ${iosAppPath}`);
74+
console.log(`Output folder: ${outputFolder}`);
75+
console.log(`Required headers: ${requiredHeaders}`);
76+
77+
try {
78+
switch (requiredHeaders) {
79+
case 'react-native':
80+
symlinkReactNativeHeaders(reactNativePath, outputFolder);
81+
break;
82+
case 'codegen':
83+
symlinkCodegenHeaders(reactNativePath, iosAppPath, outputFolder);
84+
break;
85+
case 'third-party-dependencies':
86+
symlinkThirdPartyDependenciesHeaders(reactNativePath, outputFolder);
87+
break;
88+
case 'all':
89+
symlinkReactNativeHeaders(reactNativePath, outputFolder);
90+
symlinkCodegenHeaders(reactNativePath, iosAppPath, outputFolder);
91+
symlinkThirdPartyDependenciesHeaders(reactNativePath, outputFolder);
92+
break;
93+
default:
94+
throw new Error(
95+
`Unsupported requiredHeaders value: ${requiredHeaders}`,
96+
);
97+
}
98+
99+
console.log('Successfully prepared app dependencies headers');
100+
} catch (error) {
101+
console.error('Error preparing app dependencies headers:', error.message);
102+
throw error;
103+
}
104+
}
105+
20106
/**
21107
* Create symlinks for React Native headers in the output folder.
22108
* This function orchestrate the creation of all the headers required by React Native:
@@ -100,4 +186,5 @@ function symlinkReactNativeHeaders(
100186

101187
module.exports = {
102188
symlinkReactNativeHeaders,
189+
prepareAppDependenciesHeaders,
103190
};

0 commit comments

Comments
 (0)