* Compute the structural diff between two .deepnote files.
( path1: string, path2: string, file1: DeepnoteFile, file2: DeepnoteFile, options: DiffOptions )
| 113 | * Compute the structural diff between two .deepnote files. |
| 114 | */ |
| 115 | function computeDiff( |
| 116 | path1: string, |
| 117 | path2: string, |
| 118 | file1: DeepnoteFile, |
| 119 | file2: DeepnoteFile, |
| 120 | options: DiffOptions |
| 121 | ): DiffResult { |
| 122 | const notebooks1 = new Map(file1.project.notebooks.map(nb => [nb.id, nb])) |
| 123 | const notebooks2 = new Map(file2.project.notebooks.map(nb => [nb.id, nb])) |
| 124 | |
| 125 | const notebookDiffs: NotebookDiff[] = [] |
| 126 | const summary = { |
| 127 | notebooksAdded: 0, |
| 128 | notebooksRemoved: 0, |
| 129 | notebooksModified: 0, |
| 130 | notebooksUnchanged: 0, |
| 131 | blocksAdded: 0, |
| 132 | blocksRemoved: 0, |
| 133 | blocksModified: 0, |
| 134 | blocksUnchanged: 0, |
| 135 | } |
| 136 | |
| 137 | // Find removed and modified notebooks |
| 138 | for (const [id, nb1] of notebooks1) { |
| 139 | const nb2 = notebooks2.get(id) |
| 140 | if (!nb2) { |
| 141 | // Notebook removed |
| 142 | notebookDiffs.push({ |
| 143 | name: nb1.name, |
| 144 | id, |
| 145 | status: 'removed', |
| 146 | blockCount: nb1.blocks.length, |
| 147 | }) |
| 148 | summary.notebooksRemoved++ |
| 149 | summary.blocksRemoved += nb1.blocks.length |
| 150 | } else { |
| 151 | // Notebook exists in both - compare blocks and name |
| 152 | const blockDiffs = computeBlockDiffs(nb1.blocks, nb2.blocks, options) |
| 153 | const hasBlockChanges = blockDiffs.some(bd => bd.status !== 'unchanged') |
| 154 | const wasRenamed = nb1.name !== nb2.name |
| 155 | const hasChanges = hasBlockChanges || wasRenamed |
| 156 | |
| 157 | if (hasChanges) { |
| 158 | notebookDiffs.push({ |
| 159 | name: nb2.name, |
| 160 | ...(wasRenamed && { oldName: nb1.name }), |
| 161 | id, |
| 162 | status: 'modified', |
| 163 | blockDiffs: blockDiffs.filter(bd => bd.status !== 'unchanged'), |
| 164 | }) |
| 165 | summary.notebooksModified++ |
| 166 | } else { |
| 167 | notebookDiffs.push({ |
| 168 | name: nb2.name, |
| 169 | id, |
| 170 | status: 'unchanged', |
| 171 | }) |
| 172 | summary.notebooksUnchanged++ |
no test coverage detected