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

Commit b718f19

Browse files
vovacodeschristophwitzko
authored andcommitted
fix: properly handle completely unpublished packages (#113)
1 parent 79e992f commit b718f19

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,29 @@ module.exports = function (pluginConfig, {pkg, npm, plugins, options}, cb) {
1212
client.get(`${npm.registry}${pkg.name.replace('/', '%2F')}`, {
1313
auth: npm.auth
1414
}, (err, data) => {
15-
if (err && (
16-
err.statusCode === 404 ||
17-
/not found/i.test(err.message)
18-
)) {
15+
const isNotFound = err && (err.statusCode === 404 || /not found/i.test(err.message))
16+
const isCompletelyUnpublished = data && !data['dist-tags']
17+
18+
if (isNotFound || isCompletelyUnpublished) {
1919
return cb(null, {})
2020
}
2121

2222
if (err) return cb(err)
2323

24-
let version = data['dist-tags'][npm.tag]
24+
const distTags = data['dist-tags']
25+
let version = distTags[npm.tag]
2526

2627
if (!version &&
2728
options &&
2829
options.fallbackTags &&
2930
options.fallbackTags[npm.tag] &&
30-
data['dist-tags'][options.fallbackTags[npm.tag]]) {
31-
version = data['dist-tags'][options.fallbackTags[npm.tag]]
31+
distTags[options.fallbackTags[npm.tag]]) {
32+
version = distTags[options.fallbackTags[npm.tag]]
3233
}
3334

3435
if (!version) {
3536
return cb(new SemanticReleaseError(
36-
`There is no release with the dist-tag "${npm.tag}" yet.
37+
`There is no release with the dist-tag "${npm.tag}" yet.
3738
Tag a version manually or define "fallbackTags".`, 'ENODISTTAG'))
3839
}
3940

test/mocks/registry.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ const availableModule = {
1515
}
1616
}
1717

18+
const completelyUnpublishedModule = {
19+
name: 'i-am-completely-unpublished',
20+
time: {
21+
'2.0.0': '2016-12-01T17:50:30.699Z',
22+
unpublished: {
23+
time: '2016-12-01T17:53:45.940Z'
24+
}
25+
}
26+
}
27+
1828
module.exports = nock('http://registry.npmjs.org')
1929
.get('/available')
2030
.reply(200, availableModule)
@@ -25,6 +35,8 @@ module.exports = nock('http://registry.npmjs.org')
2535
.reply(200, availableModule)
2636
.get('/@scoped%2Favailable')
2737
.reply(200, availableModule)
38+
.get('/completely-unpublished')
39+
.reply(200, completelyUnpublishedModule)
2840
.get('/unavailable')
2941
.reply(404, {})
3042
.get('/unavailable-no-body')

test/specs/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const npm = {
1111
}
1212

1313
test('last release from registry', (t) => {
14-
t.plan(6)
14+
t.plan(7)
1515

1616
t.test('get release from package name', (tt) => {
1717
lastRelease({}, {
@@ -85,6 +85,17 @@ test('last release from registry', (t) => {
8585
})
8686
})
8787

88+
t.test('get nothing from completely unpublished package name', (tt) => {
89+
lastRelease({}, {
90+
pkg: {name: 'completely-unpublished'},
91+
npm
92+
}, (err, release) => {
93+
tt.error(err)
94+
tt.is(release.version, undefined, 'no version')
95+
tt.end()
96+
})
97+
})
98+
8899
t.test('get nothing from not yet published package name', (tt) => {
89100
tt.plan(3)
90101

0 commit comments

Comments
 (0)