Skip to content

Instantly share code, notes, and snippets.

@artalar
Last active May 16, 2024 07:29
Show Gist options
  • Save artalar/42e9d86d57ed2b7a191385d3d5fc26d4 to your computer and use it in GitHub Desktop.
Save artalar/42e9d86d57ed2b7a191385d3d5fc26d4 to your computer and use it in GitHub Desktop.
GPT-4o inspects react compiler
npx cloc compiler
3668 text files.
2905 unique files.
767 files ignored.
github.com/AlDanial/cloc v 2.00 T=1.10 s (2642.9 files/s, 139378.2 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Markdown 1149 11504 2 50310
TypeScript 312 2806 6885 34998
Rust 54 870 1016 20469
JavaScript 1337 1705 1956 16982
JSON 30 6 0 3179
TOML 15 34 25 279
CSS 1 10 7 54
Bourne Shell 4 15 27 36
Text 2 0 0 24
SVG 1 0 0 4
-------------------------------------------------------------------------------
SUM: 2905 16950 9918 126335
-------------------------------------------------------------------------------
Total Count of Parsed Files: 332
Total Lines of Code in Parsed Files: 56890
Top 10 Files with Most Lines of Code:
#1: compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts - 4156 lines
#2: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts - 2317 lines
#3: compiler/packages/babel-plugin-react-compiler/src/Inference/InferReferenceEffects.ts - 2081 lines
#4: compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts - 1509 lines
#5: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts - 1479 lines
#6: compiler/crates/react_estree_codegen/src/ecmascript.json - 1367 lines
#7: compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts - 1143 lines
#8: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PropagateScopeDependencies.ts - 1038 lines
#9: compiler/packages/babel-plugin-react-compiler/scripts/eslint-plugin-react-hooks-test-cases.js - 986 lines
#10: compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts - 981 lines
const fs = require('fs');
const path = require('path');
const shouldSkipFile = filePath => {
const lowerCasePath = filePath.toLowerCase();
const baseName = path.basename(filePath).toLowerCase();
return (
lowerCasePath.endsWith('.wasm') ||
baseName.endsWith('.lock') ||
lowerCasePath.includes('snapshot') ||
lowerCasePath.includes('fixtures') ||
baseName.includes('generated')
);
};
const getFilesInDirectory = (dir, allFiles = []) => {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
allFiles = getFilesInDirectory(filePath, allFiles);
} else if (!shouldSkipFile(filePath)) {
allFiles.push(filePath);
}
});
return allFiles;
};
const countLines = (filePath) => {
const fileContent = fs.readFileSync(filePath, 'utf-8');
return fileContent.split('\n').length;
};
const getTopFilesByLines = (dir, topN = 10) => {
const allFiles = getFilesInDirectory(dir);
let totalLines = 0;
let totalFilesCount = allFiles.length;
const filesWithLineCount = allFiles.map(filePath => {
const lines = countLines(filePath);
totalLines += lines;
return { path: filePath, lines };
});
filesWithLineCount.sort((a, b) => b.lines - a.lines);
const topFiles = filesWithLineCount.slice(0, topN);
return { topFiles, totalLines, totalFilesCount };
};
const dirPath = process.argv[2];
if (!dirPath) {
console.error('Please provide a directory path');
process.exit(1);
}
const { topFiles, totalLines, totalFilesCount } = getTopFilesByLines(dirPath);
console.log(`Total Count of Parsed Files: ${totalFilesCount}`);
console.log(`Total Lines of Code in Parsed Files: ${totalLines}`);
console.log('Top 10 Files with Most Lines of Code:');
topFiles.forEach((file, index) => {
console.log(`#${index + 1}: ${file.path} - ${file.lines} lines`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment