Files
react-native/packages/react-native/scripts/swiftpm/headers-mappings.js
T
Riccardo Cipolleschi 6807231120 Create function to create hardlink to header required to build React Native Core (#53635)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53635

## 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 did two things:
1. we move the helper functions to a headers-utils.js file (and the tests to the `headers-utils-test.js` file)
2. we added a function that coordinates the creation of the header links *and added tests for it)

## Changelog:
[Internal] -

Reviewed By: cortinico

Differential Revision: D81778464

fbshipit-source-id: fd8eb5a7af55db0a08c4d299c5470058d5424768
2025-09-22 10:14:58 -07:00

150 lines
4.3 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
const path = require('path');
/*::
type MappingOption = {
destination: string;
excludeFolders: Array<string>;
preserveStructure: boolean
}
*/
function reactCommonMappings(
reactCommonPath /*: string */,
headersOutput /*: string */,
) /*: { [string]: MappingOption } */ {
let mappings /*: { [string]: MappingOption } */ = {};
mappings[`${reactCommonPath}/react`] = {
destination: path.join(headersOutput, 'react'),
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/react/renderer/components/view/platform/cxx`] = {
destination: path.join(headersOutput, 'React/renderer/components/view'),
excludeFolders: [],
preserveStructure: false,
};
mappings[`${reactCommonPath}/react/renderer/graphics/platform/ios`] = {
destination: path.join(headersOutput, 'react/renderer/graphics'),
excludeFolders: [],
preserveStructure: false,
};
mappings[`${reactCommonPath}/react/runtime/platform/ios/ReactCommon`] = {
destination: path.join(headersOutput, 'ReactCommon'),
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/react/nativemodule/core/platform/ios`] = {
destination: headersOutput,
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/react/nativemodule/samples/platform/ios`] = {
destination: headersOutput,
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/callinvoker`] = {
destination: headersOutput,
excludeFolders: ['tests'],
preserveStructure: true,
};
mappings[`${reactCommonPath}/cxxreact`] = {
destination: path.join(headersOutput, 'cxxreact'),
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/jserrorhandler`] = {
destination: path.join(headersOutput, 'jserrorhandler'),
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/jsinspector-modern`] = {
destination: path.join(headersOutput, 'jsinspector-modern'),
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/oscompat`] = {
destination: path.join(headersOutput, 'oscompat'),
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/runtimeexecutor`] = {
destination: headersOutput,
excludeFolders: [],
preserveStructure: true,
};
mappings[`${reactCommonPath}/yoga/yoga`] = {
destination: path.join(headersOutput, 'yoga'),
excludeFolders: [],
preserveStructure: true,
};
return mappings;
}
function reactMappings(
reactNativePath /*: string */,
headersOutput /*: string */,
) /*: { [string]: MappingOption } */ {
let mappings /*: { [string]: MappingOption } */ = {};
mappings[`${reactNativePath}/React`] = {
destination: path.join(headersOutput, 'React'),
excludeFolders: ['includes', 'headers', 'tests'],
preserveStructure: false,
};
mappings[`${reactNativePath}/React/FBReactNativeSpec`] = {
destination: headersOutput,
excludeFolders: ['tests'],
preserveStructure: true,
};
return mappings;
}
function librariesMappings(
reactNativePath /*: string */,
headersOutput /*: string */,
) /*: { [string]: MappingOption } */ {
let mappings /*: { [string]: MappingOption } */ = {};
mappings[`${reactNativePath}/Libraries`] = {
destination: path.join(headersOutput, 'React'),
excludeFolders: ['tests'],
preserveStructure: false,
};
mappings[`${reactNativePath}/Libraries/FBLazyVector`] = {
destination: path.join(headersOutput, 'FBLazyVector'),
excludeFolders: ['tests'],
preserveStructure: false,
};
mappings[`${reactNativePath}/Libraries/Required`] = {
destination: path.join(headersOutput, 'RCTRequired'),
excludeFolders: ['tests'],
preserveStructure: false,
};
mappings[`${reactNativePath}/Libraries/TypeSafety`] = {
destination: path.join(headersOutput, 'RCTTypeSafety'),
excludeFolders: ['tests'],
preserveStructure: false,
};
return mappings;
}
module.exports = {
librariesMappings,
reactCommonMappings,
reactMappings,
};