Skip to content

Commit b2e2edf

Browse files
fuhao.xuisaacs
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

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

lib/publish.js

Lines changed: 7 additions & 5 deletions
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

Lines changed: 5 additions & 1 deletion
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)