@@ -39,7 +39,7 @@ export class FileStore implements IStore {
39
39
return this . publishers . length ;
40
40
}
41
41
42
- private constructor ( readonly path : string , private publishers : IPublisher [ ] ) { }
42
+ private constructor ( readonly path : string , private publishers : IPublisher [ ] ) { }
43
43
44
44
private async save ( ) : Promise < void > {
45
45
await fs . promises . writeFile ( this . path , JSON . stringify ( { publishers : this . publishers } ) , { mode : '0600' } ) ;
@@ -92,7 +92,7 @@ export class KeytarStore implements IStore {
92
92
private readonly keytar : typeof import ( 'keytar' ) ,
93
93
private readonly serviceName : string ,
94
94
private publishers : IPublisher [ ]
95
- ) { }
95
+ ) { }
96
96
97
97
get ( name : string ) : IPublisher {
98
98
return this . publishers . filter ( p => p . name === name ) [ 0 ] ;
@@ -113,20 +113,14 @@ export class KeytarStore implements IStore {
113
113
}
114
114
}
115
115
116
- export async function verifyPat ( pat : string , publisherName ?: string ) : Promise < void > {
117
- if ( ! pat ) {
118
- throw new Error ( 'The Personal Access Token is mandatory.' ) ;
119
- }
116
+ export interface IVerifyPatOptions {
117
+ readonly publisherName ?: string ;
118
+ readonly pat ?: string ;
119
+ }
120
120
121
- if ( ! publisherName ) {
122
- try {
123
- publisherName = ( await readManifest ( ) ) . publisher ;
124
- } catch ( error ) {
125
- throw new Error (
126
- `Can not read the publisher's name. Either supply it as an argument or run vsce from the extension folder. Additional information:\n\n${ error } `
127
- ) ;
128
- }
129
- }
121
+ export async function verifyPat ( options : IVerifyPatOptions ) : Promise < void > {
122
+ const publisherName = options . publisherName ?? ( await readManifest ( ) ) . publisher ;
123
+ const pat = options . pat ?? ( await getPublisher ( publisherName ) ) . pat ;
130
124
131
125
try {
132
126
// If the caller of the `getRoleAssignments` API has any of the roles
@@ -145,7 +139,7 @@ async function requestPAT(publisherName: string): Promise<string> {
145
139
console . log ( `${ getMarketplaceUrl ( ) } /manage/publishers/` ) ;
146
140
147
141
const pat = await read ( `Personal Access Token for publisher '${ publisherName } ':` , { silent : true , replace : '*' } ) ;
148
- await verifyPat ( pat , publisherName ) ;
142
+ await verifyPat ( { publisherName, pat } ) ;
149
143
return pat ;
150
144
}
151
145
0 commit comments