1- import type { TwoFactorState } from './npm' ;
21import type { PackageInfo , ReleaseOptions } from './types' ;
32import chalk from 'chalk' ;
43import { execa } from 'execa' ;
54import open from 'open' ;
65import semver from 'semver' ;
6+ import { ReleaseError } from './error' ;
77import {
88 getGitTagVersion ,
99 getGitTagVersionRelease ,
@@ -12,7 +12,7 @@ import {
1212 releaseNotes ,
1313} from './git' ;
1414import { logger } from './logger' ;
15- import { getNpmEnv , getOtpCode , getTwoFactorState , updatePackageVersion } from './npm' ;
15+ import { getNpmEnv , updatePackageVersion } from './npm' ;
1616import { run } from './utils' ;
1717
1818export async function runPublish ( opts : ReleaseOptions ) {
@@ -56,14 +56,13 @@ async function bumpVersionAndTag(opts: ReleaseOptions) {
5656
5757async function runPublishPackages ( opts : ReleaseOptions ) {
5858 const { pkgs, dryRun, packageManager : pm } = opts ;
59- const twoFactorState = getTwoFactorState ( opts ) ;
6059
6160 if ( opts . publish ) {
6261 for ( const pkg of pkgs ) {
6362 if ( ! dryRun && opts . build && pkg . packageJson ?. scripts ?. build ) {
6463 await run ( `${ pm . cli } run build` , { cwd : pkg . dir } ) ;
6564 }
66- await publishOnePackage ( pkg , opts , twoFactorState ) ;
65+ await publishOnePackage ( pkg , opts ) ;
6766 const tag = `${ pkg . name } @${ pkg . newVersion } ` ;
6867 logger . success ( `Publish ${ chalk . green ( tag ) } successfully 🎉` ) ;
6968 }
@@ -85,7 +84,6 @@ async function runPublishPackages(opts: ReleaseOptions) {
8584async function publishOnePackage (
8685 pkg : PackageInfo ,
8786 opts : ReleaseOptions ,
88- twoFactorState : TwoFactorState ,
8987) {
9088 const { packageManager : pm , dryRun } = opts ;
9189 const args : string [ ] = [ 'publish' , '--access' , pkg . access , '--tag' , pkg . tag ] ;
@@ -98,10 +96,6 @@ async function publishOnePackage(
9896 args . push ( `---new-version` , pkg . newVersion ) ;
9997 }
10098
101- if ( await twoFactorState . isRequired ) {
102- await getOtpCode ( twoFactorState ) ;
103- }
104-
10599 if ( dryRun && pm . cli !== 'yarn' ) {
106100 args . push ( '--dry-run' ) ;
107101 }
@@ -111,15 +105,7 @@ async function publishOnePackage(
111105 cli = 'yarn npm' ;
112106 }
113107
114- const getArgs = ( ) => {
115- const otp = twoFactorState . token ;
116- if ( otp ) {
117- return [ ...args , '--otp' , otp ] ;
118- }
119- return [ ...args ] ;
120- } ;
121-
122- const cmd = [ cli ] . concat ( getArgs ( ) ) . join ( ' ' ) ;
108+ const cmd = [ cli ] . concat ( args ) . join ( ' ' ) ;
123109 logger . debug ( cmd ) ;
124110
125111 if ( dryRun && pm . cli === 'yarn' ) {
@@ -128,21 +114,13 @@ async function publishOnePackage(
128114 }
129115
130116 try {
131- await runNpmPublish ( cli , getArgs ( ) , pkg ) ;
132- twoFactorState . tryAgain = false ;
117+ await runNpmPublish ( cli , args , pkg ) ;
133118 }
134119 catch ( e : any ) {
135120 if ( e && needOtp ( e . message ) ) {
136- if ( twoFactorState . token !== null ) {
137- // the current otp code must be invalid since it errored
138- twoFactorState . token = null ;
139- }
140- twoFactorState . tryAgain = true ;
141- await publishOnePackage ( pkg , opts , twoFactorState ) ;
142- }
143- else {
144- throw e ;
121+ logger . error ( chalk . red ( 'Please use "Access Tokens -> Security settings" to bypass 2FA"' ) ) ;
145122 }
123+ ReleaseError . rollback ( e . message ) ;
146124 }
147125}
148126
0 commit comments