@@ -12,6 +12,7 @@ import {
1212 FIXTURE_PATH_NO_DEPENDENCIES ,
1313 FIXTURE_PATH_PACKAGE_MISSING_PACKAGE_JSON ,
1414 FIXTURE_PATH_INCONSISTENT_LOCAL_PACKAGE_VERSION ,
15+ FIXTURE_PATH_RESOLUTIONS ,
1516} from '../fixtures/index.js' ;
1617import mockFs from 'mock-fs' ;
1718import { readFileSync } from 'node:fs' ;
@@ -170,6 +171,43 @@ describe('Utils | dependency-versions', function () {
170171 } ,
171172 ] ) ;
172173 } ) ;
174+
175+ it ( 'has mismatches with resolutions' , function ( ) {
176+ const dependencyVersions = calculateVersionsForEachDependency (
177+ getPackagesHelper ( FIXTURE_PATH_RESOLUTIONS )
178+ ) ;
179+ expect ( calculateMismatchingVersions ( dependencyVersions ) ) . toStrictEqual ( [
180+ {
181+ dependency : 'foo' ,
182+ versions : [
183+ {
184+ version : '^1.2.0' ,
185+ packages : [
186+ expect . objectContaining ( {
187+ path : FIXTURE_PATH_RESOLUTIONS ,
188+ } ) ,
189+ ] ,
190+ } ,
191+ {
192+ version : '1.3.0' ,
193+ packages : [
194+ expect . objectContaining ( {
195+ path : join ( FIXTURE_PATH_RESOLUTIONS , 'package1' ) ,
196+ } ) ,
197+ ] ,
198+ } ,
199+ {
200+ version : '^2.0.0' ,
201+ packages : [
202+ expect . objectContaining ( {
203+ path : FIXTURE_PATH_RESOLUTIONS ,
204+ } ) ,
205+ ] ,
206+ } ,
207+ ] ,
208+ } ,
209+ ] ) ;
210+ } ) ;
173211 } ) ;
174212
175213 describe ( '#filterOutIgnoredDependencies' , function ( ) {
@@ -685,6 +723,106 @@ describe('Utils | dependency-versions', function () {
685723 } ) ;
686724 } ) ;
687725
726+ describe ( 'resolutions' , function ( ) {
727+ beforeEach ( function ( ) {
728+ // Create a mock workspace filesystem for temporary usage in this test because changes will be written to some files.
729+ mockFs ( {
730+ 'package.json' : JSON . stringify ( {
731+ workspaces : [ '*' ] ,
732+ devDependencies : {
733+ foo : '^1.2.0' ,
734+ } ,
735+ resolutions : {
736+ foo : '^1.0.0' ,
737+ bar : '^1.0.0' ,
738+ } ,
739+ } ) ,
740+ package1 : {
741+ 'package.json' : JSON . stringify ( {
742+ name : 'package1' ,
743+ dependencies : {
744+ foo : '^2.0.0' ,
745+ bar : '^1.0.0' ,
746+ } ,
747+ } ) ,
748+ } ,
749+ } ) ;
750+ } ) ;
751+
752+ afterEach ( function ( ) {
753+ mockFs . restore ( ) ;
754+ } ) ;
755+
756+ it ( 'fixes the fixable inconsistencies' , function ( ) {
757+ const packages = getPackagesHelper ( '.' ) ;
758+ const mismatchingVersions = calculateMismatchingVersions (
759+ calculateVersionsForEachDependency ( packages )
760+ ) ;
761+ const { fixed, notFixed } = fixMismatchingVersions (
762+ packages ,
763+ mismatchingVersions
764+ ) ;
765+
766+ // Read in package.json files.
767+ const packageJsonRootContents = readFileSync ( 'package.json' , 'utf8' ) ;
768+ const packageJson1Contents = readFileSync (
769+ 'package1/package.json' ,
770+ 'utf8'
771+ ) ;
772+ const packageJsonRoot : PackageJson = JSON . parse (
773+ packageJsonRootContents
774+ ) ;
775+ const packageJson1 : PackageJson = JSON . parse ( packageJson1Contents ) ;
776+
777+ expect (
778+ packageJsonRoot . devDependencies &&
779+ packageJsonRoot . devDependencies [ 'foo' ]
780+ ) . toStrictEqual ( '^2.0.0' ) ;
781+
782+ expect (
783+ packageJsonRoot . resolutions && packageJsonRoot . resolutions [ 'foo' ]
784+ ) . toStrictEqual ( '^2.0.0' ) ;
785+
786+ expect (
787+ packageJson1 . dependencies && packageJson1 . dependencies [ 'foo' ]
788+ ) . toStrictEqual ( '^2.0.0' ) ;
789+
790+ expect ( notFixed ) . toStrictEqual ( [ ] ) ;
791+
792+ expect ( fixed ) . toStrictEqual ( [
793+ {
794+ dependency : 'foo' ,
795+ versions : [
796+ {
797+ version : '^1.0.0' ,
798+ packages : [
799+ expect . objectContaining ( {
800+ path : '.' ,
801+ } ) ,
802+ ] ,
803+ } ,
804+ {
805+ version : '^1.2.0' ,
806+ packages : [
807+ expect . objectContaining ( {
808+ path : '.' ,
809+ } ) ,
810+ ] ,
811+ } ,
812+ {
813+ version : '^2.0.0' ,
814+ packages : [
815+ expect . objectContaining ( {
816+ path : 'package1' ,
817+ } ) ,
818+ ] ,
819+ } ,
820+ ] ,
821+ } ,
822+ ] ) ;
823+ } ) ;
824+ } ) ;
825+
688826 describe ( 'increasable range' , function ( ) {
689827 beforeEach ( function ( ) {
690828 // Create a mock workspace filesystem for temporary usage in this test because changes will be written to some files.
0 commit comments