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-02-22 08:04:23 +0300
committerisaacs <i@izs.me>2011-02-22 08:04:23 +0300
commit80cd4bdd070bd4d61d259db8b89f84b796234887 (patch)
treef1facbcfdf882f78cfff3228703343c3ed7f201c /lib/utils/read-json.js
parente7e5292fa7aa8e06bc69aec261daaa6c7aaab27f (diff)
Allow invalid json in already-installed packages
Diffstat (limited to 'lib/utils/read-json.js')
-rw-r--r--lib/utils/read-json.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js
index cd6872cef..7800d2035 100644
--- a/lib/utils/read-json.js
+++ b/lib/utils/read-json.js
@@ -70,14 +70,28 @@ function processJsonString (opts, cb) { return function (er, jsonString) {
try {
json = JSON.parse(jsonString)
} catch (ex) {
- var e = new Error(
- "Failed to parse json\n"+ex.message)
- e.errno = npm.EJSONPARSE
- if (cb) return cb(e)
- throw e
+ if (opts.file && opts.file.indexOf(npm.dir) === 0) {
+ try {
+ json = require("vm").runInNewContext("(\n"+jsonString+"\n)")
+ log.error(ex, "parse error "+opts.file)
+ } catch (ex2) {
+ return jsonParseFail(ex, cb)
+ }
+ } else {
+ return jsonParseFail(ex, cb)
+ }
}
return processObject(opts, cb)(er, json)
}}
+
+function jsonParseFail (ex, cb) {
+ var e = new Error(
+ "Failed to parse json\n"+ex.message)
+ e.errno = npm.EJSONPARSE
+ if (cb) return cb(e)
+ throw e
+}
+
function processObject (opts, cb) { return function (er, json) {
// slashes would be a security risk.