From 938a77d6e7fb79f8ceb72c51bf06e27127fb9f06 Mon Sep 17 00:00:00 2001 From: dr-js Date: Fri, 8 Jan 2021 09:46:57 +0800 Subject: [PATCH] fix: publish: delay registry & login check till publishConfig merge --- lib/publish.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/publish.js b/lib/publish.js index 8ef7eff4c8a64..49b2088070e7a 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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()) @@ -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({