Skip to content

Commit

Permalink
feat(without): skip testing some modules using --without option, close
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jun 26, 2017
1 parent 3eeb370 commit 955f7cd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bin/next-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ if (program.available) {
keep: program.keep,
allow: allow,
type: program.type,
tldr: program.tldr
tldr: program.tldr,
without: program.without
}

var checkCurrent = nextUpdate.checkCurrentInstall.bind(null, opts)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"lodash": "3.10.1",
"npm-utils": "1.7.1",
"optimist": "0.6.1",
"pluralize": "5.0.0",
"q": "2.0.3",
"quote": "0.4.0",
"ramda": "0.24.1",
Expand Down
21 changes: 19 additions & 2 deletions src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var print = require('./print-modules-table')
var nameVersionParser = require('./moduleName')
var getKnownDependencies = require('./get-known-dependencies')
const {getSkippedModules} = require('./utils')
const pluralize = require('pluralize')

require('console.table')
var _ = require('lodash')
Expand Down Expand Up @@ -41,6 +42,7 @@ function printTable (options, nameVersionPairs) {
? nameVersionPairs
: _.filter(nameVersionPairs, { type: allowedType })

// TODO just use Ramda project
console.table(title, _.map(filtered, function (nameVersion) {
return {
module: nameVersion.name,
Expand Down Expand Up @@ -80,9 +82,14 @@ function normalizeModuleNames (moduleNames) {

function getDependenciesToCheck (options, moduleNames) {
check.verify.object(options, 'missing options')
debug('initial module names', moduleNames)
debug('get dependencies for options')
debug(options)
moduleNames = normalizeModuleNames(moduleNames)
debug('normalized module names', moduleNames)
if (moduleNames) {
debug('normalized module names', moduleNames)
} else {
debug('no --module filter')
}

var workingDirectory = process.cwd()

Expand All @@ -97,6 +104,16 @@ function getDependenciesToCheck (options, moduleNames) {
}
nameVersionPairs = remove(nameVersionPairs, skipModules)
}
if (options.without) {
la(check.array(options.without),
'without should be an array', options.without)
if (check.unempty(options.without)) {
debug('checking without %s %s',
pluralize('module', options.without.length),
options.without.join(', '))
nameVersionPairs = remove(nameVersionPairs, options.without)
}
}
printTable(options, nameVersionPairs)

var toCheck = nameVersionPairs
Expand Down
3 changes: 2 additions & 1 deletion src/next-update-as-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = function nextUpdateTopLevel (options) {
allow: options.allow || options.allowed,
type: options.type,
changedLog: options['changed-log'],
limit: is.maybe.fn(options.limit) ? options.limit : T
limit: is.maybe.fn(options.limit) ? options.limit : T,
without: options.without
}

const checkUpdates = nextUpdate.checkAllUpdates.bind(null, opts)
Expand Down
4 changes: 4 additions & 0 deletions src/next-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ function checkAllUpdates (options) {
console.log('will check only latest versions because testing all')
}

if (check.string(options.without)) {
options.without = [options.without]
}

if (check.string(moduleName)) {
moduleName = [moduleName]
}
Expand Down
21 changes: 17 additions & 4 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var la = require('lazy-ass')
var check = require('check-more-types')
var log = require('debug')('next-update')
const R = require('ramda')

var request = require('request')
var verify = check.verify
Expand Down Expand Up @@ -225,7 +226,7 @@ function fetchVersions (nameVersion) {
}
log('extracting versions')
var versions = extractVersions(info)
log('versions', versions)
log('%d versions', versions.length)

if (!Array.isArray(versions)) {
throw new Error('Could not get versions for ' + name +
Expand All @@ -235,8 +236,14 @@ function fetchVersions (nameVersion) {

var validVersions = versions.filter(cleanVersionForName)
var newerVersions = validVersions.filter(isLaterVersion)
log('valid versions', validVersions)
log('newer versions', newerVersions)
log('%d valid versions', validVersions.length)
if (validVersions.length) {
log('last version %s', R.last(validVersions))
}
if (newerVersions.length) {
log('%d newer versions', newerVersions.length)
log('from %s to %s', R.head(newerVersions), R.last(newerVersions))
}

deferred.resolve({
name: name,
Expand Down Expand Up @@ -269,10 +276,16 @@ function nextVersions (options, nameVersionPairs, checkLatestOnly) {
var fetchAllPromise = q.all(fetchPromises)
.timeout(MAX_CHECK_TIMEOUT, 'timed out waiting for NPM')

function logFetched (fetched) {
fetched.forEach(individual => {
log('%s - %d versions', individual.name, individual.versions.length)
})
}

return fetchAllPromise.then(function (results) {
check.verify.array(results, 'expected list of results')
log('fetch all new version results')
log(results)
logFetched(results)

var available = results.filter(function (nameNewVersions) {
return nameNewVersions &&
Expand Down
11 changes: 11 additions & 0 deletions test/as-parent-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ describe('testing check-types', () => {
return chdir.to(testFolder).then(prune).then(install).then(chdir.back)
})

it('skips without module', function () {
this.timeout(TWO_MINUTES)
const opts = {
without: 'check-types',
keep: false
}
return nextUpdate(opts).then(results => {
la(results === undefined, 'no results without a module to check', results)
})
})

it('checks latest check-types', function () {
this.timeout(TWO_MINUTES)
const opts = {
Expand Down

0 comments on commit 955f7cd

Please sign in to comment.