Skip to content

Commit

Permalink
Add external registry support to authentication check (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored and sindresorhus committed Mar 15, 2019
1 parent cc56c0c commit 72ebf7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions source/npm-util.js
Expand Up @@ -16,9 +16,15 @@ exports.checkConnection = () => pTimeout(
'Connection to npm registry timed out'
);

exports.username = async () => {
exports.username = async ({externalRegistry}) => {
const args = ['whoami'];

if (externalRegistry) {
args.push('--registry', externalRegistry);
}

try {
return await execa.stdout('npm', ['whoami']);
return await execa.stdout('npm', args);
} catch (error) {
throw new Error(/ENEEDAUTH/.test(error.stderr) ?
'You must be logged in. Use `npm login` and try again.' :
Expand Down
6 changes: 4 additions & 2 deletions source/prerequisite-tasks.js
Expand Up @@ -28,9 +28,11 @@ module.exports = (input, pkg, options) => {
},
{
title: 'Verify user is authenticated',
skip: () => process.env.NODE_ENV === 'test' || pkg.private || isExternalRegistry,
skip: () => process.env.NODE_ENV === 'test' || pkg.private,
task: async () => {
const username = await npm.username();
const username = await npm.username({
externalRegistry: isExternalRegistry ? pkg.publishConfig.registry : false
});

const collaborators = await npm.collaborators(pkg.name);
if (!collaborators) {
Expand Down

0 comments on commit 72ebf7d

Please sign in to comment.