From d106b1a8cebd6dc7f7559daa1dcf2e8b1d52898d Mon Sep 17 00:00:00 2001 From: legobeat <109787230+legobeat@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:04:20 +0000 Subject: [PATCH] chore(constraints): respect ALLOWED_INCONSISTENT_DEPENDENCIES for workspace packages; simplify logic (#4800) --- yarn.config.cjs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/yarn.config.cjs b/yarn.config.cjs index 9b51713461..eb78a316c6 100644 --- a/yarn.config.cjs +++ b/yarn.config.cjs @@ -12,6 +12,15 @@ const { basename, resolve } = require('path'); const semver = require('semver'); const { inspect } = require('util'); +/** + * These packages and ranges are allowed to mismatch expected consistency checks + * Only intended as temporary measures to faciliate upgrades and releases. + * This should trend towards empty. + */ +const ALLOWED_INCONSISTENT_DEPENDENCIES = { + '@metamask/rpc-errors': ['^7.0.0'], +}; + /** * Aliases for the Yarn type definitions, to make the code more readable. * @@ -594,6 +603,11 @@ function expectUpToDateWorkspaceDependenciesAndDevDependencies( dependencyWorkspace !== null && dependency.type !== 'peerDependencies' ) { + const ignoredRanges = ALLOWED_INCONSISTENT_DEPENDENCIES[dependency.ident]; + if (ignoredRanges?.includes(dependency.range)) { + continue; + } + dependency.update(`^${dependencyWorkspace.manifest.version}`); } } @@ -714,10 +728,6 @@ function expectControllerDependenciesListedAsPeerDependencies( } } -const ALLOWED_INCONSISTENT_DEPENDENCIES = Object.entries({ - '@metamask/rpc-errors': ['^7.0.0'], -}); - /** * Filter out dependency ranges which are not to be considered in `expectConsistentDependenciesAndDevDependencies`. * @@ -729,19 +739,15 @@ function getInconsistentDependenciesAndDevDependencies( dependencyIdent, dependenciesByRange, ) { - for (const [ - allowedPackage, - ignoredRange, - ] of ALLOWED_INCONSISTENT_DEPENDENCIES) { - if (allowedPackage === dependencyIdent) { - return new Map( - Object.entries(dependenciesByRange).filter( - ([range]) => !ignoredRange.includes(range), - ), - ); - } + const ignoredRanges = ALLOWED_INCONSISTENT_DEPENDENCIES[dependencyIdent]; + if (!ignoredRanges) { + return dependenciesByRange; } - return dependenciesByRange; + return new Map( + Object.entries(dependenciesByRange).filter( + ([range]) => !ignoredRanges.includes(range), + ), + ); } /**