Skip to content

Commit 6c17a67

Browse files
committed
feat: npm login check [#3]
1 parent 35e1265 commit 6c17a67

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/registry/npm.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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(

src/tasks/npm.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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(

0 commit comments

Comments
 (0)