Skip to content

Commit

Permalink
fix(publish): follow config for registry auth check
Browse files Browse the repository at this point in the history
The "do you have auth configured" only takes into consideration a hard-coded
"registry" config, which means that if you don't have auth configured for
the npm registry, but you do for the one you have tied to a scope elsewhere
in your npmrc, we would erroneously tell you that to add a token.

This uses the same method that the rest of the publish chain uses to determine
which registry it would be publishing to, then sees if you have auth for THAT registry.

Because that other function does a hard fallback to the npm registry, there is no more
need for the exception we throw if you do not have one configured.  Also, the npm cli
already defaults that config item, so you can't even set it to a falsey value if you
wanted
  • Loading branch information
wraithgar committed Feb 2, 2021
1 parent c1589c1 commit a8e6155
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/publish.js
Expand Up @@ -6,6 +6,7 @@ const libpub = require('libnpmpublish').publish
const runScript = require('@npmcli/run-script')
const pacote = require('pacote')
const npa = require('npm-package-arg')
const npmFetch = require('npm-registry-fetch')

const npm = require('./npm.js')
const output = require('./utils/output.js')
Expand Down Expand Up @@ -76,12 +77,8 @@ 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',
})
}
const resolved = npa.resolve(manifest.name, manifest.version)
const registry = npmFetch.pickRegistry(resolved, opts)

if (!dryRun) {
const creds = npm.config.getCredentialsByURI(registry)
Expand Down

0 comments on commit a8e6155

Please sign in to comment.