Skip to content

Commit

Permalink
fix(install) save don't work when pkg is found and version is supplied,
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Jan 15, 2015
1 parent 88f5a6b commit 3669c75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ function* installPackage(id, args, saveDeps) {

// The package has downloaded in dest
// always false when version is not empty
if (existInDest(idObj, args)) return;
if (existInDest(idObj, args)) {
// save dependencies to package.json
if ((args.save || args.saveDev) && saveDeps) {
save(idObj, args);
}
return;
}

// Fetch pkg info from registry
var pinfo = yield* info(idObj, args);
Expand Down
20 changes: 20 additions & 0 deletions test/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,26 @@ describe('/lib/install.js', function() {
});
rimraf.sync(tmpDir);
});

it('should save to package.json when found in spm_modules and version is supplied', function* () {
var tmpDir = join(fixtures, 'tmp2');
var pkgPath = join(tmpDir, 'package.json');
mkdirp.sync(tmpDir);
fs.writeFileSync(pkgPath, '{"name": "a", "version": "1.0.0"}');
var args = {
name: '[email protected]',
cwd: tmpDir,
destination: join(fixtures, 'package-dest', 'spm_modules'),
save: true,
downloadlist: {}
};
yield* install.installPackage(args.name, args, true);
var pkg = require(pkgPath);
pkg.spm.dependencies.should.eql({
tmp: '0.0.2'
});
rimraf.sync(tmpDir);
});
});
});

Expand Down

0 comments on commit 3669c75

Please sign in to comment.