Skip to content

Commit 6a58c63

Browse files
committed
fix: fix npm log
1 parent 6e015a9 commit 6a58c63

1 file changed

Lines changed: 36 additions & 7 deletions

File tree

lib/package/npm.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ export default class Npm {
8888
error = true;
8989
}
9090

91+
const statusText = Object.entries( res.data?.tags || {} )
92+
.map( ( [ tag, version ] ) => `${ tag }: ${ version || "-" }` )
93+
.join( ", " );
94+
9195
logger.log( "Set npm tags:", res.ok
9296
? ( res.data.updated
93-
? ansi.ok( " Updated " )
94-
: "Not modified" )
97+
? ansi.ok( " Updated " ) + ", " + statusText
98+
: "Not modified, " + statusText )
9599
: ansi.error( " " + res.statusText + " " ) );
96100

97101
if ( !res.ok && error ) {
@@ -120,12 +124,16 @@ export default class Npm {
120124
res = result( [ 500, "Package name is not valid" ] );
121125
}
122126
else {
123-
res = await this.api.setAccessStatus( this.pkg.name, accessStatus );
127+
res = await this.#setAccessStatus( accessStatus );
124128

125129
error = true;
126130
}
127131

128-
logger.log( "Set npm access status:", res + "" );
132+
logger.log( "Set npm access status:", res.ok
133+
? ( res.data.updated
134+
? ansi.ok( " Updated " ) + ", access status: " + res.data.accessStatus
135+
: "Not modified, access status: " + res.data.accessStatus )
136+
: ansi.error( " " + res.statusText + " " ) );
129137

130138
if ( !res.ok && error ) {
131139
throw res;
@@ -216,7 +224,7 @@ export default class Npm {
216224
if ( !res.ok ) return res;
217225

218226
const versions = res.data,
219-
statusText = [];
227+
tags = {};
220228

221229
for ( const tag of [ "latest", "next" ] ) {
222230
res = await this.pkg.git.getCommit( { "commitRef": tag } );
@@ -227,7 +235,7 @@ export default class Npm {
227235

228236
if ( commit?.isRelease ) tagVersion = commit.releaseVersion.version;
229237

230-
statusText.push( `${ tag }: ${ tagVersion || "-" }` );
238+
tags[ tag ] = tagVersion;
231239

232240
if ( tagVersion ) {
233241
if ( versions[ tag ] !== tagVersion ) {
@@ -247,8 +255,29 @@ export default class Npm {
247255
}
248256
}
249257

250-
return result( [ 200, statusText.join( ", " ) ], {
258+
return result( 200, {
251259
updated,
260+
tags,
261+
} );
262+
}
263+
264+
async #setAccessStatus ( accessStatus ) {
265+
var res,
266+
updated = false;
267+
268+
res = await this.api.getPackageAccessStatus( this.pkg.name );
269+
if ( !res.ok ) return res;
270+
271+
if ( res.data.accessStatus !== accessStatus ) {
272+
res = await this.api.setPackageAccessStatus( this.pkg.name, accessStatus );
273+
if ( !res.ok ) return res;
274+
275+
updated = true;
276+
}
277+
278+
return result( 200, {
279+
updated,
280+
accessStatus,
252281
} );
253282
}
254283
}

0 commit comments

Comments
 (0)