diff --git a/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.test.ts b/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.test.ts index 90290d563..2d8f141c3 100644 --- a/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.test.ts +++ b/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.test.ts @@ -23,12 +23,12 @@ const mockReport: Report = { success: console.log, }; -const mockJavaSpec = ` +const mockJavaModuleSpec = ` /** * Some comment */ -package com.bobtest; +package com.facebook.fbreact.specs; import com.example.exampleimport; @@ -38,11 +38,27 @@ class SomeClass { } }`; +const mockJavaViewSpec = ` +/** + * Some comment + */ + +package com.facebook.react.viewmanagers; + +public interface SomeInterface { + void setColor(T view, @Nullable String value); +} +`; + const mockProjectPath = path.resolve(__dirname, 'mockProject'); -const mockCodegenSpecsPath = path.resolve( +const mockCodegenModuleSpecsPath = path.resolve( mockProjectPath, 'android/generated/java/com/facebook/fbreact/specs' ); +const mockCodegenViewSpecsPath = path.resolve( + mockProjectPath, + 'android/generated/java/com/facebook/react/viewmanagers' +); describe('patchCodegenAndroidPackage', () => { beforeEach(() => { @@ -50,8 +66,8 @@ describe('patchCodegenAndroidPackage', () => { [mockProjectPath]: { 'package.json': JSON.stringify(mockPackageJson), }, - [mockCodegenSpecsPath]: { - 'NativeBobtestSpec.java': mockJavaSpec, + [mockCodegenModuleSpecsPath]: { + 'NativeBobtestSpec.java': mockJavaModuleSpec, }, }); }); @@ -101,6 +117,40 @@ describe('patchCodegenAndroidPackage', () => { mockReport ); - expect(await fs.pathExists(mockCodegenSpecsPath)).toBe(false); + expect(await fs.pathExists(mockCodegenModuleSpecsPath)).toBe(false); + }); + + it("doesn't delete the view manager specs", async () => { + const mockPackageJsonWithTypeAll = { + ...mockPackageJson, + codegenConfig: { + ...mockPackageJson.codegenConfig, + type: 'all', + }, + }; + + mockfs({ + [mockProjectPath]: { + 'package.json': JSON.stringify(mockPackageJsonWithTypeAll), + }, + [mockCodegenModuleSpecsPath]: { + 'NativeBobtestSpec.java': mockJavaModuleSpec, + }, + [mockCodegenViewSpecsPath]: { + 'BobtestViewManagerInterface.java': mockJavaViewSpec, + }, + }); + + await patchCodegenAndroidPackage( + mockProjectPath, + mockPackageJsonWithTypeAll, + mockReport + ); + + expect( + await fs.pathExists( + path.join(mockCodegenViewSpecsPath, 'BobtestViewManagerInterface.java') + ) + ).toBeTruthy(); }); }); diff --git a/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.ts b/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.ts index 9ba2fcadf..5b0fbd970 100644 --- a/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.ts +++ b/packages/react-native-builder-bob/src/targets/codegen/patches/patchCodegenAndroidPackage.ts @@ -30,7 +30,7 @@ export async function patchCodegenAndroidPackage( if (!(await fs.pathExists(codegenAndroidPath))) { throw new Error( - `The codegen android path defined in your package.json: ${codegenAndroidPath} doesnt' exist.` + `The codegen android path defined in your package.json: ${codegenAndroidPath} doesn't exist.` ); } @@ -89,7 +89,19 @@ export async function patchCodegenAndroidPackage( }) ); - await fs.rm(path.resolve(codegenAndroidPath, 'java/com/facebook'), { - recursive: true, - }); + if ( + await fs.pathExists( + path.resolve(codegenAndroidPath, 'java/com/facebook/react/viewmanagers') + ) + ) { + // Keep the view managers + await fs.rm(path.resolve(codegenAndroidPath, 'java/com/facebook/fbreact'), { + recursive: true, + }); + } else { + // Delete the entire facebook namespace + await fs.rm(path.resolve(codegenAndroidPath, 'java/com/facebook'), { + recursive: true, + }); + } }