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

Commit 300aa6f

Browse files
committed
feat: add support for fallbackTags
1 parent a27b5ab commit 300aa6f

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const SemanticReleaseError = require('@semantic-release/error')
33
const npmlog = require('npmlog')
44
const RegClient = require('npm-registry-client')
55

6-
module.exports = function (pluginConfig, {pkg, npm, plugins}, cb) {
6+
module.exports = function (pluginConfig, {pkg, npm, plugins, options}, cb) {
77
npmlog.level = npm.loglevel || 'warn'
88
let clientConfig = {log: npmlog}
99
// disable retries for tests
@@ -22,9 +22,21 @@ module.exports = function (pluginConfig, {pkg, npm, plugins}, cb) {
2222

2323
if (err) return cb(err)
2424

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

27-
if (!version) return cb(new SemanticReleaseError(`There is no release with the dist-tag "${npm.tag}" yet. Tag a version first.`, 'ENODISTTAG'))
27+
if (!version &&
28+
options &&
29+
options.fallbackTags &&
30+
options.fallbackTags[npm.tag] &&
31+
data['dist-tags'][options.fallbackTags[npm.tag]]) {
32+
version = data['dist-tags'][options.fallbackTags[npm.tag]]
33+
}
34+
35+
if (!version) {
36+
return cb(new SemanticReleaseError(
37+
`There is no release with the dist-tag "${npm.tag}" yet.
38+
Tag a version manually or define "fallbackTags".`, 'ENODISTTAG'))
39+
}
2840

2941
cb(null, {
3042
version,

test/mocks/registry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = nock('http://registry.npmjs.org')
1919
.get('/available')
2020
.reply(200, availableModule)
2121
.get('/tagged')
22+
.times(2)
2223
.reply(200, availableModule)
2324
.get('/untagged')
2425
.reply(200, availableModule)

test/specs/index.js

Lines changed: 20 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(5)
14+
t.plan(6)
1515

1616
t.test('get release from package name', (tt) => {
1717
lastRelease({}, {
@@ -41,6 +41,25 @@ test('last release from registry', (t) => {
4141
})
4242
})
4343

44+
t.test('get release from a fallbackTag', (tt) => {
45+
lastRelease({}, {
46+
pkg: {name: 'tagged'},
47+
options: {
48+
fallbackTags: {
49+
bar: 'latest'
50+
}
51+
},
52+
npm: defaults({tag: 'bar'}, npm)
53+
}, (err, release) => {
54+
tt.error(err)
55+
tt.is(release.version, '1.33.7', 'version')
56+
tt.is(release.gitHead, 'HEAD', 'gitHead')
57+
tt.is(release.tag, 'bar', 'dist-tag')
58+
59+
tt.end()
60+
})
61+
})
62+
4463
t.test('get error from an untagged package\'s name', (tt) => {
4564
lastRelease({}, {
4665
pkg: {name: 'untagged'},

0 commit comments

Comments
 (0)