mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-25 02:32:52 -05:00
making latest tag behaviour configurable
This commit is contained in:
parent
4b06026d2e
commit
4470cb7d55
5 changed files with 21 additions and 10 deletions
|
@ -109,6 +109,9 @@ function Config(config) {
|
|||
this.server_id = crypto.pseudoRandomBytes(6).toString('hex')
|
||||
}
|
||||
|
||||
// default for sinopia 0.7.x, may be changed in the future
|
||||
if (this.ignore_latest_tag == null) this.ignore_latest_tag = true
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
|
|
@ -318,9 +318,7 @@ module.exports = function(config_hash) {
|
|||
}
|
||||
|
||||
function create_version(version, data, cb) {
|
||||
// assume latest tag, it's ignored anyway
|
||||
// if you want tags, tag packages explicitly
|
||||
storage.add_version(name, version, data, 'latest', cb)
|
||||
storage.add_version(name, version, data, null, cb)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
|
|||
}
|
||||
|
||||
data.versions[version] = metadata
|
||||
utils.tag_version(data, version, tag)
|
||||
utils.tag_version(data, version, tag, self.config)
|
||||
cb()
|
||||
}, callback)
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ Storage.prototype.add_tag = function(name, version, tag, callback) {
|
|||
}))
|
||||
}
|
||||
|
||||
utils.tag_version(data, version, tag)
|
||||
utils.tag_version(data, version, tag, self.config)
|
||||
cb()
|
||||
}, callback)
|
||||
}
|
||||
|
|
|
@ -301,7 +301,10 @@ Storage.prototype.get_package = function(name, options, callback) {
|
|||
if (whitelist.indexOf(i) === -1) delete result[i]
|
||||
}
|
||||
|
||||
// ensure that latest tag is always present,
|
||||
// this can be overridden with dist-tags
|
||||
result['dist-tags'].latest = utils.semver_sort(Object.keys(result.versions))
|
||||
|
||||
for (var i in result['dist-tags']) {
|
||||
if (Array.isArray(result['dist-tags'][i])) {
|
||||
result['dist-tags'][i] = result['dist-tags'][i][result['dist-tags'][i].length-1]
|
||||
|
@ -376,7 +379,7 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,
|
|||
}
|
||||
|
||||
try {
|
||||
Storage._merge_versions(pkginfo, up_res)
|
||||
Storage._merge_versions(pkginfo, up_res, self.config)
|
||||
} catch(err) {
|
||||
self.logger.error({
|
||||
sub: 'out',
|
||||
|
@ -409,7 +412,7 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options,
|
|||
|
||||
// function gets a local info and an info from uplinks and tries to merge it
|
||||
// exported for unit tests only
|
||||
Storage._merge_versions = function(local, up) {
|
||||
Storage._merge_versions = function(local, up, config) {
|
||||
// copy new versions to a cache
|
||||
// NOTE: if a certain version was updated, we can't refresh it reliably
|
||||
for (var i in up.versions) {
|
||||
|
@ -420,7 +423,7 @@ Storage._merge_versions = function(local, up) {
|
|||
|
||||
// refresh dist-tags
|
||||
for (var i in up['dist-tags']) {
|
||||
utils.tag_version(local, up['dist-tags'][i], i)
|
||||
utils.tag_version(local, up['dist-tags'][i], i, config || {})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
lib/utils.js
11
lib/utils.js
|
@ -91,8 +91,15 @@ module.exports.filter_tarball_urls = function(pkg, req, config) {
|
|||
return pkg
|
||||
}
|
||||
|
||||
module.exports.tag_version = function(data, version, tag) {
|
||||
if (tag === 'latest') return
|
||||
function can_add_tag(tag, config) {
|
||||
if (!tag) return false
|
||||
if (tag === 'latest' && config.ignore_latest_tag) return false
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports.tag_version = function(data, version, tag, config) {
|
||||
if (!can_add_tag(tag, config)) return
|
||||
|
||||
switch(typeof(data['dist-tags'][tag])) {
|
||||
case 'string':
|
||||
data['dist-tags'][tag] = [data['dist-tags'][tag]]
|
||||
|
|
Loading…
Add table
Reference in a new issue