Skip to content

Commit 3f9ea5e

Browse files
committed
Merge pull request #2 from inexplicable/master
exports.npmls
2 parents 6692786 + bae75b7 commit 3f9ea5e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var debugMiddleware = exports.debugMiddleware = function(req, res, next){
3535

3636
if(req.url === '/deps'){
3737

38-
require('./utils').npmls
38+
exports.npmls
3939
.then(function(deps){
4040
res.type('json').send(deps);
4141
})
@@ -336,3 +336,27 @@ exports.monCreateServer = function createServer(app){
336336

337337
return server;
338338
};
339+
340+
exports.npmls = (function npmls(){
341+
342+
var tillList = when.defer(),
343+
execPath = process.execPath,
344+
execArgv = [path.join(require.resolve('npm'), '../../bin/npm-cli.js'), 'ls', '--json', '--depth=10'],
345+
execFile = require('child_process').execFile;
346+
347+
execFile(execPath, execArgv, {
348+
'cwd': process.cwd(),
349+
'encoding': 'utf-8'
350+
},
351+
function(err, stdout){
352+
353+
if(err){
354+
tillList.reject(err);
355+
}
356+
else{
357+
tillList.resolve(stdout);
358+
}
359+
});
360+
361+
return tillList.promise;
362+
})();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"socket.io": "~0.9.0",
3030
"express": "~3.1.0",
3131
"when": "~2.7.0",
32-
"ejs": "~0.8.0"
32+
"ejs": "~0.8.0",
33+
"npm": "~1.3.0"
3334
},
3435
"devDependencies": {
3536
"optimist": "~0.6.0",

0 commit comments

Comments
 (0)