diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-02-10 09:27:45 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-02-10 09:27:45 +0300 |
commit | add5890ce447dabf120b907a85f715df1e065f44 (patch) | |
tree | d5eebd936d04200c0334087873f6ce928cc0ae19 /node_modules/read-package-json/read-json.js | |
parent | a988590d10727b956c6fe1ef84abfa70ddbeed11 (diff) |
read-package-json@1.3.1
Warns when a bin reference is a dangling reference.
Diffstat (limited to 'node_modules/read-package-json/read-json.js')
-rw-r--r-- | node_modules/read-package-json/read-json.js | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/node_modules/read-package-json/read-json.js b/node_modules/read-package-json/read-json.js index acb7d62d8..863f8e8e3 100644 --- a/node_modules/read-package-json/read-json.js +++ b/node_modules/read-package-json/read-json.js @@ -332,6 +332,31 @@ function githead_ (file, data, dir, head, cb) { }) } +/** + * Warn if the bin references don't point to anything. This might be better in + * normalize-package-data if it had access to the file path. + */ +function checkBinReferences_ (file, data, warn, cb) { + if (!(data.bin instanceof Object)) return cb() + + var keys = Object.keys(data.bin) + var keysLeft = keys.length + if (!keysLeft) return cb() + + function handleExists(relName, result) { + keysLeft-- + if (!result) warn("No bin file found at " + relName) + if (!keysLeft) cb() + } + + keys.forEach(function (key) { + var dirName = path.dirname(file) + var relName = data.bin[key] + var binPath = path.resolve(dirName, relName) + fs.exists(binPath, handleExists.bind(null, relName)) + }) +} + function final (file, data, log, strict, cb) { var pId = makePackageId(data) function warn(msg) { @@ -344,9 +369,11 @@ function final (file, data, log, strict, cb) { catch (error) { return cb(error) } - typoWarned[pId] = true - readJson.cache.set(file, data) - cb(null, data) + checkBinReferences_(file, data, warn, function () { + typoWarned[pId] = true + readJson.cache.set(file, data) + cb(null, data) + }) } function makePackageId (data) { |