File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,10 @@ updateNotifier({pkg: cli.pkg}).notify();
97
97
98
98
const runPublish = flags . publish && ! pkg . private ;
99
99
100
- const availability = await isPackageNameAvailable ( pkg ) ;
100
+ const availability = flags . publish ? await isPackageNameAvailable ( pkg ) : {
101
+ isAvailable : false ,
102
+ isUnknown : false
103
+ } ;
101
104
102
105
const version = cli . input . length > 0 ? cli . input [ 0 ] : false ;
103
106
Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ module.exports = async (input = 'patch', options) => {
215
215
] ) ;
216
216
217
217
const isExternalRegistry = npm . isExternalRegistry ( pkg ) ;
218
- if ( ! options . exists && ! pkg . private && ! isExternalRegistry ) {
218
+ if ( options . availability . isAvailable && ! options . availability . isUnknown && ! pkg . private && ! isExternalRegistry ) {
219
219
tasks . add ( [
220
220
{
221
221
title : 'Enabling two-factor authentication' ,
Original file line number Diff line number Diff line change 1
1
import test from 'ava' ;
2
+ import sinon from 'sinon' ;
3
+ import proxyquire from 'proxyquire' ;
2
4
import np from '../source' ;
3
5
4
6
const defaultOptions = {
5
7
cleanup : true ,
6
8
tests : true ,
7
9
publish : true ,
8
- runPublish : true
10
+ runPublish : true ,
11
+ availability : {
12
+ isAvailable : false ,
13
+ isUnknown : false
14
+ }
9
15
} ;
10
16
11
17
test ( 'version is invalid' , async t => {
@@ -28,3 +34,30 @@ test('errors on too low version', async t => {
28
34
await t . throwsAsync ( np ( '1.0.0' , defaultOptions ) , / N e w v e r s i o n ` 1 \. 0 \. 0 ` s h o u l d b e h i g h e r t h a n c u r r e n t v e r s i o n ` \d + \. \d + \. \d + ` / ) ;
29
35
await t . throwsAsync ( np ( '1.0.0-beta' , defaultOptions ) , / N e w v e r s i o n ` 1 \. 0 \. 0 - b e t a ` s h o u l d b e h i g h e r t h a n c u r r e n t v e r s i o n ` \d + \. \d + \. \d + ` / ) ;
30
36
} ) ;
37
+
38
+ test ( 'skip enabling 2FA if the package exists' , async t => {
39
+ const enable2faStub = sinon . stub ( ) ;
40
+
41
+ const np = proxyquire ( '../source' , {
42
+ del : sinon . stub ( ) ,
43
+ execa : sinon . stub ( ) . returns ( { pipe : sinon . stub ( ) } ) ,
44
+ './prerequisite-tasks' : sinon . stub ( ) ,
45
+ './git-tasks' : sinon . stub ( ) ,
46
+ './git-util' : {
47
+ hasUpstream : sinon . stub ( ) . returns ( true ) ,
48
+ push : sinon . stub ( )
49
+ } ,
50
+ './npm/enable-2fa' : enable2faStub ,
51
+ './npm/publish' : sinon . stub ( ) . returns ( { pipe : sinon . stub ( ) } )
52
+ } ) ;
53
+
54
+ await t . notThrowsAsync ( np ( '1.0.0' , {
55
+ ...defaultOptions ,
56
+ availability : {
57
+ isAvailable : false ,
58
+ isUnknown : false
59
+ }
60
+ } ) ) ;
61
+
62
+ t . true ( enable2faStub . notCalled ) ;
63
+ } ) ;
You can’t perform that action at this time.
0 commit comments