Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 746d157

Browse files
committed
[fixes #4] better normalization of resolve opts
1 parent 0049eb4 commit 746d157

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ var async = require('async'),
1010
download = require('./lib/download'),
1111
extract = require('./lib/extract'),
1212
versions = require('./lib/versions'),
13-
pluck = require('lodash.pluck'),
14-
defaults = require('lodash.defaults'),
13+
defaults = require('amp-defaults'),
1514
semver = require('semver'),
1615
debug = require('debug')('mongodb-version-manager');
1716

lib/resolve.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var os = require('os'),
44
versions = require('./versions'),
55
semver = require('semver'),
66
request = require('request'),
7-
async = require('async');
7+
async = require('async'),
8+
defaults = require('amp-defaults');
89

910
module.exports = function(opts, fn){
1011
if(Array.isArray(opts)){
@@ -20,38 +21,49 @@ module.exports = function(opts, fn){
2021
if(typeof opts === 'string'){
2122
opts = {version: opts};
2223
}
24+
var handler = versions;
25+
26+
defaults(opts, {
27+
arch: ARCH,
28+
platform: PLATFORM,
29+
branch: 'master',
30+
bits: '64',
31+
debug: false
32+
});
33+
34+
// 64bit -> 64
35+
opts.bits = opts.bits.replace(/[^0-9]/g, '');
2336

24-
var arch = opts.arch || ARCH,
25-
platform = opts.platform || PLATFORM,
26-
handler = versions;
37+
if(opts.platform === 'darwin') opts.platform = 'osx';
38+
if(opts.platform === 'windows') opts.platform = 'win32';
2739

28-
opts.branch = opts.branch || 'master';
29-
opts.platform = opts.platform || PLATFORM;
30-
opts.bits = opts.bits || '64';
31-
opts.ext = (platform === 'win32' ? '.zip' : '.tgz');
40+
opts.ext = (opts.platform === 'win32' ? '.zip' : '.tgz');
41+
// @todo: get list of distros from mci and make sure passed in is valid.
3242
opts.distro = opts.distro || null;
3343

44+
// A commit hash
45+
if(opts.version.length === 40 || opts.version.length === 8){
46+
// @todo: Use dyno rest api to resolve 8char short sha to full sha.
47+
return mci(opts, fn);
48+
}
49+
3450
if(opts.version === 'latest' || opts.version === 'unstable'){
3551
handler = latest;
3652
}
3753
else if(opts.version === 'stable'){
3854
handler = stable;
3955
}
40-
else if(opts.version.length === 40 || opts.version.length === 8){
41-
// A commit hash
42-
return mci(opts, fn);
43-
}
4456
else {
4557
handler = search.bind(null, opts);
4658
}
4759

4860
handler(function(err, v){
49-
var basename = 'mongodb-' + platform+'-' + arch + (opts.debug ? '-debugsymbols' : '') + '-' + v,
61+
var basename = 'mongodb-' + opts.platform+'-' + opts.arch + (opts.debug ? '-debugsymbols' : '') + '-' + v,
5062
pkg = {
5163
name: 'mongodb',
5264
version: v,
5365
artifact: basename + opts.ext,
54-
url: 'http://fastdl.mongodb.org/'+platform+'/' + basename + opts.ext
66+
url: 'http://fastdl.mongodb.org/'+opts.platform+'/' + basename + opts.ext
5567
};
5668

5769
fn(null, pkg);
@@ -86,8 +98,6 @@ function mci(opts, fn){
8698
});
8799
}
88100

89-
90-
91101
function search(query, fn){
92102
versions(function(err, res){
93103
if(err) return fn(err);

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
"mocha": "~2.0.1"
1919
},
2020
"dependencies": {
21+
"amp-defaults": "~1.0.1",
2122
"async": "~0.9.0",
2223
"cheerio": "~0.17.0",
2324
"debug": "~1.0.4",
2425
"docopt": "~0.4.0",
2526
"downcache": "0.0.5-a",
2627
"fs-extra": "~0.10.0",
27-
"lodash.defaults": "~2.4.1",
28-
"lodash.pluck": "~2.4.1",
29-
"lodash.without": "~2.4.1",
3028
"progress": "~1.1.8",
3129
"request": "~2.40.0",
3230
"semver": "~3.0.1",

0 commit comments

Comments
 (0)