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
  • Loading branch information
fuhao.xu committed Dec 29, 2020
1 parent 7282329 commit cb85c6a
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 cb85c6a

Please sign in to comment.