Skip to content

Commit 17202af

Browse files
committed
fix: handle npm otp error
1 parent 2c96e0e commit 17202af

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/registry/npm.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ export class NpmRegistry extends Registry {
124124

125125
async publishProvenance() {
126126
try {
127-
await this.npm(['publish', '--provenance', '--access', 'public']);
127+
try {
128+
await this.npm(['publish', '--provenance', '--access', 'public']);
129+
} catch (error) {
130+
if (`${error}`.includes('EOTP')) {
131+
return false;
132+
}
133+
}
128134

129135
return true;
130136
} catch (error) {
@@ -144,7 +150,7 @@ export class NpmRegistry extends Registry {
144150
try {
145151
await this.npm(args);
146152
} catch (error) {
147-
if (`${error}`.includes('OTP')) {
153+
if (`${error}`.includes('EOTP')) {
148154
return false;
149155
}
150156
}

src/tasks/npm.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,12 @@ export const npmPublishTasks: ListrTask<Ctx> = {
7979
);
8080
}
8181

82-
try {
83-
await npm.publishProvenance();
84-
} catch (error) {
85-
if (`${error}`.includes('EOTP')) {
86-
throw new NpmAvailableError(
87-
`In CI environment, publishing with 2FA is not allowed. Please disable 2FA when accessing with a token from ${link('npm', `https://www.npmjs.com/package/${npm.packageName}/access`)}.`,
88-
);
89-
}
82+
const result = await npm.publishProvenance();
9083

91-
throw error;
84+
if (!result) {
85+
throw new NpmAvailableError(
86+
`In CI environment, publishing with 2FA is not allowed. Please disable 2FA when accessing with a token from ${link('npm', `https://www.npmjs.com/package/${npm.packageName}/access`)}.`,
87+
);
9288
}
9389
}
9490
},

0 commit comments

Comments
 (0)