Skip to content

Commit

Permalink
fix: publish: delay registry & login check till publishConfig merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-js authored and nlf committed Jan 28, 2021
1 parent f1bea2f commit 938a77d
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/publish.js
Expand Up @@ -35,22 +35,7 @@ const publish = async args => {
log.verbose('publish', args)

const opts = { ...npm.flatOptions }
const { json, defaultTag, registry } = opts

if (!registry) {
throw Object.assign(new Error('No registry specified.'), {
code: 'ENOREGISTRY',
})
}

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',
})
}
}
const { json, defaultTag } = opts

if (semver.validRange(defaultTag))
throw new Error('Tag name must not be a valid SemVer range: ' + defaultTag.trim())
Expand Down Expand Up @@ -91,6 +76,22 @@ const publish_ = async (arg, opts) => {
if (manifest.publishConfig)
Object.assign(opts, publishConfigToOpts(manifest.publishConfig))

const { registry } = opts
if (!registry) {
throw Object.assign(new Error('No registry specified.'), {
code: 'ENOREGISTRY',
})
}

if (!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',
})
}
}

// only run scripts for directory type publishes
if (spec.type === 'directory') {
await runScript({
Expand Down

0 comments on commit 938a77d

Please sign in to comment.