Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Commit

Permalink
fix: Accept registry URL with or without a trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Oct 3, 2017
1 parent 554ff1c commit a2cdc29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {promisify} = require('util');
const {resolve} = require('url');
const SemanticReleaseError = require('@semantic-release/error');
const RegClient = require('npm-registry-client');
const npmlog = require('npmlog');
Expand All @@ -7,7 +8,7 @@ module.exports = async function({retry} = {}, {pkg, npm, options}, cb) {
npmlog.level = npm.loglevel || 'warn';
const client = new RegClient({log: npmlog, retry});
try {
const data = await promisify(client.get.bind(client))(`${npm.registry}${pkg.name.replace('/', '%2F')}`, {
const data = await promisify(client.get.bind(client))(resolve(npm.registry, pkg.name.replace('/', '%2F')), {
auth: npm.auth,
});
if (data && !data['dist-tags']) {
Expand Down
14 changes: 14 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ test.serial('Accept an undefined "pluginConfig"', async t => {
t.is(release.tag, 'latest');
t.true(registry.isDone());
});

test.serial('Handle missing trailing slash on registry URL', async t => {
const name = 'available';
const registry = available(name);
const release = await promisify(lastRelease)(
{},
{pkg: {name}, npm: defaults({registry: 'http://registry.npmjs.org'}, npm)}
);

t.is(release.version, '1.33.7');
t.is(release.gitHead, 'HEAD');
t.is(release.tag, 'latest');
t.true(registry.isDone());
});

0 comments on commit a2cdc29

Please sign in to comment.