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 | |
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')
-rw-r--r-- | node_modules/read-package-json/package.json | 19 | ||||
-rw-r--r-- | node_modules/read-package-json/read-json.js | 33 | ||||
-rw-r--r-- | node_modules/read-package-json/test/bin.js | 43 | ||||
-rw-r--r-- | node_modules/read-package-json/test/fixtures/badbin.json | 11 | ||||
-rw-r--r-- | node_modules/read-package-json/test/fixtures/bin.json | 11 | ||||
-rw-r--r-- | node_modules/read-package-json/test/fixtures/bin/echo | 3 | ||||
-rw-r--r-- | node_modules/read-package-json/test/fixtures/emptybin.json | 11 |
7 files changed, 119 insertions, 12 deletions
diff --git a/node_modules/read-package-json/package.json b/node_modules/read-package-json/package.json index 1fd2f674f..3c2ff0ff8 100644 --- a/node_modules/read-package-json/package.json +++ b/node_modules/read-package-json/package.json @@ -1,6 +1,6 @@ { "name": "read-package-json", - "version": "1.2.7", + "version": "1.3.1", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me", @@ -30,15 +30,16 @@ "graceful-fs": "2 || 3" }, "license": "ISC", - "gitHead": "41d6696c527e32a1cb38ebf0b6fc91b489b0499c", + "gitHead": "59011e6b660cf0cc916646a08955c12a8f990174", "bugs": { "url": "https://github.com/isaacs/read-package-json/issues" }, "homepage": "https://github.com/isaacs/read-package-json", - "_id": "read-package-json@1.2.7", - "_shasum": "f0b440c461a218f4dbf48b094e80fc65c5248502", - "_from": "read-package-json@>=1.2.7-0 <1.3.0-0", - "_npmVersion": "2.0.0-beta.0", + "_id": "read-package-json@1.3.1", + "_shasum": "5a965f9fc34b25ffa5e0d93b1d0fc063af6d10b0", + "_from": "read-package-json@1.3.1", + "_npmVersion": "2.5.1", + "_nodeVersion": "0.12.0", "_npmUser": { "name": "othiym23", "email": "ogd@aoaioxxysz.net" @@ -54,9 +55,9 @@ } ], "dist": { - "shasum": "f0b440c461a218f4dbf48b094e80fc65c5248502", - "tarball": "http://registry.npmjs.org/read-package-json/-/read-package-json-1.2.7.tgz" + "shasum": "5a965f9fc34b25ffa5e0d93b1d0fc063af6d10b0", + "tarball": "http://registry.npmjs.org/read-package-json/-/read-package-json-1.3.1.tgz" }, "directories": {}, - "_resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-1.2.7.tgz" + "_resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-1.3.1.tgz" } 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) { diff --git a/node_modules/read-package-json/test/bin.js b/node_modules/read-package-json/test/bin.js new file mode 100644 index 000000000..2ed4ec5ca --- /dev/null +++ b/node_modules/read-package-json/test/bin.js @@ -0,0 +1,43 @@ +// vim: set softtabstop=16 shiftwidth=16: +var tap = require("tap") +var readJson = require("../") +var path = require("path") +var fs = require("fs") + +var createWarningCollector = function () { + var warn = function (msg) { + warn.warnings.push(arguments) + } + warn.warnings = [] + return warn +} + +tap.test("Bin test", function (t) { + var p = path.resolve(__dirname, "fixtures/bin.json") + var warn = createWarningCollector() + readJson(p, warn, function (er, data) { + t.equals(warn.warnings.length, 0) + t.deepEqual(data.bin, {"bin-test": "./bin/echo"}) + t.end() + }) +}) + +tap.test("Bad bin test", function (t) { + var p = path.resolve(__dirname, "fixtures/badbin.json") + var warn = createWarningCollector() + readJson(p, warn, function (er, data) { + t.equals(warn.warnings.length, 1) + t.equals(warn.warnings[0][2], "No bin file found at ./bin/typo") + t.end() + }) +}) + +tap.test("Empty bin test", function (t) { + var p = path.resolve(__dirname, "fixtures/emptybin.json") + var warn = createWarningCollector() + readJson(p, warn, function (er, data) { + t.equals(warn.warnings.length, 0) + t.same(data.bin, {}, "no mapping to bin because object was empty") + t.end() + }) +}) diff --git a/node_modules/read-package-json/test/fixtures/badbin.json b/node_modules/read-package-json/test/fixtures/badbin.json new file mode 100644 index 000000000..06c57f43b --- /dev/null +++ b/node_modules/read-package-json/test/fixtures/badbin.json @@ -0,0 +1,11 @@ +{ + "name": "badbin-test", + "description": "my desc", + "repository": { + "type": "git", + "url": "git://github.com/npm/read-package-json.git" + }, + "version": "0.0.1", + "readme": "hello world", + "bin": "./bin/typo" +} diff --git a/node_modules/read-package-json/test/fixtures/bin.json b/node_modules/read-package-json/test/fixtures/bin.json new file mode 100644 index 000000000..d47a5270c --- /dev/null +++ b/node_modules/read-package-json/test/fixtures/bin.json @@ -0,0 +1,11 @@ +{ + "name": "bin-test", + "description": "my desc", + "repository": { + "type": "git", + "url": "git://github.com/npm/read-package-json.git" + }, + "version": "0.0.1", + "readme": "hello world", + "bin": "./bin/echo" +} diff --git a/node_modules/read-package-json/test/fixtures/bin/echo b/node_modules/read-package-json/test/fixtures/bin/echo new file mode 100644 index 000000000..aaed87850 --- /dev/null +++ b/node_modules/read-package-json/test/fixtures/bin/echo @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "Hello world"
\ No newline at end of file diff --git a/node_modules/read-package-json/test/fixtures/emptybin.json b/node_modules/read-package-json/test/fixtures/emptybin.json new file mode 100644 index 000000000..ef926f04d --- /dev/null +++ b/node_modules/read-package-json/test/fixtures/emptybin.json @@ -0,0 +1,11 @@ +{ + "name": "badbin-test", + "description": "my desc", + "repository": { + "type": "git", + "url": "git://github.com/npm/read-package-json.git" + }, + "version": "0.0.1", + "readme": "hello world", + "bin": {} +} |