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

Function compare

scripts/compareAPIs.js:65–195  ·  view source on GitHub ↗

* This takes the json files generated by the buildBranchAPI and buildPublishedAPI and * reconstructs our interfaces and create a graph of all dependencies between interfaces. * From there, we diff the reconstructed interfaces and track all that have changes. * We use the graph to communicate what

()

Source from the content-addressed store, hash-verified

63 * as well as the local console.
64 */
65async function compare() {
66 let branchDir = args.values['branch-api-dir'] || path.join(__dirname, '..', 'dist', 'branch-api');
67 let publishedDir = args.values['base-api-dir'] || path.join(__dirname, '..', 'dist', 'base-api');
68 if (!(fs.existsSync(branchDir) && fs.existsSync(publishedDir))) {
69 console.log(
70 chalk.redBright(`you must have both a branchDir ${branchDir} and baseDir ${publishedDir}`)
71 );
72 return;
73 }
74
75 let branchAPIs = fg.sync(`${branchDir}/**/api.json`);
76 let publishedAPIs = fg.sync(`${publishedDir}/**/api.json`);
77 let pairs = [];
78
79 // find all matching pairs based on what's been published
80 for (let pubApi of publishedAPIs) {
81 let pubApiPath = pubApi.split(path.sep);
82 let pkgJson = readJsonSync(
83 path.join('/', ...pubApiPath.slice(0, pubApiPath.length - 2), 'package.json')
84 );
85 let name = pkgJson.name;
86 let sharedPath = path.join(name, 'dist', 'api.json');
87 let found = false;
88 for (let branchApi of branchAPIs) {
89 if (branchApi.includes(sharedPath)) {
90 found = true;
91 pairs.push({pubApi, branchApi});
92 break;
93 }
94 }
95 if (!found) {
96 pairs.push({pubApi, branchApi: null});
97 }
98 }
99
100 // don't care about private APIs, but we do care if we're about to publish a new one
101 for (let branchApi of branchAPIs) {
102 let branchApiPath = branchApi.split(path.sep);
103 let pkgJson = readJsonSync(
104 path.join('/', ...branchApiPath.slice(0, branchApiPath.length - 2), 'package.json')
105 );
106 let name = pkgJson.name;
107 let sharedPath = path.join(name, 'dist', 'api.json');
108 let found = false;
109 for (let pubApi of publishedAPIs) {
110 if (pubApi.includes(sharedPath)) {
111 found = true;
112 break;
113 }
114 }
115 let json = readJsonSync(path.join(branchApi, '..', '..', 'package.json'));
116 if (!found && !json.private) {
117 pairs.push({pubApi: null, branchApi});
118 }
119 }
120
121 let allDiffs = {};
122 for (let pair of pairs) {

Callers 1

compareAPIs.jsFile · 0.85

Calls 10

getDiffFunction · 0.85
invertDependenciesFunction · 0.85
followDependenciesFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.80
readJsonSyncFunction · 0.70
hasMethod · 0.65
addMethod · 0.65
filterMethod · 0.65

Tested by

no test coverage detected