Skip to content

Instantly share code, notes, and snippets.

@Mr0grog
Last active August 29, 2015 13:56
Show Gist options
  • Save Mr0grog/9145413 to your computer and use it in GitHub Desktop.
Save Mr0grog/9145413 to your computer and use it in GitHub Desktop.
Testing dependencies
#!/usr/bin/env node
var spawn = require('child_process').spawn;
var list = spawn('npm', ['list', '--json']);
var result = "";
list.stdout.on('data', function (data) {
result += data;
});
list.on('close', function(code) {
var data = JSON.parse(result);
if (data.problems) {
data.problems.forEach(function(problem) {
console.error(' ' + problem);
});
}
else {
console.log(' Your packages look good!');
}
process.exit(code);
});
{
"name": "node-test-package",
"version": "0.1.0",
"description": "Test your your installed packages against your dependencies.",
"main": "node-test-package.js",
"bin": {
"node-test-package": "./node-test-package.js"
}
}
{
"name": "thinger",
"version": "0.1.0",
"description": "I gots me some bad deps",
"main": "index.js",
"scripts": {
"test": "node_modules/node-test-package/node-test-package.js && run-actual-tests"
},
"devDependencies": {
"node-test-package": "~0.1.0"
}
}
@jfirebaugh
Copy link

The incantation that handles my use case seems to be npm ls --depth=Infinity > /dev/null. The --depth argument overrides the npm_config_depth=null environment variable that is set up by npm for the test lifecycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment