@@ -15,7 +15,7 @@ import { getIndent } from './lib/get-indent';
1515import { getPackages } from './lib/get-packages' ;
1616import { getMismatchedVersionsByName } from './lib/get-versions-by-name' ;
1717import { getNewest } from './lib/version' ;
18- import { CommanderApi } from './typings' ;
18+ import { CommanderApi , IManifest } from './typings' ;
1919
2020export const run = async ( program : CommanderApi ) => {
2121 program
@@ -34,29 +34,38 @@ export const run = async (program: CommanderApi) => {
3434 pkgs
3535 ) ;
3636
37- Object . entries ( mismatchedVersionsByName ) . forEach ( ( [ name , versions ] ) => {
38- const newest = getNewest ( versions ) ;
39- pkgs . forEach ( ( { data, path } ) => {
40- dependencyTypes . forEach ( ( type ) => {
41- if ( data [ type ] && data [ type ] [ name ] && data [ type ] [ name ] !== newest ) {
37+ await Promise . all (
38+ pkgs . map ( ( { data, path } ) => {
39+ const nextData : IManifest = JSON . parse ( JSON . stringify ( data ) ) ;
40+ const shortPath = `./${ relative ( '.' , path ) } ` ;
41+ const changes : string [ ] [ ] = [ ] ;
42+ Object . entries ( mismatchedVersionsByName ) . forEach ( ( [ name , versions ] ) => {
43+ const newest = getNewest ( versions ) ;
44+ dependencyTypes . forEach ( ( type ) => {
45+ if (
46+ nextData [ type ] &&
47+ nextData [ type ] [ name ] &&
48+ nextData [ type ] [ name ] !== newest
49+ ) {
50+ changes . push ( [ name , nextData [ type ] [ name ] , newest ] ) ;
51+ nextData [ type ] [ name ] = newest ;
52+ }
53+ } ) ;
54+ } ) ;
55+ if ( changes . length > 0 ) {
56+ changes . forEach ( ( [ name , from , to ] ) => {
4257 console . log (
43- relative ( process . cwd ( ) , path ) ,
58+ chalk . bgYellow . black ( ' FIXED ' ) ,
59+ chalk . blue ( shortPath ) ,
4460 name ,
45- data [ type ] [ name ] ,
46- '-> ' ,
47- newest
61+ chalk . red ( from ) ,
62+ '→ ' ,
63+ chalk . green ( to )
4864 ) ;
49- data [ type ] [ name ] = newest ;
50- }
51- } ) ;
52- } ) ;
53- } ) ;
54-
55- await Promise . all (
56- pkgs . map ( ( { data, path } ) => writeJson ( path , data , { spaces : indent } ) )
65+ } ) ;
66+ return writeJson ( path , nextData , { spaces : indent } ) ;
67+ }
68+ console . log ( chalk . bgGreen . black ( ' VALID ' ) , chalk . blue ( shortPath ) ) ;
69+ } )
5770 ) ;
58-
59- _ . each ( pkgs , ( pkg ) => {
60- console . log ( chalk . blue ( `./${ relative ( '.' , pkg . path ) } ` ) ) ;
61- } ) ;
6271} ;
0 commit comments