@@ -619,6 +619,163 @@ export default class Package {
619619 return this . npm . runScript ( script , { args } ) ;
620620 }
621621
622+ async getOutdatedDependencies ( { cache = { } } = { } ) {
623+ if ( ! this . dependencies . hasDependencies ) return result ( 200 ) ;
624+
625+ var res ,
626+ updates = [ ] ,
627+ promises = [ ] ;
628+
629+ for ( const dependency of this . dependencies ) {
630+ if ( cache [ dependency . name ] ) continue ;
631+
632+ const promise = async resolve => {
633+ const mutex = MUTEX_SET . get ( "outdated-dependencies/" + dependency . name ) ;
634+
635+ if ( mutex . tryLock ( ) ) {
636+ if ( dependency . gitRepositorySlug ) {
637+ res = await this . git . exec ( [ "ls-remote" , "--tags" , `https://github.com/${ dependency . gitRepositorySlug } ` ] ) ;
638+
639+ if ( res . ok ) {
640+ const versions = [ ] ;
641+
642+ for ( const line of res . data . split ( "\n" ) ) {
643+ const fields = line . split ( "\t" ) ,
644+ tag = fields [ 1 ] ?. replace ( "refs/tags/" , "" ) ;
645+
646+ if ( ! tag || tag . endsWith ( "^{}" ) ) continue ;
647+
648+ if ( SemanticVersion . isValid ( tag ) ) {
649+ versions . push ( tag ) ;
650+ }
651+ }
652+
653+ res . data = versions ;
654+ }
655+ }
656+ else {
657+ res = await this . npm . getPackageTags ( dependency . name ) ;
658+
659+ if ( res . ok ) {
660+ res . data = [ res . data . latest ] ;
661+ }
662+ }
663+
664+ if ( res . ok ) {
665+ let latest ;
666+
667+ for ( let version of res . data ) {
668+ version = new SemanticVersion ( version ) ;
669+
670+ if ( ! version . isPreRelease ) {
671+ if ( latest ) {
672+ if ( version . gt ( latest ) ) latest = version ;
673+ }
674+ else {
675+ latest = version ;
676+ }
677+ }
678+ }
679+
680+ res = result ( 200 , {
681+ latest,
682+ } ) ;
683+ }
684+
685+ cache [ dependency . name ] = res ;
686+
687+ mutex . unlock ( ) ;
688+ }
689+ else {
690+ await mutex . wait ( ) ;
691+ }
692+
693+ resolve ( ) ;
694+ } ;
695+
696+ promises . push ( new Promise ( resolve => promise ( resolve ) ) ) ;
697+ }
698+
699+ if ( promises . length ) {
700+ await Promise . all ( promises ) ;
701+ }
702+
703+ try {
704+ for ( const dependency of this . dependencies ) {
705+ res = cache [ dependency . name ] ;
706+ if ( ! res . ok ) throw res ;
707+
708+ const isOutdated = ! dependency . range . test ( res . data . latest ) ;
709+
710+ if ( isOutdated ) {
711+ updates . push ( {
712+ "name" : dependency . name ,
713+ "wanted" : dependency . range ,
714+ "latest" : res . data . latest ,
715+ isOutdated,
716+ } ) ;
717+ }
718+ }
719+ }
720+ catch ( e ) {
721+ res = result . catch ( e ) ;
722+ }
723+
724+ const logger = new Logger ( {
725+ "stdout" : "pipe" ,
726+ "stderr" : "pipe" ,
727+ } ) ;
728+
729+ if ( res . ok ) {
730+ res = result ( 200 , {
731+ "updates" : updates . length
732+ ? updates
733+ : null ,
734+ } ) ;
735+
736+ if ( updates . length ) {
737+ const table = new Table ( {
738+ "ansi" : process . stdout ,
739+ "width" : process . stdout ,
740+ "columns" : {
741+ "name" : {
742+ "title" : ansi . hl ( "DEPENDENCY" ) ,
743+ "headerAlign" : "center" ,
744+ "headerValign" : "end" ,
745+ } ,
746+ "wanted" : {
747+ "title" : ansi . hl ( "WANTED VERSION" ) ,
748+ "headerAlign" : "center" ,
749+ "headerValign" : "end" ,
750+ "align" : "end" ,
751+ "width" : 30 ,
752+ } ,
753+ "latest" : {
754+ "title" : ansi . hl ( "LATEST VERSION" ) ,
755+ "headerAlign" : "center" ,
756+ "headerValign" : "end" ,
757+ "align" : "end" ,
758+ "width" : 30 ,
759+ } ,
760+ } ,
761+ } )
762+ . write ( updates . sort ( ( a , b ) => compare ( a . name , b . name ) ) )
763+ . end ( ) ;
764+
765+ logger . log ( table . content . trim ( ) ) ;
766+ }
767+ }
768+ else {
769+ logger . log ( "Get dependencies ... " + ansi . error ( " ERROR " ) + ", " + res ) ;
770+
771+ res = result ( 500 , { } ) ;
772+ }
773+
774+ res . data . log = logger . flush ( ) . trim ( ) ;
775+
776+ return res ;
777+ }
778+
622779 async updateDependencies ( { reinstall, commit, repeatOnError = false } = { } ) {
623780 if ( ! this . dependencies . hasDependencies ) return result ( 200 ) ;
624781
@@ -841,163 +998,6 @@ export default class Package {
841998 return res ;
842999 }
8431000
844- async getOutdatedDependencies ( { cache = { } } = { } ) {
845- if ( ! this . dependencies . hasDependencies ) return result ( 200 ) ;
846-
847- var res ,
848- updates = [ ] ,
849- promises = [ ] ;
850-
851- for ( const dependency of this . dependencies ) {
852- if ( cache [ dependency . name ] ) continue ;
853-
854- const promise = async resolve => {
855- const mutex = MUTEX_SET . get ( "outdated-dependencies/" + dependency . name ) ;
856-
857- if ( mutex . tryLock ( ) ) {
858- if ( dependency . gitRepositorySlug ) {
859- res = await this . git . exec ( [ "ls-remote" , "--tags" , `https://github.com/${ dependency . gitRepositorySlug } ` ] ) ;
860-
861- if ( res . ok ) {
862- const versions = [ ] ;
863-
864- for ( const line of res . data . split ( "\n" ) ) {
865- const fields = line . split ( "\t" ) ,
866- tag = fields [ 1 ] ?. replace ( "refs/tags/" , "" ) ;
867-
868- if ( ! tag || tag . endsWith ( "^{}" ) ) continue ;
869-
870- if ( SemanticVersion . isValid ( tag ) ) {
871- versions . push ( tag ) ;
872- }
873- }
874-
875- res . data = versions ;
876- }
877- }
878- else {
879- res = await this . npm . getPackageTags ( dependency . name ) ;
880-
881- if ( res . ok ) {
882- res . data = [ res . data . latest ] ;
883- }
884- }
885-
886- if ( res . ok ) {
887- let latest ;
888-
889- for ( let version of res . data ) {
890- version = new SemanticVersion ( version ) ;
891-
892- if ( ! version . isPreRelease ) {
893- if ( latest ) {
894- if ( version . gt ( latest ) ) latest = version ;
895- }
896- else {
897- latest = version ;
898- }
899- }
900- }
901-
902- res = result ( 200 , {
903- latest,
904- } ) ;
905- }
906-
907- cache [ dependency . name ] = res ;
908-
909- mutex . unlock ( ) ;
910- }
911- else {
912- await mutex . wait ( ) ;
913- }
914-
915- resolve ( ) ;
916- } ;
917-
918- promises . push ( new Promise ( resolve => promise ( resolve ) ) ) ;
919- }
920-
921- if ( promises . length ) {
922- await Promise . all ( promises ) ;
923- }
924-
925- try {
926- for ( const dependency of this . dependencies ) {
927- res = cache [ dependency . name ] ;
928- if ( ! res . ok ) throw res ;
929-
930- const isOutdated = ! dependency . range . test ( res . data . latest ) ;
931-
932- if ( isOutdated ) {
933- updates . push ( {
934- "name" : dependency . name ,
935- "wanted" : dependency . range ,
936- "latest" : res . data . latest ,
937- isOutdated,
938- } ) ;
939- }
940- }
941- }
942- catch ( e ) {
943- res = result . catch ( e ) ;
944- }
945-
946- const logger = new Logger ( {
947- "stdout" : "pipe" ,
948- "stderr" : "pipe" ,
949- } ) ;
950-
951- if ( res . ok ) {
952- res = result ( 200 , {
953- "updates" : updates . length
954- ? updates
955- : null ,
956- } ) ;
957-
958- if ( updates . length ) {
959- const table = new Table ( {
960- "ansi" : process . stdout ,
961- "width" : process . stdout ,
962- "columns" : {
963- "name" : {
964- "title" : ansi . hl ( "DEPENDENCY" ) ,
965- "headerAlign" : "center" ,
966- "headerValign" : "end" ,
967- } ,
968- "wanted" : {
969- "title" : ansi . hl ( "WANTED VERSION" ) ,
970- "headerAlign" : "center" ,
971- "headerValign" : "end" ,
972- "align" : "end" ,
973- "width" : 30 ,
974- } ,
975- "latest" : {
976- "title" : ansi . hl ( "LATEST VERSION" ) ,
977- "headerAlign" : "center" ,
978- "headerValign" : "end" ,
979- "align" : "end" ,
980- "width" : 30 ,
981- } ,
982- } ,
983- } )
984- . write ( updates . sort ( ( a , b ) => compare ( a . name , b . name ) ) )
985- . end ( ) ;
986-
987- logger . log ( table . content . trim ( ) ) ;
988- }
989- }
990- else {
991- logger . log ( "Get dependencies ... " + ansi . error ( " ERROR " ) + ", " + res ) ;
992-
993- res = result ( 500 , { } ) ;
994- }
995-
996- res . data . log = logger . flush ( ) . trim ( ) ;
997-
998- return res ;
999- }
1000-
10011001 async runTests ( { log } = { } ) {
10021002 var res ;
10031003
0 commit comments