Skip to content

Commit

Permalink
fix: npm publish --dry-run should not check login status
Browse files Browse the repository at this point in the history
PR-URL: #2422
Credit: @buyan302
Close: #2422
Reviewed-by: @isaacs
  • Loading branch information
fuhao.xu authored and isaacs committed Jan 7, 2021
1 parent 0fed44d commit b2e2edf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/publish.js
Expand Up @@ -43,11 +43,13 @@ const publish = async args => {
})
}

const creds = npm.config.getCredentialsByURI(registry)
if (!creds.token && !creds.username) {
throw Object.assign(new Error('This command requires you to be logged in.'), {
code: 'ENEEDAUTH',
})
if (!opts.dryRun) {
const creds = npm.config.getCredentialsByURI(registry)
if (!creds.token && !creds.username) {
throw Object.assign(new Error('This command requires you to be logged in.'), {
code: 'ENEEDAUTH',
})
}
}

if (semver.validRange(defaultTag))
Expand Down
6 changes: 5 additions & 1 deletion test/lib/publish.js
Expand Up @@ -193,7 +193,11 @@ t.test('should log tarball contents', (t) => {
dryRun: true,
registry: 'https://registry.npmjs.org/',
},
config,
config: {
...config,
getCredentialsByURI: () => {
throw new Error('should not call getCredentialsByURI!')
}},
},
'../../lib/utils/tar.js': {
getContents: () => ({
Expand Down

0 comments on commit b2e2edf

Please sign in to comment.