Skip to content

Commit

Permalink
fix(android): findComponentDescriptors should look in codegenConfig?.…
Browse files Browse the repository at this point in the history
…jsSrcsDir only and it should look into components starging with Native or ending with NativeComponent
  • Loading branch information
mfazekas committed Jul 14, 2024
1 parent d6982fc commit 7e7f9d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('android::getDependencyConfig', () => {
fs.__setMockFilesystem({
empty: {},
nested: {
'package.json': JSON.stringify({codegenConfig: {jsSrcsDir: 'src'}}),
android: {
app: mocks.valid,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ import {extractComponentDescriptors} from './extractComponentDescriptors';
import {unixifyPaths} from '@react-native-community/cli-tools';

export function findComponentDescriptors(packageRoot: string) {
const files = glob.sync('**/+(*.js|*.jsx|*.ts|*.tsx)', {
cwd: unixifyPaths(packageRoot),
onlyFiles: true,
ignore: ['**/node_modules/**'],
});
let pjson: {codegenConfig?: {jsSrcsDir?: string}} = JSON.parse(
fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'),
);
const jsSrcsDir = pjson?.codegenConfig?.jsSrcsDir;
if (jsSrcsDir === undefined) {
return [];
}

const jsSrcsRoot = path.join(packageRoot, jsSrcsDir);

const files = glob.sync(
'**/(Native*|*NativeComponent)(.android|)(.js|.jsx|.ts|.tsx)',
{
cwd: unixifyPaths(jsSrcsRoot),
onlyFiles: true,
ignore: ['**/node_modules/**'],
},
);
const codegenComponent = files
.map((filePath) =>
fs.readFileSync(path.join(packageRoot, filePath), 'utf8'),
)
.map((filePath) => fs.readFileSync(path.join(jsSrcsRoot, filePath), 'utf8'))
.map(extractComponentDescriptors)
.filter(Boolean);

Expand Down

0 comments on commit 7e7f9d3

Please sign in to comment.