Skip to content

Commit

Permalink
chore(constraints): allow execeptions for dependency-range consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Oct 9, 2024
1 parent e0d921a commit d7c7bd1
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,35 @@ function expectControllerDependenciesListedAsPeerDependencies(
}
}

/**
* Filter out dependency ranges which are not to be considered in `expectConsistentDependenciesAndDevDependencies`.
*
* @param {string} dependencyIdent - The dependency being filtered for
* @param {Map<string, Dependency>} dependenciesByRange - Dependencies by range
* @returns {Map<string, Dependency>} The resulting map.
*/
function getInconsistentDependenciesAndDevDependencies(
dependencyIdent,
dependenciesByRange,
) {
const ALLOWED_INCONSISTENT_DEPENDENCIES = Object.entries({
// '@metamask/foo': ['^1.0.0'],
});
for (const [
allowedPackage,
ignoredRange,
] of ALLOWED_INCONSISTENT_DEPENDENCIES) {
if (allowedPackage === dependencyIdent) {
return new Map(
Object.entries(dependenciesByRange).filter(
([range]) => !ignoredRange.includes(range),
),
);
}
}
return dependenciesByRange;
}

/**
* Expect that all version ranges in `dependencies` and `devDependencies` for
* the same dependency across the entire monorepo are the same. As it is
Expand All @@ -732,9 +761,14 @@ function expectConsistentDependenciesAndDevDependencies(Yarn) {
dependencyIdent,
dependenciesByRange,
] of nonPeerDependenciesByIdent.entries()) {
const dependencyRanges = [...dependenciesByRange.keys()].sort();
const dependenciesToConsider =
getInconsistentDependenciesAndDevDependencies(
dependencyIdent,
dependenciesByRange,
);
const dependencyRanges = [...dependenciesToConsider.keys()].sort();
if (dependenciesByRange.size > 1) {
for (const dependencies of dependenciesByRange.values()) {
for (const dependencies of dependenciesToConsider.values()) {
for (const dependency of dependencies) {
dependency.error(
`Expected version range for ${dependencyIdent} (in ${
Expand Down

0 comments on commit d7c7bd1

Please sign in to comment.