mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-27 04:49:43 +08:00
fix: a minified or bundled script is generated, and generated files are not hubs (#2122)
Found by the README-wide sweep: vendored bundles topped "most depended on"
across many repos — delphimvcframework's bundled `Buffer` (6,162) and four
`n`s (2,386 each), retrofit's docs `main.js` `t`/`e`/`i`, TestBox's
`__webpack_require__` — because only `*.min.js` was recognized as generated.
- detectGeneratedFile (index time, persisted as files.generated) now also
flags a .js/.mjs/.cjs file whose text is mostly lines of 1,000+ chars AND
whose long lines are code (≥3% `;{}(),`) — not an ordinary file carrying
one long base64 string — and any file that defines webpack's
`__webpack_require__` loader, however readable its lines. The path rule
also matches `-min.js` (underscore-min.js).
- Entry points' hubs skip nodes in generated files, as they skip tests.
Scanned every .js file of express, axios, lodash, excalidraw, typeorm, zod,
trpc, hono, bulletproof-react: zero new flags on hand-written code; newly
caught: lodash vendor/underscore/underscore-min.js, retrofit website
main.js (754 KB) + prism.js, TestBox syntaxhighlighter.js (webpack).
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e453e820a8
commit
068c422e1d
@@ -396,15 +396,18 @@ function testFiles(cg: CodeGraph, limit: number): WireList<WireEntryTest> {
|
||||
return wireList(items, Math.max(ranked.length, items.length));
|
||||
}
|
||||
|
||||
/** The most depended-on symbols, tests and non-navigable kinds removed. */
|
||||
/** The most depended-on symbols, tests, generated files and non-navigable kinds removed. */
|
||||
function hubs(cg: CodeGraph, limit: number): WireList<WireEntryHub> {
|
||||
const ranked = cg.getTopDependedOn(SCAN_ROWS);
|
||||
const ranked = cg
|
||||
.getTopDependedOn(SCAN_ROWS)
|
||||
.map((row) => ({ row, node: cg.getNode(row.nodeId) }));
|
||||
// A vendored bundle's one-letter functions are depended on by the bundle alone.
|
||||
const generated = cg.generatedFilePredicate(ranked.flatMap(({ node }) => (node ? [node.filePath] : [])));
|
||||
|
||||
const items: WireEntryHub[] = [];
|
||||
let eligible = 0;
|
||||
for (const row of ranked) {
|
||||
const node = cg.getNode(row.nodeId);
|
||||
if (!node || NON_HUB_KINDS.has(node.kind) || isTestFile(node.filePath)) continue;
|
||||
for (const { row, node } of ranked) {
|
||||
if (!node || NON_HUB_KINDS.has(node.kind) || isTestFile(node.filePath) || generated(node.filePath)) continue;
|
||||
eligible += 1;
|
||||
if (items.length >= limit) continue;
|
||||
items.push({ ...toNodeRef(node), dependents: row.dependents });
|
||||
|
||||
Reference in New Issue
Block a user