@@ -16,6 +16,7 @@ import { isWorkingTreeClean, getCurrentBranchName } from '../../../utils/git-ope
16
16
import { logFatal , logInfo , spinner , logText } from '../../../utils/log' ;
17
17
import { getMonoAndNpmDepsOnce , DepMap } from '../../../utils/packages' ;
18
18
import { ProjectConfig } from '../../../utils/define' ;
19
+ import { isOwner } from '../../../utils/npm' ;
19
20
20
21
export const publish = async ( options : PublishOption ) => {
21
22
const currentBranchName = options . branch ? options . branch : await getCurrentBranchName ( ) ;
@@ -61,6 +62,7 @@ export const publish = async (options: PublishOption) => {
61
62
! options . commitOnly && ( await buildDeclaration ( ) ) ;
62
63
63
64
if ( installAllPrompt . installAll ) {
65
+ await authPublish ( [ pri . projectPackageJson . name , ...depMonoPackages . map ( v => v . packageJson . name ) ] )
64
66
for ( const eachPackage of depMonoPackages ) {
65
67
await publishByPackageName ( eachPackage . name , options , depMap , isDevelopBranch , currentBranchName ) ;
66
68
}
@@ -69,7 +71,7 @@ export const publish = async (options: PublishOption) => {
69
71
// eslint-disable-next-line no-unused-expressions
70
72
! options . commitOnly && ( await buildDeclaration ( ) ) ;
71
73
}
72
-
74
+ await authPublish ( [ pri . projectPackageJson . name ] )
73
75
await publishByPackageName ( currentSelectedSourceType , options , depMap , isDevelopBranch , currentBranchName ) ;
74
76
75
77
await fs . remove ( path . join ( pri . projectRootPath , tempPath . dir , declarationPath . dir ) ) ;
@@ -84,6 +86,33 @@ export const publish = async (options: PublishOption) => {
84
86
}
85
87
} ;
86
88
89
+ async function authPublish ( packageNames : string [ ] ) {
90
+ let name : string ;
91
+ try {
92
+ const nameRet = execSync ( 'tnpm whoami' ) ;
93
+ name = nameRet . toString ( ) . trim ( ) ;
94
+ } catch ( error ) {
95
+ logFatal ( error ) ;
96
+ }
97
+ const failedPkgSet = new Set < string > ( ) ;
98
+ const checkOwner = ( uName : string , pName : string ) =>
99
+ new Promise ( ( res , rej ) => {
100
+ isOwner ( uName , pName )
101
+ . then ( v => {
102
+ if ( ! v ) {
103
+ failedPkgSet . add ( pName ) ;
104
+ }
105
+ res ( v ) ;
106
+ } )
107
+ . catch ( e => rej ( e ) ) ;
108
+ } ) ;
109
+ const pkgsP = packageNames . map ( p => checkOwner ( name , p ) ) ;
110
+ await Promise . all ( pkgsP ) ;
111
+ if ( failedPkgSet . size > 0 ) {
112
+ logFatal ( `以下 npm 包无权限发布 \n ${ Array . from ( failedPkgSet ) . join ( '\n' ) } ` ) ;
113
+ }
114
+ }
115
+
87
116
async function publishByPackageName (
88
117
sourceType : string ,
89
118
options : PublishOption ,
0 commit comments