MCPcopy Index your code
hub / github.com/adobe/react-spectrum / getDiff

Function getDiff

scripts/compareAPIs.js:267–358  ·  view source on GitHub ↗
(pair)

Source from the content-addressed store, hash-verified

265
266// bulk of the logic, read the api files, rebuild the interfaces, diff those reconstructions
267function 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 {

Callers 1

compareFunction · 0.85

Calls 5

getAPIFunction · 0.85
rebuildInterfacesFunction · 0.85
formatInterfacesFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected