Clean package.json & rebaseline snapshots (#328)
This commit is contained in:
@@ -135,8 +135,12 @@ async function readFileWithCache(filePath: string): Promise<string | null> {
|
||||
}
|
||||
|
||||
// Read file and update cache
|
||||
const content = await fsAsync.readFile(filePath, "utf-8");
|
||||
fileContentCache.set(filePath, { content, mtime: currentMtime });
|
||||
const rawContent = await fsAsync.readFile(filePath, "utf-8");
|
||||
const content = cleanContent({ content: rawContent, filePath });
|
||||
fileContentCache.set(filePath, {
|
||||
content,
|
||||
mtime: currentMtime,
|
||||
});
|
||||
|
||||
// Manage cache size by clearing oldest entries when it gets too large
|
||||
if (fileContentCache.size > MAX_FILE_CACHE_SIZE) {
|
||||
@@ -157,6 +161,32 @@ async function readFileWithCache(filePath: string): Promise<string | null> {
|
||||
}
|
||||
}
|
||||
|
||||
function cleanContent({
|
||||
content,
|
||||
filePath,
|
||||
}: {
|
||||
content: string;
|
||||
filePath: string;
|
||||
}): string {
|
||||
// Why are we cleaning package.json?
|
||||
// 1. It contains unnecessary information for LLM context
|
||||
// 2. Fields like packageManager cause diffs in e2e test snapshots.
|
||||
if (path.basename(filePath) === "package.json") {
|
||||
try {
|
||||
const { dependencies, devDependencies } = JSON.parse(content);
|
||||
const cleanPackageJson = {
|
||||
dependencies,
|
||||
devDependencies,
|
||||
};
|
||||
return JSON.stringify(cleanPackageJson, null, 2);
|
||||
} catch (error) {
|
||||
logger.error(`Error cleaning package.json: ${filePath}`, error);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively walk a directory and collect all relevant files
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user