Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-12-29 22:17:21 +0400
committerisaacs <i@izs.me>2011-12-29 22:17:21 +0400
commiteac92ef67c62d2213b905d1053bc302f004d8e57 (patch)
treefe5c36861eca901cda8bca131b9428b718767df3 /lib/utils/read-json.js
parent79f3276946b9059a77263ae1153aa3c3e087d39a (diff)
Fix #1950 Warn on non-object dep hashes, instead of crashing
Diffstat (limited to 'lib/utils/read-json.js')
-rw-r--r--lib/utils/read-json.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js
index c4803c191..ffd447d32 100644
--- a/lib/utils/read-json.js
+++ b/lib/utils/read-json.js
@@ -363,7 +363,7 @@ function processObject (opts, cb) { return function (er, json) {
}
;["dependencies", "devDependencies"].forEach(function (d) {
- json[d] = json[d] ? depObjectify(json[d]) : {}
+ json[d] = json.hasOwnProperty(d) ? depObjectify(json[d], d, json._id) : {}
})
if (opts.dev || npm.config.get("dev") || npm.config.get("npat")) {
@@ -395,7 +395,19 @@ function processObject (opts, cb) { return function (er, json) {
return json
}}
-function depObjectify (deps) {
+var depObjectifyWarn = {}
+function depObjectify (deps, d, id) {
+ if ((!deps || typeof deps !== "object" || Array.isArray(deps))
+ && !depObjectifyWarn[id+d]) {
+ log.warn( d + " field should be hash of <name>:<version-range> pairs"
+ , id )
+ depObjectifyWarn[id + d] = true
+ }
+
+ if (!deps) return {}
+ if (typeof deps === "string") {
+ deps = deps.trim().split(/[\n\r\s\t ,]+/)
+ }
if (!Array.isArray(deps)) return deps
var o = {}
deps.forEach(function (d) {