MCPcopy Index your code
hub / github.com/stackblitz/bolt.new / computeFileModifications

Function computeFileModifications

app/utils/diff.ts:17–52  ·  view source on GitHub ↗
(files: FileMap, modifiedFiles: Map<string, string>)

Source from the content-addressed store, hash-verified

15type FileModifications = Record<string, ModifiedFile>;
16
17export function computeFileModifications(files: FileMap, modifiedFiles: Map<string, string>) {
18 const modifications: FileModifications = {};
19
20 let hasModifiedFiles = false;
21
22 for (const [filePath, originalContent] of modifiedFiles) {
23 const file = files[filePath];
24
25 if (file?.type !== 'file') {
26 continue;
27 }
28
29 const unifiedDiff = diffFiles(filePath, originalContent, file.content);
30
31 if (!unifiedDiff) {
32 // files are identical
33 continue;
34 }
35
36 hasModifiedFiles = true;
37
38 if (unifiedDiff.length > file.content.length) {
39 // if there are lots of changes we simply grab the current file content since it's smaller than the diff
40 modifications[filePath] = { type: 'file', content: file.content };
41 } else {
42 // otherwise we use the diff since it's smaller
43 modifications[filePath] = { type: 'diff', content: unifiedDiff };
44 }
45 }
46
47 if (!hasModifiedFiles) {
48 return undefined;
49 }
50
51 return modifications;
52}
53
54/**
55 * Computes a diff in the unified format. The only difference is that the header is omitted

Callers 1

getFileModificationsMethod · 0.90

Calls 1

diffFilesFunction · 0.85

Tested by

no test coverage detected