Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
cache: Make "*" match "latest" if all versions are prerelease
Browse files Browse the repository at this point in the history
Fixes: #8855
PR-URL: #8857
  • Loading branch information
iarna authored and othiym23 committed Jul 9, 2015
1 parent 22fdc1d commit 5125856
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/cache/add-named.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ function addNameRange (name, range, data, cb) {
var versions = Object.keys(data.versions || {})
var ms = semver.maxSatisfying(versions, range, true)
if (!ms) {
return cb(installTargetsError(range, data))
if (range === "*" && versions.length) {
return addNameTag(name, "latest", data, cb)
} else {
return cb(installTargetsError(range, data))
}
}

// if we don't have a registry connection, try to see if
Expand Down
81 changes: 81 additions & 0 deletions test/tap/splat-with-only-prerelease-to-latest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict'
var test = require('tap').test
var npm = require('../../lib/npm')
var log = require('npmlog')
var stream = require('readable-stream')

var moduleName = 'xyzzy-wibble'
var testModule = {
name: moduleName,
'dist-tags': {
latest: '1.3.0-a'
},
versions: {
'1.0.0-a': {
name: moduleName,
version: '1.0.0-a',
dist: {
shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.0.0-a.tgz'
}
},
'1.1.0-a': {
name: moduleName,
version: '1.1.0-a',
dist: {
shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.1.0-a.tgz'
}
},
'1.2.0-a': {
name: moduleName,
version: '1.2.0-a',
dist: {
shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.2.0-a.tgz'
}
},
'1.3.0-a': {
name: moduleName,
version: '1.3.0-a',
dist: {
shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz'
}
},
},
}

var lastFetched
test('setup', function (t) {
npm.load(function(){
npm.config.set('loglevel', 'silly')
npm.registry = {
get: function (uri, opts, cb) {
setImmediate(function () {
cb(null, testModule, null, {statusCode: 200})
})
},
fetch: function (u, opts, cb) {
lastFetched = u
setImmediate(function () {
var empty = new stream.Readable()
empty.push(null)
cb(null, empty)
})
}
}
t.end()
})
})


test('splat', function (t) {
t.plan(3)
var addNamed = require('../../lib/cache/add-named.js')
addNamed('xyzzy-wibble', '*', testModule, function (err, pkg) {
t.error(err, 'Succesfully resolved a splat package')
t.is(pkg.name, moduleName)
t.is(pkg.version, testModule['dist-tags'].latest)
})
})

0 comments on commit 5125856

Please sign in to comment.