diff options
Diffstat (limited to 'node_modules/read-package-json/read-json.js')
-rw-r--r-- | node_modules/read-package-json/read-json.js | 198 |
1 files changed, 141 insertions, 57 deletions
diff --git a/node_modules/read-package-json/read-json.js b/node_modules/read-package-json/read-json.js index 4226e77c0..04d22e3af 100644 --- a/node_modules/read-package-json/read-json.js +++ b/node_modules/read-package-json/read-json.js @@ -20,7 +20,7 @@ readJson.extraSet = [ readme, mans, bins, - githead + githead, ] var typoWarned = {} @@ -36,7 +36,9 @@ function readJson (file, log_, strict_, cb_) { } } - if (!log) log = function () {} + if (!log) { + log = function () {} + } cb = arguments[arguments.length - 1] readJson_(file, log, strict, cb) @@ -52,7 +54,9 @@ function stripBOM (content) { // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) // because the buffer-to-string conversion in `fs.readFileSync()` // translates it to FEFF, the UTF-16 BOM. - if (content.charCodeAt(0) === 0xFEFF) content = content.slice(1) + if (content.charCodeAt(0) === 0xFEFF) { + content = content.slice(1) + } return content } @@ -87,9 +91,13 @@ function parseJson (file, er, d, log, strict, cb) { } }) } - if (er) return cb(er) + if (er) { + return cb(er) + } - if (cache[d]) return cb(null, jsonClone(cache[d])) + if (cache[d]) { + return cb(null, jsonClone(cache[d])) + } var data @@ -102,7 +110,9 @@ function parseJson (file, er, d, log, strict, cb) { } } catch (er) { data = parseIndex(d) - if (!data) return cb(parseError(er, file)) + if (!data) { + return cb(parseError(er, file)) + } } extrasCached(file, d, data, log, strict, cb) @@ -118,16 +128,24 @@ function extrasCached (file, d, data, log, strict, cb) { } function indexjs (file, er, log, strict, cb) { - if (path.basename(file) === 'index.js') return cb(er) + if (path.basename(file) === 'index.js') { + return cb(er) + } var index = path.resolve(path.dirname(file), 'index.js') fs.readFile(index, 'utf8', function (er2, d) { - if (er2) return cb(er) + if (er2) { + return cb(er) + } - if (cache[d]) return cb(null, cache[d]) + if (cache[d]) { + return cb(null, cache[d]) + } var data = parseIndex(d) - if (!data) return cb(er) + if (!data) { + return cb(er) + } extrasCached(file, d, data, log, strict, cb) }) @@ -144,7 +162,9 @@ function extras (file, data, log_, strict_, cb_) { } } - if (!log) log = function () {} + if (!log) { + log = function () {} + } cb = arguments[i] var set = readJson.extraSet @@ -155,15 +175,23 @@ function extras (file, data, log_, strict_, cb_) { }) function then (er) { - if (errState) return - if (er) return cb(errState = er) - if (--n > 0) return + if (errState) { + return + } + if (er) { + return cb(errState = er) + } + if (--n > 0) { + return + } final(file, data, log, strict, cb) } } function scriptpath (file, data, cb) { - if (!data.scripts) return cb(null, data) + if (!data.scripts) { + return cb(null, data) + } var k = Object.keys(data.scripts) k.forEach(scriptpath_, data.scripts) cb(null, data) @@ -172,7 +200,9 @@ function scriptpath (file, data, cb) { function scriptpath_ (key) { var s = this[key] // This is never allowed, and only causes problems - if (typeof s !== 'string') return delete this[key] + if (typeof s !== 'string') { + return delete this[key] + } var spre = /^(\.[/\\])?node_modules[/\\].bin[\\/]/ if (s.match(spre)) { @@ -183,17 +213,25 @@ function scriptpath_ (key) { function gypfile (file, data, cb) { var dir = path.dirname(file) var s = data.scripts || {} - if (s.install || s.preinstall) return cb(null, data) + if (s.install || s.preinstall) { + return cb(null, data) + } glob('*.gyp', { cwd: dir }, function (er, files) { - if (er) return cb(er) - if (data.gypfile === false) return cb(null, data) + if (er) { + return cb(er) + } + if (data.gypfile === false) { + return cb(null, data) + } gypfile_(file, data, files, cb) }) } function gypfile_ (file, data, files, cb) { - if (!files.length) return cb(null, data) + if (!files.length) { + return cb(null, data) + } var s = data.scripts || {} s.install = 'node-gyp rebuild' data.scripts = s @@ -204,15 +242,21 @@ function gypfile_ (file, data, files, cb) { function serverjs (file, data, cb) { var dir = path.dirname(file) var s = data.scripts || {} - if (s.start) return cb(null, data) + if (s.start) { + return cb(null, data) + } glob('server.js', { cwd: dir }, function (er, files) { - if (er) return cb(er) + if (er) { + return cb(er) + } serverjs_(file, data, files, cb) }) } function serverjs_ (file, data, files, cb) { - if (!files.length) return cb(null, data) + if (!files.length) { + return cb(null, data) + } var s = data.scripts || {} s.start = 'node server.js' data.scripts = s @@ -220,11 +264,15 @@ function serverjs_ (file, data, files, cb) { } function authors (file, data, cb) { - if (data.contributors) return cb(null, data) + if (data.contributors) { + return cb(null, data) + } var af = path.resolve(path.dirname(file), 'AUTHORS') fs.readFile(af, 'utf8', function (er, ad) { // ignore error. just checking it. - if (er) return cb(null, data) + if (er) { + return cb(null, data) + } authors_(file, data, ad, cb) }) } @@ -240,16 +288,22 @@ function authors_ (file, data, ad, cb) { } function readme (file, data, cb) { - if (data.readme) return cb(null, data) + if (data.readme) { + return cb(null, data) + } var dir = path.dirname(file) var globOpts = { cwd: dir, nocase: true, mark: true } glob('{README,README.*}', globOpts, function (er, files) { - if (er) return cb(er) + if (er) { + return cb(er) + } // don't accept directories. files = files.filter(function (file) { return !file.match(/\/$/) }) - if (!files.length) return cb() + if (!files.length) { + return cb() + } var fn = preferMarkdownReadme(files) var rm = path.resolve(dir, fn) readme_(file, data, rm, cb) @@ -275,7 +329,9 @@ function readme_ (file, data, rm, cb) { var rmfn = path.basename(rm) fs.readFile(rm, 'utf8', function (er, rm) { // maybe not readable, or something. - if (er) return cb() + if (er) { + return cb() + } data.readme = rm data.readmeFilename = rmfn return cb(er, data) @@ -284,31 +340,32 @@ function readme_ (file, data, rm, cb) { function mans (file, data, cb) { var m = data.directories && data.directories.man - if (data.man || !m) return cb(null, data) + if (data.man || !m) { + return cb(null, data) + } m = path.resolve(path.dirname(file), m) glob('**/*.[0-9]', { cwd: m }, function (er, mans) { - if (er) return cb(er) - mans_(file, data, mans, cb) - }) -} - -function mans_ (file, data, mans, cb) { - var m = data.directories && data.directories.man - data.man = mans.map(function (mf) { - return path.resolve(path.dirname(file), m, mf) + if (er) { + return cb(er) + } + data.man = mans + return cb(null, data) }) - return cb(null, data) } function bins (file, data, cb) { data = normalizePackageBin(data) var m = data.directories && data.directories.bin - if (data.bin || !m) return cb(null, data) + if (data.bin || !m) { + return cb(null, data) + } m = path.resolve(path.dirname(file), m) glob('**', { cwd: m }, function (er, bins) { - if (er) return cb(er) + if (er) { + return cb(er) + } bins_(file, data, bins, cb) }) } @@ -330,11 +387,14 @@ function bundleDependencies (file, data, cb) { var bdd = 'bundledDependencies' // normalize key name if (data[bdd] !== undefined) { - if (data[bd] === undefined) data[bd] = data[bdd] + if (data[bd] === undefined) { + data[bd] = data[bdd] + } delete data[bdd] } - if (data[bd] === false) delete data[bd] - else if (data[bd] === true) { + if (data[bd] === false) { + delete data[bd] + } else if (data[bd] === true) { data[bd] = Object.keys(data.dependencies || {}) } else if (data[bd] !== undefined && !Array.isArray(data[bd])) { delete data[bd] @@ -343,16 +403,24 @@ function bundleDependencies (file, data, cb) { } function githead (file, data, cb) { - if (data.gitHead) return cb(null, data) + if (data.gitHead) { + return cb(null, data) + } var dir = path.dirname(file) var head = path.resolve(dir, '.git/HEAD') fs.readFile(head, 'utf8', function (er, head) { - if (er) return cb(null, data) - githead_(file, data, dir, head, cb) + if (er) { + var parent = path.dirname(dir) + if (parent === dir) { + return cb(null, data) + } + return githead(dir, data, cb) + } + githead_(data, dir, head, cb) }) } -function githead_ (file, data, dir, head, cb) { +function githead_ (data, dir, head, cb) { if (!head.match(/^ref: /)) { data.gitHead = head.trim() return cb(null, data) @@ -388,16 +456,24 @@ function githead_ (file, data, dir, head, cb) { * normalize-package-data if it had access to the file path. */ function checkBinReferences_ (file, data, warn, cb) { - if (!(data.bin instanceof Object)) return cb() + if (!(data.bin instanceof Object)) { + return cb() + } var keys = Object.keys(data.bin) var keysLeft = keys.length - if (!keysLeft) return cb() + if (!keysLeft) { + return cb() + } function handleExists (relName, result) { keysLeft-- - if (!result) warn('No bin file found at ' + relName) - if (!keysLeft) cb() + if (!result) { + warn('No bin file found at ' + relName) + } + if (!keysLeft) { + cb() + } } keys.forEach(function (key) { @@ -421,8 +497,12 @@ function final (file, data, log, strict, cb) { var pId = makePackageId(data) function warn (msg) { - if (typoWarned[pId]) return - if (log) log('package.json', pId, msg) + if (typoWarned[pId]) { + return + } + if (log) { + log('package.json', pId, msg) + } } try { @@ -451,11 +531,15 @@ function cleanString (str) { function parseIndex (data) { data = data.split(/^\/\*\*package(?:\s|$)/m) - if (data.length < 2) return null + if (data.length < 2) { + return null + } data = data[1] data = data.split(/\*\*\/$/m) - if (data.length < 2) return null + if (data.length < 2) { + return null + } data = data[0] data = data.replace(/^\s*\*/mg, '') |