diff options
Diffstat (limited to 'deps/npm/node_modules/read-package-json/read-json.js')
-rw-r--r-- | deps/npm/node_modules/read-package-json/read-json.js | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/deps/npm/node_modules/read-package-json/read-json.js b/deps/npm/node_modules/read-package-json/read-json.js index acb1286800..d9a4610d9c 100644 --- a/deps/npm/node_modules/read-package-json/read-json.js +++ b/deps/npm/node_modules/read-package-json/read-json.js @@ -1,17 +1,6 @@ // vim: set softtabstop=16 shiftwidth=16: try { - readJson.log = require("npmlog") -} catch (er) { - readJson.log = { - info: function () {}, - verbose: function () {}, - warn: function () {} - } -} - - -try { var fs = require("graceful-fs") } catch (er) { var fs = require("fs") @@ -40,25 +29,33 @@ readJson.extraSet = [ var typoWarned = {} -function readJson (file, cb) { +function readJson (file, log_, strict_, cb_) { + var log, strict, cb + for (var i = 1; i < arguments.length - 1; i++) { + if (typeof arguments[i] === 'boolean') + strict = arguments[i] + else if (typeof arguments[i] === 'function') + log = arguments[i] + } + if (!log) log = function () {}; + cb = arguments[ arguments.length - 1 ] + var c = readJson.cache.get(file) if (c) { - readJson.log.verbose("from cache", file) cb = cb.bind(null, null, c) return process.nextTick(cb); } - readJson.log.verbose("read json", file) cb = (function (orig) { return function (er, data) { if (data) readJson.cache.set(file, data); return orig(er, data) } })(cb) - readJson_(file, cb) + readJson_(file, log, strict, cb) } -function readJson_ (file, cb) { +function readJson_ (file, log, strict, cb) { fs.readFile(file, "utf8", function (er, d) { - parseJson(file, er, d, cb) + parseJson(file, er, d, log, strict, cb) }) } @@ -74,9 +71,9 @@ function stripBOM(content) { } -function parseJson (file, er, d, cb) { +function parseJson (file, er, d, log, strict, cb) { if (er && er.code === "ENOENT") { - indexjs(file, er, cb) + indexjs(file, er, log, strict, cb) return } if (er) return cb(er); @@ -86,11 +83,11 @@ function parseJson (file, er, d, cb) { d = parseIndex(d) if (!d) return cb(parseError(er, file)); } - extras(file, d, cb) + extras(file, d, log, strict, cb) } -function indexjs (file, er, cb) { +function indexjs (file, er, log, strict, cb) { if (path.basename(file) === "index.js") { return cb(er); } @@ -99,13 +96,21 @@ function indexjs (file, er, cb) { if (er2) return cb(er); d = parseIndex(d) if (!d) return cb(er); - extras(file, d, cb) + extras(file, d, log, strict, cb) }) } readJson.extras = extras -function extras (file, data, cb) { +function extras (file, data, log_, strict_, cb_) { + var log, strict, cb + for (var i = 2; i < arguments.length - 1; i++) { + if (typeof arguments[i] === 'boolean') + strict = arguments[i] + else if (typeof arguments[i] === 'function') + log = arguments[i] + } + cb = arguments[i] var set = readJson.extraSet var n = set.length var errState = null @@ -115,7 +120,8 @@ function extras (file, data, cb) { function then(er) { if (errState) return; if (er) return cb(errState = er); - if (--n === 0) final(file, data, cb); + if (--n > 0) return; + final(file, data, log, strict, cb); } } @@ -294,14 +300,14 @@ function githead_ (file, data, dir, head, cb) { }) } -function final (file, data, cb) { +function final (file, data, log, strict, cb) { var pId = makePackageId(data) function warn(msg) { if (typoWarned[pId]) return; - readJson.log.warn("package.json", pId, msg) + if (log) log("package.json", pId, msg); } try { - normalizeData(data, warn) + normalizeData(data, warn, strict) } catch (error) { return cb(error) |