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

Commit a2cdc29

Browse files
committed
fix: Accept registry URL with or without a trailing slash
1 parent 554ff1c commit a2cdc29

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {promisify} = require('util');
2+
const {resolve} = require('url');
23
const SemanticReleaseError = require('@semantic-release/error');
34
const RegClient = require('npm-registry-client');
45
const npmlog = require('npmlog');
@@ -7,7 +8,7 @@ module.exports = async function({retry} = {}, {pkg, npm, options}, cb) {
78
npmlog.level = npm.loglevel || 'warn';
89
const client = new RegClient({log: npmlog, retry});
910
try {
10-
const data = await promisify(client.get.bind(client))(`${npm.registry}${pkg.name.replace('/', '%2F')}`, {
11+
const data = await promisify(client.get.bind(client))(resolve(npm.registry, pkg.name.replace('/', '%2F')), {
1112
auth: npm.auth,
1213
});
1314
if (data && !data['dist-tags']) {

test/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,17 @@ test.serial('Accept an undefined "pluginConfig"', async t => {
134134
t.is(release.tag, 'latest');
135135
t.true(registry.isDone());
136136
});
137+
138+
test.serial('Handle missing trailing slash on registry URL', async t => {
139+
const name = 'available';
140+
const registry = available(name);
141+
const release = await promisify(lastRelease)(
142+
{},
143+
{pkg: {name}, npm: defaults({registry: 'http://registry.npmjs.org'}, npm)}
144+
);
145+
146+
t.is(release.version, '1.33.7');
147+
t.is(release.gitHead, 'HEAD');
148+
t.is(release.tag, 'latest');
149+
t.true(registry.isDone());
150+
});

0 commit comments

Comments
 (0)