Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,20 +38,36 @@ class SomeClass {
}
}`;

const mockJavaViewSpec = `
/**
* Some comment
*/

package com.facebook.react.viewmanagers;

public interface SomeInterface<T extends View> {
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(() => {
mockfs({
[mockProjectPath]: {
'package.json': JSON.stringify(mockPackageJson),
},
[mockCodegenSpecsPath]: {
'NativeBobtestSpec.java': mockJavaSpec,
[mockCodegenModuleSpecsPath]: {
'NativeBobtestSpec.java': mockJavaModuleSpec,
},
});
});
Expand Down Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
);
}

Expand Down Expand Up @@ -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,
});
}
}
Loading