@@ -4,18 +4,16 @@ import type { InternalPublishPkg, InternalPublishOptions, PublishTarget } from '
44import core from '@actions/core' ;
55import { registryRecord } from './const' ;
66import { runCommand } from './utils' ;
7+ import { syncPackage } from './sync-package' ;
8+ import { checkPackageExist } from './check-package' ;
79
8- export function checkPackageExist ( pkg : InternalPublishPkg ) {
9- try {
10- const options = core . isDebug ( ) ? '--verbose' : '' ;
11- runCommand ( `npm view ${ pkg . name } @${ pkg . version } ${ options } ` , pkg . cwd ) ;
12- return true ;
13- } catch ( err ) {
14- return false ;
15- }
16- }
10+ export async function publishPackage ( pkg : InternalPublishPkg , options : InternalPublishOptions ) {
11+ core . info ( `publish package cwd: ${ pkg . cwd } ` ) ;
12+ core . info ( `publish package name: ${ pkg . name } ` ) ;
13+ core . info ( `publish package version: ${ pkg . version } ` ) ;
14+ core . info ( `publish package tag: ${ options . tag } ` ) ;
15+ core . info ( `publish package target: ${ options . target } ` ) ;
1716
18- export function publishPackage ( pkg : InternalPublishPkg , options : InternalPublishOptions ) {
1917 // monorepo 下的所有 package 都参考根目录的 npmrc
2018 const npmrcFile = path . resolve ( '.npmrc' ) ;
2119 const backupFile = npmrcFile + '-' + Date . now ( ) ;
@@ -47,11 +45,11 @@ export function publishPackage(pkg: InternalPublishPkg, options: InternalPublish
4745 } ;
4846
4947 const check = ( ) => {
50- core . info ( `checking package is exist ` ) ;
48+ core . info ( `checking package` ) ;
5149 const isExist = checkPackageExist ( pkg ) ;
5250
5351 if ( isExist ) {
54- core . info ( `package is exists, skip publish` ) ;
52+ core . info ( `${ pkg . name } @ ${ pkg . version } is exists, skip publish` ) ;
5553 cleanup ( ) ;
5654 return true ;
5755 }
@@ -81,5 +79,11 @@ export function publishPackage(pkg: InternalPublishPkg, options: InternalPublish
8179 } ;
8280
8381 if ( check ( ) ) return ;
82+
8483 publish ( ) ;
84+
85+ if ( options . target === 'npm' && options . syncNpmmirror ) {
86+ core . info ( `syncing package` ) ;
87+ await syncPackage ( pkg . name , options ) ;
88+ }
8589}
0 commit comments