Skip to content

Commit

Permalink
Remove deprecated fs.exists call. Better error messages for package.j…
Browse files Browse the repository at this point in the history
…son parse error.
  • Loading branch information
alanshaw committed Jan 13, 2015
1 parent d3c080b commit 9da6cdd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/david.js
Expand Up @@ -7,8 +7,6 @@ var david = require("../")
, npm = require("npm")
, argv = require("minimist")(process.argv.slice(2))
, xtend = require("xtend")
, cwd = process.cwd()
, packageFile = cwd + "/package.json"

if (argv.usage || argv.help || argv.h) {
return console.log(fs.readFileSync(__dirname + "/usage.txt", "utf8"))
Expand Down Expand Up @@ -245,13 +243,21 @@ if (argv.global) {
})

} else {
if (!fs.existsSync(packageFile)) {
console.error("package.json does not exist")
var pkg

try {
pkg = fs.readFileSync(process.cwd() + "/package.json")
try {
pkg = JSON.parse(pkg)
} catch (er) {
console.error("Failed to parse package.json", er)
process.exit(1)
}
} catch (er) {
console.error("Failed to read package.json", er)
process.exit(1)
}

var pkg = require(cwd + "/package.json")

getUpdatedDeps(pkg, function (er, deps, devDeps, optionalDeps) {
if (er) {
console.error("Failed to get updated dependencies/devDependencies", er)
Expand Down

0 comments on commit 9da6cdd

Please sign in to comment.