From 8ab524312ab3bf1192b94ae6e30d296a85baa944 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 10 Dec 2024 02:32:10 -0800 Subject: [PATCH] Skip hidden folders when looking for third party components (#48182) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .../codegen/generate-artifacts-executor.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index 440b25c02a77ef..480bc8c5cce17c 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -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() @@ -778,11 +788,6 @@ function findFilesWithExtension(filePath, extension) { // Given a filepath, read the file and look for a string that starts with 'Class ' // 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 (.*)Cls\(/; const match = fileContent.match(regex);