Skip to content

Conversation

RSNara
Copy link
Contributor

@RSNara RSNara commented Mar 10, 2025

Summary:
This diff introduces annotations into the ios codegen config!

Before

In the new architecture, people can declare module/component codegen config in package.json

This config contains the following maps:

  • modulesConformingToProtocol
  • modulesProvider
  • componentProvider
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modulesConformingToProtocol": {
        "RCTImageURLLoader": [
          "RCTHelloWorldImageURLLoader"
        ],
        "RCTURLRequestHandler": [
          "RCTHelloWorldURLRequestHandler"
        ],
        "RCTImageDataDecoder": [
          "RCTHelloWorldImageDataDecoder"
        ]
      },
      "modulesProvider": {
        "HelloWorldImageURLLoader": "RCTHelloWorldImageURLLoader",
        "HelloWorldURLRequestHandler": "RCTHelloWorldURLRequestHandler",
        "HelloWorldImageDataDecoder": "RCTHelloWorldImageDataDecoder"
      },
      "componentProvider": {
        "FooComponent": "RCTFooComponentClass"
      }
    }

After

This information is a little bit easier to understand if we group it by module/component (into annotations):

(that's what this diff does!)

"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modules": {
        "HelloWorldImageURLLoader": {
          "conformsToProtocols": ["RCTImageURLLoader"],
          "className": "RCTHelloWorldImageURLLoader"
        },
        "HelloWorldURLRequestHandler": {
          "conformsToProtocols": ["RCTURLRequestHandler"],
          "className": "RCTHelloWorldURLRequestHandler"
        },
        "HelloWorldImageDataDecoder": {
          "conformsToProtocols": ["RCTImageDataDecoder"],
          "className": "RCTHelloWorldImageDataDecoder"
        }
      },
      "components": {
        "FooComponent": {
          "className": "RCTFooComponent"
        }
      },
    }

Migration

The old way is still supported (for now). We will deprecate it soon, and eventually remove it from react native!

Changelog: [iOS][Added] - Codegen: Introduce module/component annotations inside package.json

Differential Revision: D70822061

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Mar 10, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

@RSNara RSNara force-pushed the export-D70822061 branch from c9dc67f to 60f8dfd Compare March 10, 2025 23:12
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

@RSNara RSNara force-pushed the export-D70822061 branch from 60f8dfd to 039a6f7 Compare March 10, 2025 23:52
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 11, 2025
…nents (facebook#49941)

Summary:
Pull Request resolved: facebook#49941

This diff introduces annotations into the ios codegen config!

## Before
In the new architecture, people can declare module/component codegen config in [package.json](https://reactnative.dev/docs/the-new-architecture/using-codegen#configuring-codegen)

This config contains the following maps:
- modulesConformingToProtocol
- modulesProvider
- componentProvider

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modulesConformingToProtocol": {
        "RCTImageURLLoader": [
          "RCTHelloWorldImageURLLoader"
        ],
        "RCTURLRequestHandler": [
          "RCTHelloWorldURLRequestHandler"
        ],
        "RCTImageDataDecoder": [
          "RCTHelloWorldImageDataDecoder"
        ]
      },
      "modulesProvider": {
        "HelloWorldImageURLLoader": "RCTHelloWorldImageURLLoader",
        "HelloWorldURLRequestHandler": "RCTHelloWorldURLRequestHandler",
        "HelloWorldImageDataDecoder": "RCTHelloWorldImageDataDecoder"
      },
      "componentProvider": {
        "FooComponent": "RCTFooComponentClass"
      }
    }

```

## After
This information is a little bit easier to understand if we group it by module/component (into **annotations**):

(that's what this diff does!)

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modules": {
        "HelloWorldImageURLLoader": {
          "conformsToProtocols": ["RCTImageURLLoader"],
          "className": "RCTHelloWorldImageURLLoader"
        },
        "HelloWorldURLRequestHandler": {
          "conformsToProtocols": ["RCTURLRequestHandler"],
          "className": "RCTHelloWorldURLRequestHandler"
        },
        "HelloWorldImageDataDecoder": {
          "conformsToProtocols": ["RCTImageDataDecoder"],
          "className": "RCTHelloWorldImageDataDecoder"
        }
      },
      "components": {
        "FooComponent": {
          "className": "RCTFooComponent"
        }
      },
    }

```

