(pair)
| 265 | |
| 266 | // bulk of the logic, read the api files, rebuild the interfaces, diff those reconstructions |
| 267 | function getDiff(pair) { |
| 268 | let name; |
| 269 | if (pair.branchApi) { |
| 270 | name = pair.branchApi.replace(/.*branch-api/, ''); |
| 271 | } else { |
| 272 | name = pair.pubApi.replace(/.*published-api/, ''); |
| 273 | } |
| 274 | |
| 275 | if (args.values.package && !args.values.package.includes(name)) { |
| 276 | return {diff: {}, name}; |
| 277 | } |
| 278 | if (args.values.verbose) { |
| 279 | console.log(`diffing ${name}`); |
| 280 | } |
| 281 | let publishedApi = pair.pubApi === null ? {exports: {}} : getAPI(pair.pubApi); |
| 282 | let branchApi = pair.branchApi === null ? {exports: {}} : getAPI(pair.branchApi); |
| 283 | let publishedInterfaces = rebuildInterfaces(publishedApi); |
| 284 | let branchInterfaces = rebuildInterfaces(branchApi); |
| 285 | let allExportNames = [ |
| 286 | ...new Set([...Object.keys(publishedApi.exports), ...Object.keys(branchApi.exports)]) |
| 287 | ]; |
| 288 | let allInterfaces = [ |
| 289 | ...new Set([...Object.keys(publishedInterfaces), ...Object.keys(branchInterfaces)]) |
| 290 | ]; |
| 291 | let formattedPublishedInterfaces = ''; |
| 292 | let formattedBranchInterfaces = ''; |
| 293 | formattedPublishedInterfaces = formatInterfaces(publishedInterfaces, allInterfaces); |
| 294 | formattedBranchInterfaces = formatInterfaces(branchInterfaces, allInterfaces); |
| 295 | |
| 296 | let diffs = []; |
| 297 | allInterfaces.forEach((iname, index) => { |
| 298 | if (args.values.interface && args.values.interface !== iname) { |
| 299 | return; |
| 300 | } |
| 301 | let simplifiedName = allExportNames[index]; |
| 302 | let codeDiff = Diff.structuredPatch( |
| 303 | iname, |
| 304 | iname, |
| 305 | formattedPublishedInterfaces[index], |
| 306 | formattedBranchInterfaces[index], |
| 307 | {newlineIsToken: true} |
| 308 | ); |
| 309 | if (args.values.verbose) { |
| 310 | console.log(util.inspect(codeDiff, {depth: null})); |
| 311 | } |
| 312 | let result = []; |
| 313 | let prevEnd = 1; // diff lines are 1 indexed |
| 314 | let lines = formattedPublishedInterfaces[index].split('\n'); |
| 315 | codeDiff.hunks.forEach(hunk => { |
| 316 | if (hunk.oldStart > prevEnd) { |
| 317 | result = [ |
| 318 | ...result, |
| 319 | ...lines.slice(prevEnd - 1, hunk.oldStart - 1).map((item, index) => ` ${item}`) |
| 320 | ]; |
| 321 | } |
| 322 | if (args.values.isCI) { |
| 323 | result = [...result, ...hunk.lines]; |
| 324 | } else { |
no test coverage detected