Skip to content

Commit

Permalink
fix(install) check semver match before info
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 26, 2014
1 parent 5b1aaf2 commit 2575df3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
13 changes: 8 additions & 5 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var util = require('./util');
var info = require('./info');
var request = require('request');
var debug = require('debug')('spm-client:install');
var getVersion = require('father/lib/util').getVersion;

var defaults = {
cwd: process.cwd(),
Expand Down Expand Up @@ -85,18 +86,20 @@ function* installPackage(id, args, saveDeps) {
log.info('install', color.magenta(pkgId));
debug('start install package %s', pkgId);

var pinfo = yield* info(idObj, args);
pkgId = pinfo.name + '@' + pinfo.version;

// The package has downloaded in dest
// always false when version is not empty
if (existInDest(idObj, args)) return;

// Fetch pkg info from registry
var pinfo = yield* info(idObj, args);
pkgId = pinfo.name + '@' + pinfo.version;

// The package has been in downloadlist
if (pkgId in args.downloadlist) {
debug('package %s has been in downloadlist', pkgId);
return;
}

args.downloadlist[pkgId] = pinfo;

// save dependencies to package.json
Expand Down Expand Up @@ -144,8 +147,8 @@ function existInDest(idObj, args) {
return false;
}
var pkgId = format('%s@%s', idObj.name, idObj.version);
var dest = path.join(args.destination, idObj.name, idObj.version);
if (!args.force && fs.existsSync(dest)) {
var dest = path.join(args.destination, idObj.name);
if (!args.force && getVersion(idObj.version, dest)) {
log.info('found', pkgId);
debug('package %s found in %s', pkgId, dest);
if (!args.downloadlist[pkgId]) args.downloadlist[pkgId] = idObj;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"colorful": "~2.1.0",
"debug": "~1.0.4",
"extend": "~1.3.0",
"father": "0.10.6",
"fstream": "~1.0.1",
"fstream-ignore": "~1.0.1",
"generator-supported": "~0.0.1",
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/package-dest/spm_modules/a/1.0.0/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"version": "1.0.0"
}
3 changes: 3 additions & 0 deletions test/fixtures/package-dest/spm_modules/b/1.0.6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0.6"
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"version": "0.0.2"
}
12 changes: 12 additions & 0 deletions test/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ describe('/lib/install.js', function() {
logInfo.calls[1].arguments.should.eql(['found', 'a@1.0.0']);
});

it('should return when exist in dest with semver', function* () {
var args = {
name: 'b@~1.0.3',
destination: join(fixtures, 'package-dest', 'spm_modules'),
downloadlist: {}
};
yield* install.installPackage(args.name, args, true);
args.downloadlist.should.have.property('b@~1.0.3');
logInfo.callCount.should.eql(2);
logInfo.calls[1].arguments.should.eql(['found', 'b@~1.0.3']);
});

it('should install stable return when exist in dest', function* () {
var args = {
name: 'tmp',
Expand Down

0 comments on commit 2575df3

Please sign in to comment.