Skip to content

Commit

Permalink
Merge pull request caolan#7 from mailru/rc
Browse files Browse the repository at this point in the history
Rc
  • Loading branch information
gobwas committed Apr 29, 2015
2 parents b119462 + 8fa54a1 commit c948ba7
Show file tree
Hide file tree
Showing 13 changed files with 1,062 additions and 415 deletions.
353 changes: 299 additions & 54 deletions lib/commands/install.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/commands/upgrade.js
Expand Up @@ -214,7 +214,7 @@ exports.getOutdated = function (deps, cfg, opt, callback) {
var uversion = updated[name] ? updated[name].current_version: null;

if (lversion) {
var lpkg = local[name].versions[lversion];
var lpkg = _.findWhere(local[name].versions, { version: lversion });
if (lpkg.source === 'repository') {
// cannot even satisfy requirements with current package,
// this needs re-installing from repositories
Expand Down
14 changes: 7 additions & 7 deletions lib/couchdb.js
Expand Up @@ -211,12 +211,12 @@ CouchDB.prototype.client = function (method, path, data, callback) {
logger.debug('request data', data);

request.on('response', function (response) {
logger.debug('response:', {
headers: response.headers,
url: response.url,
method: response.method,
statusCode: response.statusCode
});
//logger.debug('response:', {
// headers: response.headers,
// url: response.url,
// method: response.method,
// statusCode: response.statusCode
//});
if (response.headers.connection === 'close' &&
response.statusCode >= 300) {
var err3 = exports.statusCodeError(response.statusCode);
Expand All @@ -235,7 +235,7 @@ CouchDB.prototype.client = function (method, path, data, callback) {
catch (e) {
logger.info('Unexpected response', buffer.join(''));
}
logger.debug('data:', data);
//logger.debug('data:', data);
if (response.statusCode >= 300) {
if (data && data.error) {
var err = new Error(
Expand Down
30 changes: 20 additions & 10 deletions lib/git.js
Expand Up @@ -31,6 +31,7 @@ exports.temp = [];

function Repository(path) {
this.path = path;
this.at = null;
}

exports.Repository = Repository;
Expand All @@ -44,7 +45,8 @@ Repository.prototype = {
return function(callback) {
logger.debug("git", "getting log from " + this.path);

run(command(), { cwd: this.path }, function(err, stderr, stdout) {
// with 5MB
run(command(), { cwd: this.path, maxBuffer: 1024 * 1024 * 5 }, function(err, stderr, stdout) {
if (err) {
callback(err);
return;
Expand All @@ -64,7 +66,8 @@ Repository.prototype = {
return function(callback) {
logger.debug("git", "getting refs from " + this.path);

run(command(), { cwd: this.path }, function(err, stderr, stdout) {
// with 5MB
run(command(), { cwd: this.path, maxBuffer: 1024 * 1024 * 5 }, function(err, stderr, stdout) {
var found, result;

if (err) {
Expand Down Expand Up @@ -105,6 +108,13 @@ Repository.prototype = {
command = _.template('git checkout <%= commitish %>');

return function(commitish, callback) {
var self = this;

if (this.at === commitish) {
callback(null);
return;
}

logger.debug("git", "checking out " + this.path + "#" + commitish);

run(command({ commitish: commitish }), { cwd: this.path }, function(err, stderr, stdout) {
Expand All @@ -113,6 +123,8 @@ Repository.prototype = {
return;
}

self.at = commitish;

callback(null);
});
}
Expand Down Expand Up @@ -475,23 +487,21 @@ exports.availableVersions = function (name, uri, callback) {
var versions;

if (err) {
logger.warning('package "' + name + '" from ' + uri + " does not provide package.json");
logger.warning('package "' + name + '" from ' + uri + " does not provide valid package.json");
callback(err);
return;
}

(versions = {})[doc.version] = {
(versions = []).push({
source: 'git',
def: {
git: {
path: path,
commitish: commitish,
uri: uri
},
config: _.extend({}, doc, {
// hm
name: name
})
};
config: doc,
version: doc.version
});

callback(null, versions);
});
Expand Down
13 changes: 7 additions & 6 deletions lib/packages.js
Expand Up @@ -152,21 +152,22 @@ exports.resolveCandidates = function (name, source, paths) {
*/

exports.availableVersions = function (candidates, callback) {
var versions = {};
var versions = [];
async.forEach(candidates, function (c, cb) {
pathExists(path.join(c, 'package.json'), function (exists) {
if (exists) {
settings.load(c, function (err, doc) {
if (err) {
return cb(err);
}
if (!versions[doc.version]) {
versions[doc.version] = {
//if (!versions[doc.version]) {
versions.push({
source: 'local',
path: c,
config: doc,
source: 'local'
};
}
version: doc.version
});
//}
cb();
});
}
Expand Down
31 changes: 15 additions & 16 deletions lib/repository.js
Expand Up @@ -436,21 +436,22 @@ exports.resolve = function (name, ranges, repos, callback) {
*/

exports.availableVersions = function (name, repositories, callback) {
var versions = {};
var versions = [];
async.forEach(repositories, function (repo, cb) {
exports.get(repo, name, true, function (err, doc) {
if (err) {
return cb(err);
}
if (doc && doc.versions) {
for (var k in doc.versions) {
if (!versions[k]) {
versions[k] = {
for (var k in doc.versions) if (doc.versions.hasOwnProperty(k)) {
//if (!versions[k]) {
versions.push({
source: 'repository',
repository: repo,
config: doc.versions[k],
source: 'repository'
};
}
version: k
});
//}
}
}
cb();
Expand All @@ -470,27 +471,25 @@ exports.availableVersions = function (name, repositories, callback) {
* was found on, and 'version' which is the actual max satisfying version.
*
* @param {String} name - the name of the package to look up
* @param {Array} ranges - an array of version range requirements
* @param {Array} ranges - an array of version range requirements
* @param {Array} repositories - an array of repository URLs
* @param {Function} callback
*/

exports.maxSatisfying = function (name, ranges, repositories, callback) {
// TODO: what to do about tags?
exports.availableVersions(name, repositories, function (err, vers) {
var max;

if (err) {
return callback(err);
}
var max = versions.maxSatisfying(Object.keys(vers), ranges);
if (!max) {

if (!(max = versions.maxSatisfying(_.pluck(vers, "version"), ranges))) {
return callback(null, null);
}
return callback(null, {
source: vers[max].source,
repository: vers[max].repository,
config: vers[max].config,
version: max
}, vers);

return callback(null, _.findWhere(vers, { version: max }), vers);
});
};

Expand Down

0 comments on commit c948ba7

Please sign in to comment.