Skip to content

Commit

Permalink
feat(registry): provide new option '--registry' to set a custom regis…
Browse files Browse the repository at this point in the history
…try url bahmutov#116
  • Loading branch information
xpure-sklatt committed Nov 3, 2017
1 parent 9205cc6 commit 1c5b51f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/cover
/test/cover
/src/test/npm-debug.log
.idea/
*.eml
*.iml
.DS_Store
node_modules/
npm-debug.log
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "next-update",
"description": "Tests if module's dependencies can be updated to the newer version without breaking the tests",
"version": "0.0.0",
"version": "3.5.3",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
"bin": {
"next-update": "bin/next-update.js"
Expand Down Expand Up @@ -127,6 +127,7 @@
"limited": "gt --filter 'allow major' --output src/test/*.coffee",
"lint": "standard --verbose --fix *.js src/*.js src/**/*.js bin/*.js test/*.js",
"mocha": "mocha src/*-spec.js test/*-spec.js",
"next-update": "node bin/next-update.js --registry mutti",
"posttest": "npm run mocha",
"prebuild": "npm run lint",
"prelint": "npm run pretty",
Expand Down
9 changes: 9 additions & 0 deletions src/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ var program = optimist
alias: 'L',
description: 'print commit changes between working versions'
})
.options('registry', {
string: true,
default: false,
description: 'use a custom registry url'
})
.usage(info)
.argv

Expand All @@ -105,6 +110,10 @@ if (program.version) {
process.exit(0)
}

if (program.registry) {
console.log('### use custom registry:', program.registry)
}

if (program.help || program.h || program['?']) {
optimist.showHelp()
process.exit(0)
Expand Down
6 changes: 3 additions & 3 deletions src/next-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ function checkAllUpdates (options) {

return isOnline()
.then(function (online) {
if (!online) {
throw new Error('Need to be online to check new modules')
}
// if (!online) {
// throw new Error('Need to be online to check new modules')
// }
}).then(function () {
if (isSingleSpecificVersion(moduleName)) {
var nv = nameVersionParser(moduleName[0])
Expand Down
8 changes: 5 additions & 3 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ function isNotFound (str) {
// fetching versions inspired by
// https://github.com/jprichardson/npm-latest
// returns a promise
function fetchVersions (nameVersion) {
function fetchVersions (options, nameVersion) {
console.log('#### options ####', JSON.stringify(options, null, 2))
// console.log(nameVersion);
// TODO use check.schema
check.verify.object(nameVersion, 'expected name, version object')
Expand Down Expand Up @@ -180,8 +181,9 @@ function fetchVersions (nameVersion) {
la(check.webUrl(npmUrl), 'need npm registry url, got', npmUrl)

npmUrl = npmUrl.replace(/^https:/, 'http:').trim()
var url = npmUrl + escapeName(name)
var url = (options.registry || npmUrl) + escapeName(name)

console.log('### GET', url)
// TODO how to detect if the registry is not responding?

log('getting url', url)
Expand Down Expand Up @@ -315,7 +317,7 @@ function nextVersions (options, nameVersionPairs, checkLatestOnly) {
const verbose = verboseLog(options)
verbose('checking NPM registry')

var fetchPromises = nameVersionPairs.map(fetchVersions)
var fetchPromises = nameVersionPairs.map(fetchVersions.bind(null, options))
var fetchAllPromise = q.all(fetchPromises)
.timeout(MAX_CHECK_TIMEOUT, 'timed out waiting for NPM')

Expand Down
12 changes: 6 additions & 6 deletions src/test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function onError (error) {

gt.test('basic of fetch', function () {
gt.func(fetchVersions)
gt.arity(fetchVersions, 1)
gt.arity(fetchVersions, 2)
})

gt.async('fetch non existent module', 2, function () {
var promise = fetchVersions({
var promise = fetchVersions({}, {
name: 'this-module-should-not-exist-at-all',
version: '0.2.0'
})
Expand All @@ -31,8 +31,8 @@ gt.async('fetch non existent module', 2, function () {

gt.async('fetch gt later versions', function () {
gt.func(fetchVersions)
gt.arity(fetchVersions, 1)
var promise = fetchVersions({ name: 'gt', version: '0.5.0' })
gt.arity(fetchVersions, 2)
var promise = fetchVersions({}, { name: 'gt', version: '0.5.0' })
gt.func(promise.then, 'return object has then method')
promise.then(function (results) {
gt.object(results, 'returns an object')
Expand All @@ -44,8 +44,8 @@ gt.async('fetch gt later versions', function () {

gt.async('fetch module later versions', function () {
gt.func(fetchVersions)
gt.arity(fetchVersions, 1)
var promise = fetchVersions({ name: 'lodash', version: '0.7.0' })
gt.arity(fetchVersions, 2)
var promise = fetchVersions({}, { name: 'lodash', version: '0.7.0' })
gt.func(promise.then, 'return object has then method')
promise.then(function (results) {
gt.object(results, 'returns an object')
Expand Down

0 comments on commit 1c5b51f

Please sign in to comment.