mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
preserve tags when publishing something (ref #63)
This commit is contained in:
parent
bea03619d7
commit
6eada0f22e
9 changed files with 106 additions and 21 deletions
18
lib/index.js
18
lib/index.js
|
@ -215,7 +215,9 @@ module.exports = function(config_hash) {
|
|||
app.put('/:package/:tag', can('publish'), media('application/json'), function(req, res, next) {
|
||||
if (typeof(req.body) !== 'string') return next('route')
|
||||
|
||||
storage.add_tag(req.params.package, req.body, req.params.tag, function(err) {
|
||||
var tags = {}
|
||||
tags[req.params.tag] = req.body
|
||||
storage.add_tags(req.params.package, tags, function(err) {
|
||||
if (err) return next(err)
|
||||
res.status(201)
|
||||
return res.send({
|
||||
|
@ -293,9 +295,13 @@ module.exports = function(config_hash) {
|
|||
create_version(t2, metadata.versions[t2], function(err) {
|
||||
if (err) return next(err)
|
||||
|
||||
res.status(201)
|
||||
return res.send({
|
||||
ok: ok_message
|
||||
add_tags(metadata['dist-tags'], function(err) {
|
||||
if (err) return next(err)
|
||||
|
||||
res.status(201)
|
||||
return res.send({
|
||||
ok: ok_message
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -318,6 +324,10 @@ module.exports = function(config_hash) {
|
|||
function create_version(version, data, cb) {
|
||||
storage.add_version(name, version, data, null, cb)
|
||||
}
|
||||
|
||||
function add_tags(tags, cb) {
|
||||
storage.add_tags(name, tags, cb)
|
||||
}
|
||||
})
|
||||
|
||||
// unpublishing an entire package
|
||||
|
|
|
@ -134,13 +134,13 @@ Storage.prototype.update_versions = function(name, newdata, callback) {
|
|||
|
||||
if (verdata.dist && verdata.dist.tarball) {
|
||||
var url = utils.parse_tarball_url(
|
||||
verdata.dist.__sinopia_orig_tarball || verdata.dist.tarball
|
||||
/*verdata.dist.__sinopia_orig_tarball ||*/ verdata.dist.tarball
|
||||
)
|
||||
|
||||
// we do NOT overwrite any existing records
|
||||
if (url != null && data._distfiles[url.filename] == null) {
|
||||
data._distfiles[url.filename] = {
|
||||
url: verdata.dist.__sinopia_orig_tarball || verdata.dist.tarball,
|
||||
url: /*verdata.dist.__sinopia_orig_tarball ||*/ verdata.dist.tarball,
|
||||
sha: verdata.dist.shasum,
|
||||
}
|
||||
}
|
||||
|
@ -222,19 +222,21 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
|
|||
}, callback)
|
||||
}
|
||||
|
||||
Storage.prototype.add_tag = function(name, version, tag, callback) {
|
||||
Storage.prototype.add_tags = function(name, tags, callback) {
|
||||
var self = this
|
||||
|
||||
self.update_package(name, function updater(data, cb) {
|
||||
if (data.versions[version] == null) {
|
||||
return cb(new UError({
|
||||
status: 404,
|
||||
msg: "this version doesn't exist"
|
||||
}))
|
||||
}
|
||||
for (var t in tags) {
|
||||
if (data.versions[tags[t]] == null) {
|
||||
return cb(new UError({
|
||||
status: 404,
|
||||
msg: "this version doesn't exist"
|
||||
}))
|
||||
}
|
||||
|
||||
utils.tag_version(data, version, tag, self.config)
|
||||
cb()
|
||||
utils.tag_version(data, tags[t], t, self.config)
|
||||
cb()
|
||||
}
|
||||
}, callback)
|
||||
}
|
||||
|
||||
|
|
|
@ -122,8 +122,8 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
|
|||
//
|
||||
// Used storages: local (write)
|
||||
//
|
||||
Storage.prototype.add_tag = function(name, version, tag, callback) {
|
||||
return this.local.add_tag(name, version, tag, callback)
|
||||
Storage.prototype.add_tags = function(name, tag_hash, callback) {
|
||||
return this.local.add_tags(name, tag_hash, callback)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -301,7 +301,7 @@ Storage.prototype.get_package = function(name, options, callback) {
|
|||
if (whitelist.indexOf(i) === -1) delete result[i]
|
||||
}
|
||||
|
||||
if (self.config.ignore_latest_tag) {
|
||||
if (self.config.ignore_latest_tag || !result['dist-tags'].latest) {
|
||||
result['dist-tags'].latest = utils.semver_sort(Object.keys(result.versions))
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ module.exports.filter_tarball_urls = function(pkg, req, config) {
|
|||
for (var ver in pkg.versions) {
|
||||
var dist = pkg.versions[ver].dist
|
||||
if (dist != null && dist.tarball != null) {
|
||||
dist.__sinopia_orig_tarball = dist.tarball
|
||||
//dist.__sinopia_orig_tarball = dist.tarball
|
||||
dist.tarball = filter(dist.tarball)
|
||||
}
|
||||
}
|
||||
|
|
1
test/functional/fixtures/newnpmreg.json
Normal file
1
test/functional/fixtures/newnpmreg.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"_id":"testpkg-newnpmreg","name":"testpkg-newnpmreg","description":"","dist-tags":{"foo":"0.0.0","latest":"0.0.0"},"versions":{"0.0.0":{"name":"testpkg-newnpmreg","version":"0.0.0","description":"","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":""},"author":"","license":"ISC","_id":"testpkg-newnpmreg@0.0.0","dist":{"shasum":"8ee7331cbc641581b1a8cecd9d38d744a8feb863","tarball":"http://localhost:1234/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz"},"_from":".","_npmVersion":"1.3.1","_npmUser":{"name":"alex","email":"alex@kocharin.ru"},"maintainers":[{"name":"alex","email":"alex@kocharin.ru"}]}},"readme":"","maintainers":[{"name":"alex","email":"alex@kocharin.ru"}],"_attachments":{"testpkg-newnpmreg-0.0.0.tgz":{"content_type":"application/octet-stream","data":"H4sIAAAAAAAAA+2TsW7CMBCGM/spTh6YKHUSIJLXqkPnrixWcIMLsS3btCDEu/fs0Ba1SFVVVISUP8Odzqf/zlY+K+qlaOSt7eLo2RudnVmMsel4DBjzasKOY1JZlJDlRVkU5aSspnnG8pIVOZ6fe5FTWvsgHK7yV5/uLvARr0Q7qkUrKadB+mCXzY2Wr9q2TjZ0SF+k88poPGUj/LAyl752yoauioVWqJgpPZcb/Hmw0jV4ynfJEw9lvTAwo/fOGcdBG4h18FbW6knJ+YzCYAByowLkdD+kTlrjVTBumzy2Nq7XqIDea7eKY7FJrMPCuG6Hlaql9rHr4fGO7i/9pFcl+4X/rWhX557xA/9FVZ3gv+j5/w9F+jl8g58c0OeQyCdH3HOglETsObxTTw7McwLJClt+wzz5JD45IPEcEHjMEfg0r8M9pQfaOSDs5NLP16tXr15XqzeJD6m5AAwAAA==","length":352}}}
|
|
@ -43,7 +43,6 @@
|
|||
}
|
||||
},
|
||||
"dist-tags": {
|
||||
"latest": "5.4.3",
|
||||
"something": "0.1.1alpha",
|
||||
"bad": "1.1"
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ describe('Func', function() {
|
|||
require('./gzip')()
|
||||
require('./incomplete')()
|
||||
require('./mirror')()
|
||||
require('./newnpmreg')()
|
||||
require('./race')()
|
||||
require('./racycrash')()
|
||||
require('./security')()
|
||||
|
|
72
test/functional/newnpmreg.js
Normal file
72
test/functional/newnpmreg.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
var assert = require('assert')
|
||||
|
||||
function readfile(x) {
|
||||
return require('fs').readFileSync(__dirname + '/' + x)
|
||||
}
|
||||
|
||||
function sha(x) {
|
||||
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex')
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
var server = process.server
|
||||
var server2 = process.server2
|
||||
|
||||
describe('newnpmreg', function() {
|
||||
before(function(cb) {
|
||||
server.request({
|
||||
uri: '/testpkg-newnpmreg',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
method: 'PUT',
|
||||
json: JSON.parse(readfile('fixtures/newnpmreg.json')),
|
||||
}, function(err, res, body) {
|
||||
assert.equal(res.statusCode, 201)
|
||||
cb()
|
||||
})
|
||||
})
|
||||
|
||||
it('add pkg', function(){})
|
||||
|
||||
it('server1 - tarball', function(cb) {
|
||||
server.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
|
||||
cb()
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - tarball', function(cb) {
|
||||
server2.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
// not real sha due to utf8 conversion
|
||||
assert.strictEqual(sha(body), '789ca61e3426ce55c4983451b58e62b04abceaf6')
|
||||
cb()
|
||||
})
|
||||
})
|
||||
|
||||
it('server1 - package', function(cb) {
|
||||
server.get_package('testpkg-newnpmreg', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55551/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
||||
cb()
|
||||
})
|
||||
})
|
||||
|
||||
it('server2 - package', function(cb) {
|
||||
server2.get_package('testpkg-newnpmreg', function(res, body) {
|
||||
assert.equal(res.statusCode, 200)
|
||||
assert.equal(body.name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
||||
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55552/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
||||
cb()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
|
@ -32,7 +32,7 @@ module.exports = function() {
|
|||
assert.equal(typeof(body.versions['1.1']), 'object')
|
||||
assert.equal(body['dist-tags'].something, '0.1.1alpha')
|
||||
// note: 5.4.3 is invalid tag, 0.1.3alpha is highest semver
|
||||
assert.equal(body['dist-tags'].latest, '5.4.3')
|
||||
assert.equal(body['dist-tags'].latest, '0.1.3alpha')
|
||||
assert.equal(body['dist-tags'].bad, null)
|
||||
cb()
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue