fix: reformat RCTLegacyInteropComponents (#41908)

Summary:
When Codegen generates interop components it reformats `RCTLegacyInteropComponents.mm` to have each component in a new line. This creates this unnecessary diff every time I run `pod install`. This PR aims to commit a formatted version of the codegen-generated file to avoid creating this diff every time. Here is a reference of Codegen function generating this: 44d6e4310c/packages/react-native/scripts/codegen/generate-legacy-interop-components.js (L53)

![CleanShot 2023-12-12 at 14 09 34@2x](https://github.com/facebook/react-native/assets/52801365/2d5454d0-3bcb-484c-aa45-b5286c3ac5ba)

## Changelog:

[INTERNAL] [CHANGED] - Reformat `RCTLegacyInteropComponents` to follow Codegen generated formatting

Pull Request resolved: https://github.com/facebook/react-native/pull/41908

Test Plan: CI Green

Reviewed By: cipolleschi

Differential Revision: D52077611

Pulled By: cortinico

fbshipit-source-id: 12fbbfacc7e73147a988d321c8bc771acaaad8bb
This commit is contained in:
Oskar Kwaśniewski 2023-12-13 09:43:14 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 5a600e60d9
Коммит d5b1c71b3f
1 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@ -18,6 +18,7 @@ const PROJECT_FIELD = 'project';
const IOS_FIELD = 'ios';
const LEGACY_COMPONENTS_FIELD = 'unstable_reactLegacyComponentNames';
const OUTPUT_FILE_NAME = 'RCTLegacyInteropComponents.mm';
const MAX_CHARS_IN_ONE_LINE = 80;
const argv = yargs
.option('p', {
@ -34,7 +35,14 @@ const argv = yargs
const appRoot = argv.path;
const outputPath = argv.outputPath;
function fileBody(components) {
function fileBody(components, isOneLine) {
// Generate components array string with proper formatting
const componentsString = components.join(isOneLine ? '' : '\n');
const componentsArray = isOneLine
? `@[${componentsString} ];`
: `@[
${componentsString}
];`;
// eslint-disable duplicate-license-header
return `/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
@ -49,9 +57,7 @@ function fileBody(components) {
+ (NSArray<NSString *> *)legacyInteropComponents
{
return @[
${components}
];
return ${componentsArray}
}
@end
@ -112,7 +118,10 @@ function generateRCTLegacyInteropComponents() {
return;
}
console.log(`Components found: ${componentNames}`);
let componentsArray = componentNames.map(name => `\t\t\t@"${name}",`);
const isOneLine = componentNames.join().length < MAX_CHARS_IN_ONE_LINE;
let componentsArray = componentNames.map(
(name, index) => `${isOneLine ? ' ' : '\t\t\t'}@"${name}",`,
);
// Remove the last comma
if (componentsArray.length > 0) {
componentsArray[componentsArray.length - 1] = componentsArray[
@ -121,7 +130,7 @@ function generateRCTLegacyInteropComponents() {
}
const filePath = `${outputPath}/${OUTPUT_FILE_NAME}`;
fs.writeFileSync(filePath, fileBody(componentsArray.join('\n')));
fs.writeFileSync(filePath, fileBody(componentsArray, isOneLine));
console.log(`${filePath} updated!`);
}