1
1
import chalk from 'chalk' ;
2
2
import { spawnSync } from 'child_process' ;
3
- import { readFileSync } from 'fs' ;
3
+ import { readFileSync , unlinkSync } from 'fs' ;
4
4
import { join } from 'path' ;
5
5
import { BaseReleaseTask } from './base-release-task' ;
6
6
import { checkReleaseOutput } from './check-release-output' ;
7
7
import { extractReleaseNotes } from './extract-release-notes' ;
8
8
import { GitClient } from './git/git-client' ;
9
9
import { getGithubNewReleaseUrl } from './git/github-urls' ;
10
- import {
11
- isNpmAuthenticated ,
12
- npmLogout ,
13
- npmLoginInteractive ,
14
- npmPublish ,
15
- } from './npm/npm-client' ;
16
- import { promptForNpmDistTag , promptForNpmOtp } from './prompt/npm-dist-tag-prompt' ;
10
+ import { npmPublish } from './npm/npm-client' ;
11
+ import { promptForNpmDistTag } from './prompt/npm-dist-tag-prompt' ;
17
12
import { promptForUpstreamRemote } from './prompt/upstream-remote-prompt' ;
18
13
import { releasePackages } from './release-output/release-packages' ;
19
14
import { CHANGELOG_FILE_NAME } from './stage-release' ;
20
15
import { parseVersionName , Version } from './version-name/parse-version' ;
21
16
22
- /** Maximum allowed tries to authenticate NPM. */
23
- const MAX_NPM_LOGIN_TRIES = 2 ;
24
-
25
17
/**
26
18
* Class that can be instantiated in order to create a new release. The tasks requires user
27
19
* interaction/input through command line prompts.
@@ -94,10 +86,6 @@ class PublishReleaseTask extends BaseReleaseTask {
94
86
await this . _promptStableVersionForNextTag ( ) ;
95
87
}
96
88
97
- // Ensure that we are authenticated, so that we can run "npm publish" for
98
- // each package once the release output is built.
99
- this . _checkNpmAuthentication ( ) ;
100
-
101
89
this . _buildReleasePackages ( ) ;
102
90
console . info ( chalk . green ( ` ✓ Built the release output.` ) ) ;
103
91
@@ -124,12 +112,8 @@ class PublishReleaseTask extends BaseReleaseTask {
124
112
// the user to interactively confirm that the script should continue.
125
113
await this . _promptConfirmReleasePublish ( ) ;
126
114
127
- // Prompt for the OTP right before publishing so that it doesn't expire while building the
128
- // packages.
129
- const npmOtp = await promptForNpmOtp ( ) ;
130
-
131
115
for ( let packageName of releasePackages ) {
132
- this . _publishPackageToNpm ( packageName , npmDistTag , npmOtp ) ;
116
+ this . _publishPackageToNpm ( packageName , npmDistTag ) ;
133
117
}
134
118
135
119
const newReleaseUrl = getGithubNewReleaseUrl ( {
@@ -144,17 +128,11 @@ class PublishReleaseTask extends BaseReleaseTask {
144
128
145
129
console . log ( ) ;
146
130
console . info ( chalk . green ( chalk . bold ( ` ✓ Published all packages successfully` ) ) ) ;
147
-
148
- // Always log out of npm after releasing to prevent unintentional changes to
149
- // any packages.
150
- if ( npmLogout ( ) ) {
151
- console . info ( chalk . green ( ` ✓ Logged out of npm` ) ) ;
152
- } else {
153
- console . error ( chalk . red ( ` ✘ Could not log out of NPM. Please manually log out!` ) ) ;
154
- }
155
-
156
131
console . info ( chalk . yellow ( ` ⚠ Please draft a new release of the version on Github.` ) ) ;
157
132
console . info ( chalk . yellow ( ` ${ newReleaseUrl } ` ) ) ;
133
+
134
+ // Remove file at ~/.npmrc after release is complete.
135
+ unlinkSync ( '~/.npmrc' ) ;
158
136
}
159
137
160
138
/**
@@ -205,45 +183,11 @@ class PublishReleaseTask extends BaseReleaseTask {
205
183
}
206
184
}
207
185
208
- /**
209
- * Checks whether NPM is currently authenticated. If not, the user will be prompted to enter
210
- * the NPM credentials that are necessary to publish the release. We achieve this by basically
211
- * running "npm login" as a child process and piping stdin/stdout/stderr to the current tty.
212
- */
213
- private _checkNpmAuthentication ( ) {
214
- if ( isNpmAuthenticated ( ) ) {
215
- console . info ( chalk . green ( ` ✓ NPM is authenticated.` ) ) ;
216
- return ;
217
- }
218
-
219
- let failedAuthentication = false ;
220
- console . log ( chalk . yellow ( ` ⚠ NPM is currently not authenticated. Running "npm login"..` ) ) ;
221
-
222
- for ( let i = 0 ; i < MAX_NPM_LOGIN_TRIES ; i ++ ) {
223
- if ( npmLoginInteractive ( ) ) {
224
- // In case the user was able to login properly, we want to exit the loop as we
225
- // don't need to ask for authentication again.
226
- break ;
227
- }
228
-
229
- failedAuthentication = true ;
230
- console . error ( chalk . red ( ` ✘ Could not authenticate successfully. Please try again.` ) ) ;
231
- }
232
-
233
- if ( failedAuthentication ) {
234
- console . error ( chalk . red ( ` ✘ Could not authenticate after ${ MAX_NPM_LOGIN_TRIES } tries. ` +
235
- `Exiting..` ) ) ;
236
- process . exit ( 1 ) ;
237
- }
238
-
239
- console . info ( chalk . green ( ` ✓ Successfully authenticated NPM.` ) ) ;
240
- }
241
-
242
186
/** Publishes the specified package within the given NPM dist tag. */
243
- private _publishPackageToNpm ( packageName : string , npmDistTag : string , npmOtp : string ) {
187
+ private _publishPackageToNpm ( packageName : string , npmDistTag : string ) {
244
188
console . info ( chalk . green ( ` ⭮ Publishing "${ packageName } "..` ) ) ;
245
189
246
- const errorOutput = npmPublish ( join ( this . releaseOutputPath , packageName ) , npmDistTag , npmOtp ) ;
190
+ const errorOutput = npmPublish ( join ( this . releaseOutputPath , packageName ) , npmDistTag ) ;
247
191
248
192
if ( errorOutput ) {
249
193
console . error ( chalk . red ( ` ✘ An error occurred while publishing "${ packageName } ".` ) ) ;
0 commit comments