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>2012-11-30 01:46:37 +0400
committerisaacs <i@izs.me>2012-11-30 01:46:37 +0400
commitaf07eab1a9bed1839b86e282b11336fada731443 (patch)
treea3a72b7ac00e670175e49128547b821aa8fb1fcb /node_modules/read-package-json
parent00cba324d44885b3ba72ae32a64331bc9f77cc7c (diff)
read-package-json@0.1.10
Diffstat (limited to 'node_modules/read-package-json')
-rw-r--r--node_modules/read-package-json/package.json4
-rw-r--r--node_modules/read-package-json/read-json.js46
-rw-r--r--node_modules/read-package-json/test/basic.js9
3 files changed, 56 insertions, 3 deletions
diff --git a/node_modules/read-package-json/package.json b/node_modules/read-package-json/package.json
index 84bdf34f1..c64dd61d1 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": "0.1.9",
+ "version": "0.1.10",
"author": {
"name": "Isaac Z. Schlueter",
"email": "i@izs.me",
@@ -32,6 +32,6 @@
},
"readme": "# read-package-json\n\nThis is the thing that npm uses to read package.json files. It\nvalidates some stuff, and loads some default things.\n\nIt keeps a cache of the files you've read, so that you don't end\nup reading the same package.json file multiple times.\n\nNote that if you just want to see what's literally in the package.json\nfile, you can usually do `var data = require('some-module/package.json')`.\n\nThis module is basically only needed by npm, but it's handy to see what\nnpm will see when it looks at your package.\n\n## Usage\n\n```javascript\nvar readJson = require('read-package-json')\n\nreadJson('/path/to/package.json', function (er, data) {\n if (er) {\n console.error(\"There was an error reading the file\")\n return\n }\n\n console.error('the package data is', data)\n}\n```\n\n## readJson(file, cb)\n\n* `file` {String} The path to the package.json file\n* `cb` {Function}\n\nReads the JSON file and does the things.\n\n## `package.json` Fields\n\nSee `man 5 package.json` or `npm help json`.\n\n## readJson.log\n\nBy default this is a reference to the `npmlog` module. But if that\nmodule can't be found, then it'll be set to just a dummy thing that does\nnothing.\n\nReplace with your own `{log,warn,error}` object for fun loggy time.\n\n## readJson.extras(file, data, cb)\n\nRun all the extra stuff relative to the file, with the parsed data.\n\nModifies the data as it does stuff. Calls the cb when it's done.\n\n## readJson.extraSet = [fn, fn, ...]\n\nArray of functions that are called by `extras`. Each one receives the\narguments `fn(file, data, cb)` and is expected to call `cb(er, data)`\nwhen done or when an error occurs.\n\nOrder is indeterminate, so each function should be completely\nindependent.\n\nMix and match!\n\n## readJson.cache\n\nThe `lru-cache` object that readJson uses to not read the same file over\nand over again. See\n[lru-cache](https://github.com/isaacs/node-lru-cache) for details.\n\n## Other Relevant Files Besides `package.json`\n\nSome other files have an effect on the resulting data object, in the\nfollowing ways:\n\n### `README?(.*)`\n\nIf there is a `README` or `README.*` file present, then npm will attach\na `readme` field to the data with the contents of this file.\n\nOwing to the fact that roughly 100% of existing node modules have\nMarkdown README files, it will generally be assumed to be Markdown,\nregardless of the extension. Please plan accordingly.\n\n### `server.js`\n\nIf there is a `server.js` file, and there is not already a\n`scripts.start` field, then `scripts.start` will be set to `node\nserver.js`.\n\n### `AUTHORS`\n\nIf there is not already a `contributors` field, then the `contributors`\nfield will be set to the contents of the `AUTHORS` file, split by lines,\nand parsed.\n\n### `bindings.gyp`\n\nIf a bindings.gyp file exists, and there is not already a\n`scripts.install` field, then the `scripts.install` field will be set to\n`node-gyp rebuild`.\n\n### `wscript`\n\nIf a wscript file exists, and there is not already a `scripts.install`\nfield, then the `scripts.install` field will be set to `node-waf clean ;\nnode-waf configure build`.\n\nNote that the `bindings.gyp` file supercedes this, since node-waf has\nbeen deprecated in favor of node-gyp.\n\n### `index.js`\n\nIf the json file does not exist, but there is a `index.js` file\npresent instead, and that file has a package comment, then it will try\nto parse the package comment, and use that as the data instead.\n\nA package comment looks like this:\n\n```javascript\n/**package\n * { \"name\": \"my-bare-module\"\n * , \"version\": \"1.2.3\"\n * , \"description\": \"etc....\" }\n **/\n\n// or...\n\n/**package\n{ \"name\": \"my-bare-module\"\n, \"version\": \"1.2.3\"\n, \"description\": \"etc....\" }\n**/\n```\n\nThe important thing is that it starts with `/**package`, and ends with\n`**/`. If the package.json file exists, then the index.js is not\nparsed.\n\n### `{directories.man}/*.[0-9]`\n\nIf there is not already a `man` field defined as an array of files or a\nsingle file, and\nthere is a `directories.man` field defined, then that directory will\nbe searched for manpages.\n\nAny valid manpages found in that directory will be assigned to the `man`\narray, and installed in the appropriate man directory at package install\ntime, when installed globally on a Unix system.\n\n### `{directories.bin}/*`\n\nIf there is not already a `bin` field defined as a string filename or a\nhash of `<name> : <filename>` pairs, then the `directories.bin`\ndirectory will be searched and all the files within it will be linked as\nexecutables at install time.\n\nWhen installing locally, npm links bins into `node_modules/.bin`, which\nis in the `PATH` environ when npm runs scripts. When\ninstalling globally, they are linked into `{prefix}/bin`, which is\npresumably in the `PATH` environment variable.\n",
"readmeFilename": "README.md",
- "_id": "read-package-json@0.1.9",
+ "_id": "read-package-json@0.1.10",
"_from": "read-package-json@~0.1.8"
}
diff --git a/node_modules/read-package-json/read-json.js b/node_modules/read-package-json/read-json.js
index b13e32146..42efbc60e 100644
--- a/node_modules/read-package-json/read-json.js
+++ b/node_modules/read-package-json/read-json.js
@@ -29,7 +29,16 @@ var asyncMap = slide.asyncMap
var semver = require("semver")
// put more stuff on here to customize.
-readJson.extraSet = [gypfile, wscript, serverjs, authors, readme, mans, bins]
+readJson.extraSet = [
+ gypfile,
+ wscript,
+ serverjs,
+ authors,
+ readme,
+ mans,
+ bins,
+ githead
+]
var typoWarned = {}
// http://registry.npmjs.org/-/fields
@@ -303,6 +312,41 @@ function bins_ (file, data, bins, cb) {
return cb(null, data)
}
+function githead (file, data, cb) {
+ 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)
+ })
+}
+function githead_ (file, data, dir, head, cb) {
+ if (!head.match(/^ref: /)) {
+ data.gitHead = head.trim()
+ return cb(null, data)
+ }
+ var headFile = head.replace(/^ref: /, '').trim()
+ headFile = path.resolve(dir, '.git', headFile)
+ fs.readFile(headFile, 'utf8', function (er, head) {
+ head = head.replace(/^ref: /, '').trim()
+ data.gitHead = head
+ return cb(null, data)
+ })
+}
+
+
+try {
+ gitHead = fs.readFileSync('.git/HEAD', 'utf8').trim()
+ if (gitHead.match(/^ref: /)) {
+ gitHead = gitHead.replace(/^ref: /, '').trim()
+ gitHead = fs.readFileSync('.git/' + gitHead, 'utf8').trim()
+ }
+ config.HEAD = gitHead
+} catch (_) {
+ gitHead = '(not a git repo) ' + _.message
+}
+
function final (file, data, cb) {
var ret = validName(file, data)
if (ret !== true) return cb(ret);
diff --git a/node_modules/read-package-json/test/basic.js b/node_modules/read-package-json/test/basic.js
index 977faaa7a..8590f23c0 100644
--- a/node_modules/read-package-json/test/basic.js
+++ b/node_modules/read-package-json/test/basic.js
@@ -5,6 +5,13 @@ var path = require("path")
var fs = require("fs")
var readme = fs.readFileSync(path.resolve(__dirname, "../README.md"), "utf8")
var package = require("../package.json")
+var isGit
+try {
+ fs.readFileSync(path.resolve(__dirname, '../.git/HEAD'));
+ isGit = true
+} catch (e) {
+ isGit = false
+}
console.error("basic test")
tap.test("basic test", function (t) {
@@ -25,6 +32,8 @@ function basic_ (t, data) {
t.equal(data.main, package.main)
t.equal(data.readmeFilename, 'README.md')
+ if (isGit) t.similar(data.gitHead, /^[a-f0-9]{40}$/);
+
// optional deps are folded in.
t.deepEqual(data.optionalDependencies,
package.optionalDependencies)