Skip to content

Commit

Permalink
fix(alpha): filter out alpha releases, close #106
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jul 6, 2017
1 parent 7d61c7e commit 282c95e
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
45 changes: 45 additions & 0 deletions __snapshots__/registry-spec.js.snap-shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
exports['hasVersions 1'] = [
{
"name": "foo",
"versions": [
"1.0.0",
"1.0.1"
]
},
{
"name": "baz",
"versions": [
"3.0.0-alpha"
]
}
]

exports['filters out empty versions 1'] = [
{
"name": "foo",
"versions": [
"1.0.0",
"1.0.1"
]
}
]

exports['filters latest versions 1'] = [
{
"name": "foo",
"versions": [
"1.0.1"
]
}
]

exports['filters out alpha releases 1'] = [
{
"name": "foo",
"versions": [
"1.0.0",
"1.0.1"
]
}
]

48 changes: 45 additions & 3 deletions src/registry-spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
// @ts-check
const snapShot = require('snap-shot')
const {filterFetchedVersions, hasVersions} = require('./registry')
const check = require('check-more-types')
const la = require('lazy-ass')

/* global describe, it */
describe.only('registry', () => {
describe('filtering fetched updates', () => {
it('write test', () => {
describe('registry', () => {
describe('filterFetchedVersions', () => {
const foo = {
name: 'foo',
versions: ['1.0.0', '1.0.1']
}
const bar = {
name: 'bar',
versions: []
}
const baz = {
name: 'baz',
versions: ['3.0.0-alpha']
}
const available = [foo, bar, baz]

it('detects empty array property', () => {
la(check.array(bar.versions), 'has versions')
la(!check.unempty(bar.versions), 'is empty', bar.versions)
})

it('hasVersions', () => {
const filtered = available.filter(hasVersions)
snapShot(filtered)
})

it('filters out empty versions', () => {
const filtered = filterFetchedVersions(false, available)
snapShot(filtered)
})

it('filters latest versions', () => {
const filtered = filterFetchedVersions(true, available)
snapShot(filtered)
})

it('filters out alpha releases', () => {
// make sure to filter out alpha releases
// after fetching
// https://github.com/bahmutov/next-update/issues/106
const filtered = filterFetchedVersions(false, available)
snapShot(filtered)
})
})
})
27 changes: 20 additions & 7 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ var q = require('q')
var localVersion = require('./local-module-version')
var isUrl = require('npm-utils').isUrl
var _ = require('lodash')
const {isPrerelease} = require('./utils')

var _registryUrl = require('npm-utils').registryUrl
la(check.fn(_registryUrl), 'expected registry url function')
var registryUrl = _.once(_registryUrl)

const notPrerelease = R.complement(isPrerelease)

function cleanVersion (version, name) {
var originalVersion = version
verify.unemptyString(version, 'missing version string' + version)
Expand Down Expand Up @@ -271,15 +274,23 @@ function logFetched (fetched) {
const hasVersions = nameNewVersions =>
nameNewVersions &&
check.array(nameNewVersions.versions) &&
check.unempty(nameNewVersions)
check.unempty(nameNewVersions.versions)

const filterVersions = R.evolve({
versions: R.filter(notPrerelease)
})

function filterFetchedVersions (checkLatestOnly, results) {
la(arguments.length === 2, 'expected two arguments', arguments)
checkLatestOnly = Boolean(checkLatestOnly)
check.verify.array(results, 'expected list of results')
log('fetch all new version results')
logFetched(results)

let available = results.filter(hasVersions)
let available = results
.map(filterVersions)
.filter(hasVersions)

if (checkLatestOnly) {
available = available.map(function (nameVersions) {
if (nameVersions.versions.length > 1) {
Expand Down Expand Up @@ -315,9 +326,11 @@ function nextVersions (options, nameVersionPairs, checkLatestOnly) {
}

module.exports = {
isUrl: isUrl,
cleanVersion: cleanVersion,
cleanVersions: cleanVersions,
fetchVersions: fetchVersions,
nextVersions: nextVersions
isUrl,
cleanVersion,
cleanVersions,
fetchVersions,
nextVersions,
filterFetchedVersions,
hasVersions
}

0 comments on commit 282c95e

Please sign in to comment.