## Migration
The old way is still supported (for now). We will deprecate it soon, and eventually remove it from react native!

Changelog: [iOS][Added] - Codegen: Introduce module/component annotations inside package.json

Differential Revision: D70822061
@RSNara RSNara force-pushed the export-D70822061 branch from 039a6f7 to 6670122 Compare March 11, 2025 00:06
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

@RSNara RSNara force-pushed the export-D70822061 branch from 6670122 to a837c9c Compare March 11, 2025 20:37
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 11, 2025
…nents (facebook#49941)

Summary:
Pull Request resolved: facebook#49941

This diff introduces annotations into the ios codegen config!

## Before
In the new architecture, people can declare module/component codegen config in [package.json](https://reactnative.dev/docs/the-new-architecture/using-codegen#configuring-codegen)

This config contains the following maps:
- modulesConformingToProtocol
- modulesProvider
- componentProvider

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modulesConformingToProtocol": {
        "RCTImageURLLoader": [
          "RCTHelloWorldImageURLLoader"
        ],
        "RCTURLRequestHandler": [
          "RCTHelloWorldURLRequestHandler"
        ],
        "RCTImageDataDecoder": [
          "RCTHelloWorldImageDataDecoder"
        ]
      },
      "modulesProvider": {
        "HelloWorldImageURLLoader": "RCTHelloWorldImageURLLoader",
        "HelloWorldURLRequestHandler": "RCTHelloWorldURLRequestHandler",
        "HelloWorldImageDataDecoder": "RCTHelloWorldImageDataDecoder"
      },
      "componentProvider": {
        "FooComponent": "RCTFooComponentClass"
      }
    }

```

## After
This information is a little bit easier to understand if we group it by module/component (into **annotations**):

(that's what this diff does!)

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modules": {
        "HelloWorldImageURLLoader": {
          "conformsToProtocols": ["RCTImageURLLoader"],
          "className": "RCTHelloWorldImageURLLoader"
        },
        "HelloWorldURLRequestHandler": {
          "conformsToProtocols": ["RCTURLRequestHandler"],
          "className": "RCTHelloWorldURLRequestHandler"
        },
        "HelloWorldImageDataDecoder": {
          "conformsToProtocols": ["RCTImageDataDecoder"],
          "className": "RCTHelloWorldImageDataDecoder"
        }
      },
      "components": {
        "FooComponent": {
          "className": "RCTFooComponent"
        }
      },
    }

```

## Migration
The old way is still supported (for now). We will deprecate it soon, and eventually remove it from react native!

Changelog: [iOS][Added] - Codegen: Introduce module/component annotations inside package.json

Reviewed By: mdvacca

Differential Revision: D70822061
@RSNara RSNara force-pushed the export-D70822061 branch from a837c9c to bbb7154 Compare March 11, 2025 20:57
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

@RSNara RSNara force-pushed the export-D70822061 branch from bbb7154 to 3ed8a57 Compare March 12, 2025 18:01
RSNara added 3 commits March 12, 2025 13:32
Summary:
This will just make sure that we don't unintentionally break this script.

Changelog: [Internal]

Differential Revision: D70919549
…9905)

Summary:
Pull Request resolved: facebook#49905

This diff breaks down generate-artifacts-executor into smaller files.

Changelog: [Internal]

Differential Revision: D70795042

Reviewed By: alanleedev
…nents

Summary:
This diff introduces annotations into the ios codegen config!

## Before
In the new architecture, people can declare module/component codegen config in [package.json](https://reactnative.dev/docs/the-new-architecture/using-codegen#configuring-codegen)

This config contains the following maps:
- modulesConformingToProtocol
- modulesProvider
- componentProvider

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modulesConformingToProtocol": {
        "RCTImageURLLoader": [
          "RCTHelloWorldImageURLLoader"
        ],
        "RCTURLRequestHandler": [
          "RCTHelloWorldURLRequestHandler"
        ],
        "RCTImageDataDecoder": [
          "RCTHelloWorldImageDataDecoder"
        ]
      },
      "modulesProvider": {
        "HelloWorldImageURLLoader": "RCTHelloWorldImageURLLoader",
        "HelloWorldURLRequestHandler": "RCTHelloWorldURLRequestHandler",
        "HelloWorldImageDataDecoder": "RCTHelloWorldImageDataDecoder"
      },
      "componentProvider": {
        "FooComponent": "RCTFooComponentClass"
      }
    }

