Skip to content

Commit

Permalink
Change to Majority rule
Browse files Browse the repository at this point in the history
  • Loading branch information
einbergisak committed Sep 3, 2024
1 parent ca51b4e commit 0552047
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/backoffice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"typescript": "^5.5.3",
"typescript": "^3.8.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
}
Expand Down
39 changes: 29 additions & 10 deletions verify_dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ for (const file of packageJsonFiles) {
devDependencyDictionary[file].push(`${name}@${version}`);
}
}
const versionDicitonary = compileVersionDictionary({
const versionDictionary = compileVersionDictionary({
...dependencyDictionary,
...devDependencyDictionary,
});
const faultReport = getFaultReport(versionDicitonary);
const faultReport = getFaultReport(versionDictionary);
if (Object.keys(faultReport).length > 0) {
console.error('Dependency version mismatch found in the following projects:');
console.error('The following dependency inconsistencies were found:');
console.error(faultReport);
process.exit(1);
}
Expand Down Expand Up @@ -95,22 +95,41 @@ function getFaultReport(versionDictionary: VersionDictionary) {
const faultReport: FaultReport = {};

for (const [library, versions] of Object.entries(versionDictionary)) {
const versionKeys = Object.keys(versions);
const sortedVersions = versionKeys.toSorted(compareSemVer);
for (const version of sortedVersions.slice(1)) {
for (const project of versions[version]) {

const versionOccurrencesSorted = Object.entries(versions)
.toSorted(([version, projects]) => projects.length)





// Invariant: versionOccurrences.length > 1, as we have already filtered out deps with only one version.
if (versionOccurrencesSorted[0][1].length == versionOccurrencesSorted[1][1].length) {
// Warn if there is no majority // TODO: majority == most occurences or > 50%?
const occurencesString = Object.entries(versions).flatMap((_, projects) => projects).join("\n - ")
faultReport[library]["throughout project"] = `There is no majority version for library ${library}. It occurs in the following projects:\n${occurencesString}`;

continue
}

// There is a majority
const majorityVersion = versionOccurrencesSorted[0][0]
for (const [version, projects] of versionOccurrencesSorted.splice(1)) {
for (const project of projects) {
if (faultReport[project] === undefined) {
faultReport[project] = {};
}

faultReport[project][
library
] = `Has version ${version} but should be ${sortedVersions[0]}`;
faultReport[project][library] = `Has version ${version} but majority version throughout monorepo is ${majorityVersion}`;
}
}

}
return faultReport;
}
// faultReport[project][
// library
// ] = `Has version ${version} but should be ${sortedVersions[0]}`;

function splitVersion(dependency: string) {
const splits = dependency.split('@');
Expand Down

0 comments on commit 0552047

Please sign in to comment.