Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion __tests__/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { CodeGraph } from '../src';
import { extractFromSource, scanDirectory, buildDefaultIgnore, discoverEmbeddedRepoRoots, buildScopeIgnore } from '../src/extraction';
import { extractFromSource, scanDirectory, buildDefaultIgnore, discoverEmbeddedRepoRoots, buildScopeIgnore, getMaxFileSize } from '../src/extraction';
import { detectLanguage, isLanguageSupported, getSupportedLanguages, initGrammars, loadAllGrammars, isSourceFile } from '../src/extraction/grammars';
import { stripCppTemplateArgs, blankCppExportMacros, blankCppInlineMacros, blankMetalAttributes, blankCudaConstructs, blankCppAnnotationMacroCalls, blankCppApiPrefixMacros, blankCppInlineAnnotationMacros, recoverMangledCppName } from '../src/extraction/languages/c-cpp';
import { normalizePath } from '../src/utils';
Expand Down Expand Up @@ -10939,3 +10939,32 @@ import DataStore from '../data/DataStore';
});
});
});

describe('CODEGRAPH_MAX_FILE_SIZE env var (#1016)', () => {
const originalEnv = process.env.CODEGRAPH_MAX_FILE_SIZE;
afterEach(() => {
if (originalEnv === undefined) delete process.env.CODEGRAPH_MAX_FILE_SIZE;
else process.env.CODEGRAPH_MAX_FILE_SIZE = originalEnv;
});

it('returns 1 MB default when env var is not set', () => {
delete process.env.CODEGRAPH_MAX_FILE_SIZE;
expect(getMaxFileSize()).toBe(1024 * 1024);
});

it('returns custom value when env var is a valid positive integer', () => {
process.env.CODEGRAPH_MAX_FILE_SIZE = '5242880';
expect(getMaxFileSize()).toBe(5242880);
});

it('falls back to default for invalid values', () => {
process.env.CODEGRAPH_MAX_FILE_SIZE = 'notanumber';
expect(getMaxFileSize()).toBe(1024 * 1024);

process.env.CODEGRAPH_MAX_FILE_SIZE = '-1';
expect(getMaxFileSize()).toBe(1024 * 1024);

process.env.CODEGRAPH_MAX_FILE_SIZE = '0';
expect(getMaxFileSize()).toBe(1024 * 1024);
});
});
13 changes: 11 additions & 2 deletions src/extraction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,18 @@ export function hashContent(content: string): string {
/**
* Skip files larger than this (bytes). Generated bundles, minified JS, and
* vendored blobs blow the WASM heap and the worker-recycle budget for no useful
* symbols. 1 MB covers essentially all hand-written source.
* symbols. 1 MB covers essentially all hand-written source. Override via
* CODEGRAPH_MAX_FILE_SIZE (bytes) for projects with legitimate large source files.
*/
const MAX_FILE_SIZE = 1024 * 1024;
export function getMaxFileSize(): number {
const envVal = process.env.CODEGRAPH_MAX_FILE_SIZE;
if (envVal !== undefined) {
const parsed = parseInt(envVal, 10);
if (parsed > 0 && !isNaN(parsed)) return parsed;
}
return 1024 * 1024;
}
const MAX_FILE_SIZE = getMaxFileSize();

/**
* Directory names that are dependency, build, cache, or tooling output across the
Expand Down