```

## After
This information is a little bit easier to understand if we group it by module/component (into **annotations**):

(that's what this diff does!)

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modules": {
        "HelloWorldImageURLLoader": {
          "conformsToProtocols": ["RCTImageURLLoader"],
          "className": "RCTHelloWorldImageURLLoader"
        },
        "HelloWorldURLRequestHandler": {
          "conformsToProtocols": ["RCTURLRequestHandler"],
          "className": "RCTHelloWorldURLRequestHandler"
        },
        "HelloWorldImageDataDecoder": {
          "conformsToProtocols": ["RCTImageDataDecoder"],
          "className": "RCTHelloWorldImageDataDecoder"
        }
      },
      "components": {
        "FooComponent": {
          "className": "RCTFooComponent"
        }
      },
    }

```

## Migration
The old way is still supported (for now). We will deprecate it soon, and eventually remove it from react native!

Changelog: [iOS][Added] - Codegen: Introduce module/component annotations inside package.json

Reviewed By: mdvacca

Differential Revision: D70822061
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70822061

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 76436d3.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 12, 2025
facebook-github-bot pushed a commit that referenced this pull request Jun 9, 2025
Summary:
Hey, I'm bumping `react-native-screens` to 0.80.0-rc.4 right now & noticed that codegen does not work as expected. It crawls whole library, file by file (when working on a library it also includes nodemodules etc), despite `componentProvider` field being defined in `codegenConfig` in `package.json`.

Namely #49941 introduced a regression for libraries that stick to the old codegen config format due to compatibility reasons. Take a look at [this code](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L60-L103). We first do a pass for "old API", [removing libraries with `componentProvider` in their codegen config from `librariesToCrawl`](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L66-L75), just to later [add **ALL** libraries](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L86-L89) that do not support new codegen config format back again to `librariesToCrawl`.

This PR improves the filtering condition, to parse codegen annotations only for libraries that have defined any of the fields from the new config format (opted in for new system).

I want to emphasise that this is a significant regression, because it ruins experience of library maintenance, vastly increasing pods installation time.

## Changelog:

[IOS] [FIXED] - Fix codegen crawling all library code with `componentProvider` defined in config

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #51867

Test Plan:
1. Setup an application with any third party library, that uses "old" codegen config format, e.g. `react-native-screens@4.11.1`
2. `cd ios && bundle exec pod install`
3. Observe the codegen logs - it crawles the library instead of using provided information.

Reviewed By: cortinico

Differential Revision: D76126649

Pulled By: cipolleschi

fbshipit-source-id: 6f9c9dffcdca7204a78b4b55db10249240146141
react-native-bot pushed a commit that referenced this pull request Jun 9, 2025
Summary:
Hey, I'm bumping `react-native-screens` to 0.80.0-rc.4 right now & noticed that codegen does not work as expected. It crawls whole library, file by file (when working on a library it also includes nodemodules etc), despite `componentProvider` field being defined in `codegenConfig` in `package.json`.

Namely #49941 introduced a regression for libraries that stick to the old codegen config format due to compatibility reasons. Take a look at [this code](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L60-L103). We first do a pass for "old API", [removing libraries with `componentProvider` in their codegen config from `librariesToCrawl`](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L66-L75), just to later [add **ALL** libraries](https://github.com/facebook/react-native/blob/78caa07ff867255724e4b0ce3557ff5793b6ce1b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js#L86-L89) that do not support new codegen config format back again to `librariesToCrawl`.

This PR improves the filtering condition, to parse codegen annotations only for libraries that have defined any of the fields from the new config format (opted in for new system).

I want to emphasise that this is a significant regression, because it ruins experience of library maintenance, vastly increasing pods installation time.

## Changelog:

[IOS] [FIXED] - Fix codegen crawling all library code with `componentProvider` defined in config

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #51867

Test Plan:
1. Setup an application with any third party library, that uses "old" codegen config format, e.g. `react-native-screens@4.11.1`
2. `cd ios && bundle exec pod install`
3. Observe the codegen logs - it crawles the library instead of using provided information.

Reviewed By: cortinico

Differential Revision: D76126649

Pulled By: cipolleschi

fbshipit-source-id: 6f9c9dffcdca7204a78b4b55db10249240146141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants