From 6bf85dfe3f5f8a1ceb6c65847df13206d08077b3 Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Fri, 7 Feb 2020 04:10:14 -0300 Subject: [PATCH] Show registry URL before publishing (#485) Co-authored-by: Itai Steinherz --- source/npm/util.js | 13 ++++++++++++- source/ui.js | 10 ++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 6f8bc68a..f7011b2d 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -122,7 +122,18 @@ exports.checkIgnoreStrategy = ({files}) => { if (!files && !npmignoreExists) { console.log(` - \n${chalk.bold.yellow('Warning:')} No ${chalk.bold.cyan('files')} field specified in ${chalk.bold.magenta('package.json')} nor is a ${chalk.bold.magenta('.npmignore')} file present. Having one of those will prevent you from accidentally publishing development-specific files along with your package's source code to npm. + \n${chalk.bold.yellow('Warning:')} No ${chalk.bold.cyan('files')} field specified in ${chalk.bold.magenta('package.json')} nor is a ${chalk.bold.magenta('.npmignore')} file present. Having one of those will prevent you from accidentally publishing development-specific files along with your package's source code to npm. `); } }; + +exports.getRegistryUrl = async (pkgManager, pkg) => { + const args = ['config', 'get', 'registry']; + if (exports.isExternalRegistry(pkg)) { + args.push('--registry'); + args.push(pkg.publishConfig.registry); + } + + const {stdout} = await execa(pkgManager, args); + return stdout; +}; diff --git a/source/ui.js b/source/ui.js index 65ada8d8..d516da14 100644 --- a/source/ui.js +++ b/source/ui.js @@ -5,11 +5,11 @@ const githubUrlFromGit = require('github-url-from-git'); const isScoped = require('is-scoped'); const util = require('./util'); const git = require('./git-util'); -const {prereleaseTags, checkIgnoreStrategy} = require('./npm/util'); +const {prereleaseTags, checkIgnoreStrategy, getRegistryUrl} = require('./npm/util'); const version = require('./version'); const prettyVersionDiff = require('./pretty-version-diff'); -const printCommitLog = async repoUrl => { +const printCommitLog = async (repoUrl, registryUrl) => { const latest = await git.latestTagOrFirstCommit(); const log = await git.commitLogFromRevision(latest); @@ -41,7 +41,7 @@ const printCommitLog = async repoUrl => { const commitRange = util.linkifyCommitRange(repoUrl, `${latest}...master`); - console.log(`${chalk.bold('Commits:')}\n${history}\n\n${chalk.bold('Commit Range:')}\n${commitRange}\n`); + console.log(`${chalk.bold('Commits:')}\n${history}\n\n${chalk.bold('Commit Range:')}\n${commitRange}\n\n${chalk.bold('Registry:')}\n${registryUrl}\n`); return { hasCommits: true, @@ -53,6 +53,8 @@ module.exports = async (options, pkg) => { const oldVersion = pkg.version; const extraBaseUrls = ['gitlab.com']; const repoUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls}); + const pkgManager = options.yarn ? 'yarn' : 'npm'; + const registryUrl = await getRegistryUrl(pkgManager, pkg); const runPublish = options.publish && !pkg.private; if (runPublish) { @@ -143,7 +145,7 @@ module.exports = async (options, pkg) => { } ]; - const {hasCommits, releaseNotes} = await printCommitLog(repoUrl); + const {hasCommits, releaseNotes} = await printCommitLog(repoUrl, registryUrl); if (options.version) { return {