Skip to content

Commit

Permalink
Skip hidden folders when looking for third party components (facebook…
Browse files Browse the repository at this point in the history
…#48182)

Summary:
Pull Request resolved: facebook#48182

Maintainers from SVG reached out because of an edge case they inencountered when generating the ComponentProvider. In their setup, they had a `.git` folder in the repo and the algorithm was spending a lot of time crawling the git folder.

In general, we should avoid crawling hidden folders.

This change fix that.

## Changelog:
[General][Fixed] - Skip hidden folders when looking for third party components.

Reviewed By: javache

Differential Revision: D66959345

fbshipit-source-id: 992a79f3cff22cd6a459e0272c8140bc329888da
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Dec 10, 2024
1 parent 538fa01 commit 8ab5243
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,16 @@ function findFilesWithExtension(filePath, extension) {
const dir = fs.readdirSync(filePath);
dir.forEach(file => {
const absolutePath = path.join(filePath, file);
// Exclude files provided by react-native
if (absolutePath.includes(`${path.sep}react-native${path.sep}`)) {
return null;
}

// Skip hidden folders, that starts with `.`
if (absolutePath.includes(`${path.sep}.`)) {
return null;
}

if (
fs.existsSync(absolutePath) &&
fs.statSync(absolutePath).isDirectory()
Expand All @@ -778,11 +788,6 @@ function findFilesWithExtension(filePath, extension) {
// Given a filepath, read the file and look for a string that starts with 'Class<RCTComponentViewProtocol> '
// and ends with 'Cls(void)'. Return the string between the two.
function findRCTComponentViewProtocolClass(filepath) {
// Exclude files provided by react-native
if (filepath.includes(`${path.sep}react-native${path.sep}`)) {
return null;
}

const fileContent = fs.readFileSync(filepath, 'utf8');
const regex = /Class<RCTComponentViewProtocol> (.*)Cls\(/;
const match = fileContent.match(regex);
Expand Down

0 comments on commit 8ab5243

Please sign in to comment.