diff --git a/index.js b/index.js index 4891f33..d798cc5 100644 --- a/index.js +++ b/index.js @@ -14,8 +14,11 @@ NpmRetryInstall.getMissing = function(path, cb){ if (err) throw err; var missing_modules = []; data.forEach(function(module){ - if(module[2] === undefined) - missing_modules.push([module[1], module[3]]); + if (module[2] === undefined) + if (module[3] === 'git') + missing_modules.push([module[1], module[5]]); + else + missing_modules.push([module[1], module[3]]); }); cb(missing_modules); }); @@ -36,7 +39,7 @@ NpmRetryInstall.init = function(cb){ NpmRetryInstall.getMissing(process.cwd(), function(data){ if(data.length > 0){ console.log(data); - + async.map(data, NpmRetryInstall.installModule, function(err, result){ result.forEach(function(module){ msg.push(module[0] + "@" + module[1]); @@ -47,4 +50,4 @@ NpmRetryInstall.init = function(cb){ cb('No modules seem to be missing. Huzzah!'); } }); -}; \ No newline at end of file +}; diff --git a/test/run.js b/test/run.js index a7a7e02..9de7811 100644 --- a/test/run.js +++ b/test/run.js @@ -116,4 +116,57 @@ describe('npm-install-missing', function(){ }); }); -}); \ No newline at end of file +}); + + +describe('npm-install-missing', function(){ + this.timeout(10000); + before(function(done){ + fake_package_json.dependencies = { "npm-install-missing":"git+https://github.com/AlexCline/npm-install-missing.git" }; + mkdirp(working_dir, function(err){ + if (err) throw err; + try { + process.chdir(working_dir); + fs.writeFile(working_dir + '/package.json', JSON.stringify(fake_package_json, null, 2), function(err){ + if (err) throw err; + exec('rm -rf ' + working_dir + '/node_modules', function(err, result){ + if (err) throw err; + done(); + }); + }); + } + catch (err) { + console.log('chdir: ' + err); + } + }); + }); + + after(function(done){ + fake_package_json.dependencies = test_dependency; + exec('rm -rf ' + working_dir, function(err, result){ + if(err) throw err; + done(); + }); + }); + + describe('#getMissing()', function(){ + it('should get a list of the missing modules when moduel is from git before anything is installed', function(done){ + npm_install_missing.getMissing(process.cwd(), function(data){ + assert.that(data[0][0], is.equalTo('npm-install-missing')); + assert.that(data[0][1], is.equalTo('git+https://github.com/AlexCline/npm-install-missing.git')); + missing_mods = data; + done(); + }); + }); + }); + + + describe('#installModule', function(){ + it('should install the test_dependency module', function(done){ + npm_install_missing.installModule(missing_mods[0], function(err, result){ + assert.that(result.length, is.greaterThan(1)); + done(); + }); + }); + }); +});