(file: DiffFileName)
| 143 | * returns "my/path/{to → for}/file.js" |
| 144 | */ |
| 145 | export function filenameDiff(file: DiffFileName): string { |
| 146 | // TODO: Move unify path to parsing |
| 147 | const oldFilename = unifyPath(file.oldName); |
| 148 | const newFilename = unifyPath(file.newName); |
| 149 | |
| 150 | if (oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) { |
| 151 | const prefixPaths = []; |
| 152 | const suffixPaths = []; |
| 153 | |
| 154 | const oldFilenameParts = oldFilename.split(separator); |
| 155 | const newFilenameParts = newFilename.split(separator); |
| 156 | |
| 157 | const oldFilenamePartsSize = oldFilenameParts.length; |
| 158 | const newFilenamePartsSize = newFilenameParts.length; |
| 159 | |
| 160 | let i = 0; |
| 161 | let j = oldFilenamePartsSize - 1; |
| 162 | let k = newFilenamePartsSize - 1; |
| 163 | |
| 164 | while (i < j && i < k) { |
| 165 | if (oldFilenameParts[i] === newFilenameParts[i]) { |
| 166 | prefixPaths.push(newFilenameParts[i]); |
| 167 | i += 1; |
| 168 | } else { |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | while (j > i && k > i) { |
| 174 | if (oldFilenameParts[j] === newFilenameParts[k]) { |
| 175 | suffixPaths.unshift(newFilenameParts[k]); |
| 176 | j -= 1; |
| 177 | k -= 1; |
| 178 | } else { |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | const finalPrefix = prefixPaths.join(separator); |
| 184 | const finalSuffix = suffixPaths.join(separator); |
| 185 | |
| 186 | const oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator); |
| 187 | const newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator); |
| 188 | |
| 189 | if (finalPrefix.length && finalSuffix.length) { |
| 190 | return ( |
| 191 | finalPrefix + separator + '{' + oldRemainingPath + ' → ' + newRemainingPath + '}' + separator + finalSuffix |
| 192 | ); |
| 193 | } else if (finalPrefix.length) { |
| 194 | return finalPrefix + separator + '{' + oldRemainingPath + ' → ' + newRemainingPath + '}'; |
| 195 | } else if (finalSuffix.length) { |
| 196 | return '{' + oldRemainingPath + ' → ' + newRemainingPath + '}' + separator + finalSuffix; |
| 197 | } |
| 198 | |
| 199 | return oldFilename + ' → ' + newFilename; |
| 200 | } else if (!isDevNullName(newFilename)) { |
| 201 | return newFilename; |
| 202 | } else { |
no test coverage detected
searching dependent graphs…