Skip to content

Commit b2e2edf

Browse files
fuhao.xuisaacs
fuhao.xu
authored andcommitted
fix: npm publish --dry-run should not check login status
PR-URL: #2422 Credit: @buyan302 Close: #2422 Reviewed-by: @isaacs
1 parent 0fed44d commit b2e2edf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/publish.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ const publish = async args => {
4343
})
4444
}
4545

46-
const creds = npm.config.getCredentialsByURI(registry)
47-
if (!creds.token && !creds.username) {
48-
throw Object.assign(new Error('This command requires you to be logged in.'), {
49-
code: 'ENEEDAUTH',
50-
})
46+
if (!opts.dryRun) {
47+
const creds = npm.config.getCredentialsByURI(registry)
48+
if (!creds.token && !creds.username) {
49+
throw Object.assign(new Error('This command requires you to be logged in.'), {
50+
code: 'ENEEDAUTH',
51+
})
52+
}
5153
}
5254

5355
if (semver.validRange(defaultTag))

test/lib/publish.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ t.test('should log tarball contents', (t) => {
193193
dryRun: true,
194194
registry: 'https://registry.npmjs.org/',
195195
},
196-
config,
196+
config: {
197+
...config,
198+
getCredentialsByURI: () => {
199+
throw new Error('should not call getCredentialsByURI!')
200+
}},
197201
},
198202
'../../lib/utils/tar.js': {
199203
getContents: () => ({

0 commit comments

Comments
 (0)