File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,20 @@ export class NpmRegistry extends Registry {
6262 }
6363 }
6464
65+ async isLoggedIn ( ) {
66+ try {
67+ await this . npm ( [ 'whoami' ] ) ;
68+
69+ return true ;
70+ } catch ( error ) {
71+ if ( `${ error } ` . includes ( 'ENEEDAUTH' ) ) {
72+ return false ;
73+ }
74+
75+ throw new NpmError ( 'Failed to run `npm whoami`' , { cause : error } ) ;
76+ }
77+ }
78+
6579 async collaborators ( ) {
6680 try {
6781 return JSON . parse (
Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ export const npmAvailableCheckTasks: ListrTask<Ctx> = {
2222 task : async ( ) => {
2323 const npm = await npmRegistry ( ) ;
2424
25+ if ( ! ( await npm . isLoggedIn ( ) ) ) {
26+ throw new NpmAvailableError (
27+ 'You are not logged in. Please log in first using `npm login`.' ,
28+ ) ;
29+ }
30+
2531 if ( await npm . isPublished ( ) ) {
2632 if ( ! ( await npm . hasPermission ( ) ) ) {
2733 throw new NpmAvailableError (
You can’t perform that action at this time.
0 commit comments