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-08-02 03:10:09 +0400
committerisaacs <i@izs.me>2012-08-02 03:10:09 +0400
commitab36c089eebd8b4f46a99fc04d7885fcc349a286 (patch)
tree6d3681c3b454bd3233e8a237d25242578f13d91d
parentecb82ffa84767f24f6b2c6cb614c57b878a361bf (diff)
read-package-json@0.1.2
-rw-r--r--node_modules/read-package-json/package.json6
-rw-r--r--node_modules/read-package-json/read-json.js34
-rw-r--r--node_modules/read-package-json/test/basic.js1
-rw-r--r--node_modules/read-package-json/test/fixtures/not-json.css37
-rw-r--r--node_modules/read-package-json/test/non-json.js77
5 files changed, 137 insertions, 18 deletions
diff --git a/node_modules/read-package-json/package.json b/node_modules/read-package-json/package.json
index c3b300038..e585627ec 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.1",
+ "version": "0.1.2",
"author": {
"name": "Isaac Z. Schlueter",
"email": "i@izs.me",
@@ -31,6 +31,6 @@
"graceful-fs": "~1.1.8"
},
"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",
- "_id": "read-package-json@0.1.1",
- "_from": "read-package-json@~0.1.0"
+ "_id": "read-package-json@0.1.2",
+ "_from": "read-package-json@~0.1.1"
}
diff --git a/node_modules/read-package-json/read-json.js b/node_modules/read-package-json/read-json.js
index bb1c95262..385fc3304 100644
--- a/node_modules/read-package-json/read-json.js
+++ b/node_modules/read-package-json/read-json.js
@@ -76,21 +76,25 @@ function readJson (file, cb) {
function readJson_ (file, cb) {
fs.readFile(file, "utf8", function (er, d) {
- if (er && er.code === "ENOENT") {
- indexjs(file, er, cb)
- return
- }
- if (er) return cb(er);
- try {
- d = JSON.parse(d)
- } catch (er) {
- er = parseError(er, file);
- return cb(er);
- }
- extras(file, d, cb)
+ parseJson(file, er, d, cb)
})
}
+function parseJson (file, er, d, cb) {
+ if (er && er.code === "ENOENT") {
+ indexjs(file, er, cb)
+ return
+ }
+ if (er) return cb(er);
+ try {
+ d = JSON.parse(d)
+ } catch (er) {
+ d = parseIndex(d)
+ if (!d) return cb(parseError(er, file));
+ }
+ extras(file, d, cb)
+}
+
function indexjs (file, er, cb) {
if (path.basename(file) === "index.js") {
@@ -226,7 +230,7 @@ function readme (file, data, cb) {
var globOpts = { cwd: dir, nocase: true }
glob("README?(.*)", globOpts, function (er, files) {
if (er) return cb(er);
- if (!files.length) return cb()
+ if (!files.length) return cb();
var rm = path.resolve(dir, files[0])
readme_(file, data, rm, cb)
})
@@ -329,8 +333,6 @@ function parseError (ex, file) {
// a warning for deprecated or likely-incorrect fields
function typoWarn (file, data) {
- if (typoWarned[data._id]) return;
- typoWarned[data._id] = true
if (data.modules) {
warn(file, data,
"'modules' is deprecated")
@@ -342,6 +344,7 @@ function typoWarn (file, data) {
bugsTypoWarn(file, data)
scriptTypoWarn(file, data)
noreadmeWarn(file, data)
+ typoWarned[data._id] = true
}
function noreadmeWarn (file, data) {
@@ -485,6 +488,7 @@ function depObjectify (file, data, deps) {
function warn (f, d, m) {
+ if (typoWarned[d._id]) return;
readJson.log.warn("package.json", d._id, m)
}
diff --git a/node_modules/read-package-json/test/basic.js b/node_modules/read-package-json/test/basic.js
index 72ba81424..2e5cf7eda 100644
--- a/node_modules/read-package-json/test/basic.js
+++ b/node_modules/read-package-json/test/basic.js
@@ -1,3 +1,4 @@
+// vim: set softtabstop=16 shiftwidth=16:
var tap = require("tap")
var readJson = require("../")
var path = require("path")
diff --git a/node_modules/read-package-json/test/fixtures/not-json.css b/node_modules/read-package-json/test/fixtures/not-json.css
new file mode 100644
index 000000000..37163912d
--- /dev/null
+++ b/node_modules/read-package-json/test/fixtures/not-json.css
@@ -0,0 +1,37 @@
+body {
+ height: yo mama
+}
+
+/**package
+{
+ "name": "read-package-json",
+ "version": "0.1.1",
+ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
+ "description": "The thing npm uses to read package.json files with semantics and defaults and validation",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/read-package-json.git"
+ },
+ "main": "read-json.js",
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "dependencies": {
+ "glob": "~3.1.9",
+ "lru-cache": "~1.1.0",
+ "semver": "~1.0.14",
+ "slide": "~1.1.3"
+ },
+ "devDependencies": {
+ "tap": "~0.2.5"
+ },
+ "optionalDependencies": {
+ "npmlog": "0",
+ "graceful-fs": "~1.1.8"
+ }
+}
+**/
+
+html {
+ width: so fat
+}
diff --git a/node_modules/read-package-json/test/non-json.js b/node_modules/read-package-json/test/non-json.js
new file mode 100644
index 000000000..8f8feb10d
--- /dev/null
+++ b/node_modules/read-package-json/test/non-json.js
@@ -0,0 +1,77 @@
+// vim: set softtabstop=16 shiftwidth=16:
+var tap = require('tap')
+var readJson = require('../')
+var path = require('path')
+var fs = require('fs')
+var expect =
+{ name: 'read-package-json',
+ version: '0.1.1',
+ author:
+ { name: 'Isaac Z. Schlueter',
+ email: 'i@izs.me',
+ url: 'http://blog.izs.me/' },
+ description: 'The thing npm uses to read package.json files with semantics and defaults and validation',
+ repository:
+ { type: 'git',
+ url: 'git://github.com/isaacs/read-package-json.git' },
+ main: 'read-json.js',
+ scripts: { test: 'tap test/*.js' },
+ dependencies:
+ { glob: '~3.1.9',
+ 'lru-cache': '~1.1.0',
+ semver: '~1.0.14',
+ slide: '~1.1.3',
+ npmlog: '0',
+ 'graceful-fs': '~1.1.8' },
+ devDependencies: { tap: '~0.2.5' },
+ optionalDependencies: { npmlog: '0', 'graceful-fs': '~1.1.8' },
+ _id: 'read-package-json@0.1.1',
+ readme: 'ERROR: No README.md file found!' }
+
+tap.test('from css', function (t) {
+ var c = path.join(__dirname, 'fixtures', 'not-json.css')
+ readJson(c, function (er, d) {
+ t.same(d, expect)
+ t.end()
+ })
+})
+
+tap.test('from js', function (t) {
+ readJson(__filename, function (er, d) {
+ t.same(d, expect)
+ t.end()
+ })
+})
+
+
+
+/**package
+{
+ "name": "read-package-json",
+ "version": "0.1.1",
+ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
+ "description": "The thing npm uses to read package.json files with semantics and defaults and validation",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/read-package-json.git"
+ },
+ "main": "read-json.js",
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "dependencies": {
+ "glob": "~3.1.9",
+ "lru-cache": "~1.1.0",
+ "semver": "~1.0.14",
+ "slide": "~1.1.3"
+ },
+ "devDependencies": {
+ "tap": "~0.2.5"
+ },
+ "optionalDependencies": {
+ "npmlog": "0",
+ "graceful-fs": "~1.1.8"
+ }
+}
+**/
+