Fix node dependencies retrieval
kozmic opened this issue · 6 comments
Right now the state of retrieval of node module names and versions are broken because of the async nature of the npm.commands.ls. We either need to retrieve the same version information in another way (like grunt.file.readJSON('package.json')
).
Started work in branch node-async-fix
.
If anyone want to work on this issue, go ahead :)
What's the issue really? How can I reproduce this?
For patsy ( https://github.com/phun-ky/patsy ) , we traverse the node_modules
directory in a bit crude way to test if all dependencies are installed, like this:
check_dependencies: function(test){
var fs = require('fs'),
path = require('path'),
module_pjson = '',
module_pjson_path = '',
module_pjson_abs_path = '';
var check_modules = function(module){
module_pjson_path = '..' + path.sep + 'node_modules' + path.sep + module + path.sep + 'package.json';
module_pjson_abs_path = path.resolve(__dirname, module_pjson_path);
if(fs.existsSync(module_pjson_abs_path) && typeof require(module_pjson_abs_path) === 'object'){
//console.log(String('✓ Module ' + module + ' found!').green);
} else {
throw new Error('Module ' + module + ' not found!');
}
};
var testModules = function(module){
check_modules(module);
};
test.expect(pjson.dependencies.length);
for(var module in pjson.dependencies){
if(pjson.dependencies.hasOwnProperty(module)){
test.throws(
testModules(module),
Error,
'Show fail for non existent module'
);
}
}
test.done();
}
So, wouldn't it "basically" be to add deep traversing here if more node_modules
dirs are found?
retire.js has switched implementation now, changed in bekk/retire.js@d858b2c. So we could probably just call getNodeDependencies() in grunt-retire, so should be quite easy to implement now.
Should be fixed now