Fix PackageList.java generation for dependencies with multiple package instances - #57877
Conversation
…e instances Summary: Dependencies that register more than one React package via react-native.config.js (e.g. react-native-appsflyer) supply a packageImportPath with multiple import statements and a packageInstance with multiple "new X()" expressions. The FQCN rewriting added in react#54736 only considered the FIRST import, so the 2nd+ package instances were emitted as bare class names with no import and the generated PackageList.java failed to compile ("cannot find symbol"). Extract the FQCN from every import line and rewrite every short class name in the package instance string with its FQCN. Single-instance behaviour is unchanged. Changelog: [ANDROID] [FIXED] - Autolink: qualify every package instance in the generated PackageList.java when a dependency registers multiple packages Test Plan: Added a GeneratePackageListTaskTest case with a dependency that registers two packages (two imports, two instances). It failed before the fix (the 2nd instance was emitted as a bare class name) and passes after. Full react-native-gradle-plugin suite: 216 tests, 0 failures. Co-Authored-By: Claude <noreply@anthropic.com>
|
Hi @SnowingFox! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
A dependency that registers multiple React packages via
react-native.config.js(e.g.react-native-appsflyer) fails to generate a compilingPackageList.java.PR #54736 introduced FQCN rewriting to avoid class-name collisions, but
extractFqcnFromImportusesRegex(...).find(), which only returns the first import match, and the code rewrites only that single short class name in the instance string. The 2nd+ package instances keep a bare short class name with no import, so the generatedPackageList.javadoes not compile:Fixes #55653
This change extracts the FQCN from every import line and rewrites every bare short class name in the package instance string with its FQCN. Behaviour for the single-package case is unchanged.
Changelog:
[ANDROID] [FIXED] - Autolink: qualify every package instance in the generated PackageList.java when a dependency registers multiple packages
Test Plan:
Added a
GeneratePackageListTaskTestcase with a dependency providing two imports and two package instances, asserting the generated string contains both FQCNs and no barenew <ShortName>()token.RED (before the fix) — the new test fails because the 2nd instance stays bare:
GREEN (after the fix):
Full
react-native-gradle-pluginsuite (./gradlew :react-native-gradle-plugin:test --max-workers=2): 216 tests, 0 failures, 0 errors — no regressions.