@@ -401,24 +401,11 @@ export default class Package {
401401 } ) ;
402402 }
403403
404- async updateMetadata ( { updateDependabot, updateRepository, updateNpm , commit, logger } = { } ) {
404+ async updateMetadata ( { updateDependabot, updateRepository, updateTags , commit, logger } = { } ) {
405405 logger ||= globalThis . console ;
406406
407407 var res ;
408408
409- // fix release tags
410- if ( this . cliConfig ?. release . enabled ) {
411- res = await this . fixReleaseTags ( ) ;
412-
413- logger . log ( "Fix release tags:" , res . ok
414- ? ( res . data . updated
415- ? ansi . ok ( " Updated " )
416- : "Not modified" )
417- : ansi . error ( " " + res . statusText + " " ) ) ;
418-
419- if ( ! res . ok ) return res ;
420- }
421-
422409 // configure upstream repository
423410 if ( updateRepository ) {
424411 res = await this . configureUpstreamRepository ( ) ;
@@ -445,12 +432,30 @@ export default class Package {
445432 if ( ! res . ok ) return res ;
446433 }
447434
448- // update npm package tags
449- if ( updateNpm ) {
435+ // update release tags
436+ if ( updateTags ) {
437+
438+ // update release tags in repository
439+ if ( this . cliConfig ?. release . enabled ) {
440+ res = await this . updateReleaseTags ( ) ;
441+
442+ const statusText = Object . entries ( res . data ?. tags || { } )
443+ . map ( ( [ tag , version ] ) => `${ tag } : ${ version || "-" } ` )
444+ . join ( ", " ) ;
445+
446+ logger . log ( "Update release tags:" , res . ok
447+ ? ( res . data . updated
448+ ? ansi . ok ( " Updated " ) + ", " + statusText
449+ : "Not modified, " + statusText )
450+ : ansi . error ( " " + res . statusText + " " ) ) ;
451+
452+ if ( ! res . ok ) return res ;
453+ }
454+
450455 for ( const pkg of [ this , ...this . subPackages ] ) {
451456 if ( pkg . isPrivate ) continue ;
452457
453- res = await pkg . npm . setTags ( {
458+ res = await pkg . npm . updateTags ( {
454459 logger,
455460 } ) ;
456461
@@ -461,7 +466,7 @@ export default class Package {
461466 return result ( 200 ) ;
462467 }
463468
464- async fixReleaseTags ( ) {
469+ async updateReleaseTags ( ) {
465470 var res ,
466471 updated = false ;
467472
@@ -471,30 +476,29 @@ export default class Package {
471476 } ) ;
472477 }
473478
474- res = await this . git . getReleases ( ) ;
479+ res = await this . git . getReleaseTags ( ) ;
475480 if ( ! res . ok ) return res ;
476-
477- const releases = res . data ,
478- tags = releases . getReleaseTagsVersions ( {
479- "majorTags" : true ,
480- } ) ;
481+ const tags = res . data ;
481482
482483 for ( const tag in tags ) {
483- if ( ! tags [ tag ] ) continue ;
484484
485- res = await this . git . getCommit ( { "commitRef" : tags [ tag ] . versionString } ) ;
486- if ( ! res . ok ) return res ;
487- const commit = res . data ;
485+ // update tag
486+ if ( tags [ tag ] . action === "update" ) {
487+ res = await this . git . exec ( [ "tag" , "--force" , "--annotate" , "--message" , this . createReleaseTagAnnotation ( tag ) , tag , tags [ tag ] . version ] ) ;
488+ if ( ! res . ok ) return res ;
489+
490+ res = await this . git . exec ( [ "push" , "--atomic" , "--force" , "origin" , tag ] ) ;
491+ if ( ! res . ok ) return res ;
488492
489- if ( ! commit . tags . has ( tag ) ) {
490- const message = TAG_MESSAGES [ tag ] || `Latest stable release for the major branch: ${ tag } ` ;
493+ updated = true ;
494+ }
491495
492- // set tag
493- res = await this . git . exec ( [ "tag" , "--force" , "--annotate" , "--message" , message , tag , commit . hash ] ) ;
496+ // delete tag
497+ else if ( tags [ tag ] . action === "delete" ) {
498+ res = await this . git . exec ( [ "tag" , "--delete" , tag ] ) ;
494499 if ( ! res . ok ) return res ;
495500
496- // push tag
497- res = await this . git . exec ( [ "push" , "--atomic" , "--force" , "origin" , tag ] ) ;
501+ res = await this . git . exec ( [ "push" , "--delete" , "origin" , tag ] ) ;
498502 if ( ! res . ok ) return res ;
499503
500504 updated = true ;
@@ -503,6 +507,11 @@ export default class Package {
503507
504508 return result ( 200 , {
505509 updated,
510+ "tags" : Object . entries ( tags ) . reduce ( ( tags , [ tag , { version } ] ) => {
511+ if ( version ) {
512+ tags [ tag ] = version ;
513+ }
514+ } , { } ) ,
506515 } ) ;
507516 }
508517
@@ -1159,6 +1168,10 @@ export default class Package {
11591168 } ) ;
11601169 }
11611170
1171+ createReleaseTagAnnotation ( tag ) {
1172+ TAG_MESSAGES [ tag ] || `Latest stable release for the branch: ${ tag } ` ;
1173+ }
1174+
11621175 clearCache ( ) {
11631176 this . #clearCache( ) ;
11641177 }
0 commit comments