[Pkg-javascript-commits] [node-read-package-json] 01/05: Imported Upstream version 1.2.4

Jérémy Lal kapouer at moszumanska.debian.org
Tue Jul 29 00:01:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

kapouer pushed a commit to branch master
in repository node-read-package-json.

commit 09b10aa1fe6f33c5049c3ae5eefc70212c0d3905
Author: Jérémy Lal <kapouer at melix.org>
Date:   Tue Jul 29 01:53:22 2014 +0200

    Imported Upstream version 1.2.4
---
 .gitignore                         | 13 ++++++++++++
 package.json                       |  8 ++++----
 read-json.js                       | 41 ++++++++++++++++++++++++++++++++++----
 test/fixtures/not-json.css         |  2 +-
 test/fixtures/readmes/README       |  1 +
 test/fixtures/readmes/README.md    |  1 +
 test/fixtures/readmes/package.json |  1 +
 test/fixtures/readmes/readmexxx.yz |  1 +
 test/non-json.js                   |  3 ++-
 test/readmes.js                    | 29 +++++++++++++++++++++++++++
 10 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8c23dee
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+*.swp
+.*.swp
+
+.DS_Store
+*~
+.project
+.settings
+npm-debug.log
+coverage.html
+.idea
+lib-cov
+
+node_modules
diff --git a/package.json b/package.json
index 0214b34..ece351f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "read-package-json",
-  "version": "1.1.3",
+  "version": "1.2.4",
   "author": "Isaac Z. Schlueter <i at izs.me> (http://blog.izs.me/)",
   "description": "The thing npm uses to read package.json files with semantics and defaults and validation",
   "repository": {
@@ -12,15 +12,15 @@
     "test": "tap test/*.js"
   },
   "dependencies": {
-    "glob": "~3.2.1",
+    "glob": "^4.0.2",
     "lru-cache": "2",
-    "normalize-package-data": "~0.2"
+    "normalize-package-data": "0.4"
   },
   "devDependencies": {
     "tap": "~0.2.5"
   },
   "optionalDependencies": {
-    "graceful-fs": "2"
+    "graceful-fs": "2 || 3"
   },
   "license": "ISC"
 }
diff --git a/read-json.js b/read-json.js
index d9a4610..acb7d62 100644
--- a/read-json.js
+++ b/read-json.js
@@ -19,6 +19,7 @@ var normalizeData = require("normalize-package-data")
 readJson.extraSet = [
                 gypfile,
                 serverjs,
+                scriptpath,
                 authors,
                 readme,
                 mans,
@@ -110,6 +111,7 @@ function extras (file, data, log_, strict_, cb_) {
                                 else if (typeof arguments[i] === 'function')
                                                 log = arguments[i]
                 }
+                if (!log) log = function () {};
                 cb = arguments[i]
                 var set = readJson.extraSet
                 var n = set.length
@@ -125,6 +127,22 @@ function extras (file, data, log_, strict_, cb_) {
                 }
 }
 
+function scriptpath (file, data, cb) {
+                if (!data.scripts) return cb(null, data);
+                var k = Object.keys(data.scripts)
+                k.forEach(scriptpath_, data.scripts)
+                cb(null, data);
+}
+function scriptpath_(key) {
+                s = this[key]
+                // This is never allowed, and only causes problems
+                if (typeof s !== 'string')
+                                return delete this[key]
+                var spre = /^(\.[\/\\])?node_modules[\/\\].bin[\\\/]/
+                if (s.match(spre))
+                                this[key] = this[key].replace(spre, '')
+}
+
 function gypfile (file, data, cb) {
                 var dir = path.dirname(file)
                 var s = data.scripts || {}
@@ -213,17 +231,31 @@ function readme (file, data, cb) {
                 if (data.readme) return cb(null, data);
                 var dir = path.dirname(file)
                 var globOpts = { cwd: dir, nocase: true, mark: true }
-                glob("README?(.*)", globOpts, function (er, files) {
+                glob("{README,README.*}", globOpts, function (er, files) {
                                 if (er) return cb(er);
                                 // don't accept directories.
                                 files = files.filter(function (file) {
                                                 return !file.match(/\/$/)
                                 })
                                 if (!files.length) return cb();
-                                var rm = path.resolve(dir, files[0])
+                                var fn = preferMarkdownReadme(files)
+                                var rm = path.resolve(dir, fn)
                                 readme_(file, data, rm, cb)
                 })
 }
+function preferMarkdownReadme(files) {
+                var fallback = 0;
+                var re = /\.m?a?r?k?d?o?w?n?$/i
+                for (var i = 0; i < files.length; i++) {
+                                if (files[i].match(re))
+                                                return files[i]
+                                else if (files[i].match(/README$/))
+                                                fallback = i
+                }
+                // prefer README.md, followed by README; otherwise, return
+                // the first filename (which could be README)
+                return files[fallback];
+}
 function readme_(file, data, rm, cb) {
                 var rmfn = path.basename(rm);
                 fs.readFile(rm, "utf8", function (er, rm) {
@@ -318,9 +350,10 @@ function final (file, data, log, strict, cb) {
 }
 
 function makePackageId (data) {
-                return cleanString(data.name) + "@" + cleanString(data.version)
+                var name = cleanString(data.name)
+                var ver = cleanString(data.version)
+                return name + "@" + ver
 }
-
 function cleanString(str) {
                 return (!str || typeof(str) !== "string") ? "" : str.trim()
 }
diff --git a/test/fixtures/not-json.css b/test/fixtures/not-json.css
index 3716391..41c91e9 100644
--- a/test/fixtures/not-json.css
+++ b/test/fixtures/not-json.css
@@ -14,7 +14,7 @@ body {
   },
   "main": "read-json.js",
   "scripts": {
-    "test": "tap test/*.js"
+    "test": "./node_modules/.bin/tap test/*.js"
   },
   "dependencies": {
     "glob": "~3.1.9",
diff --git a/test/fixtures/readmes/README b/test/fixtures/readmes/README
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/test/fixtures/readmes/README
@@ -0,0 +1 @@
+foo
diff --git a/test/fixtures/readmes/README.md b/test/fixtures/readmes/README.md
new file mode 100644
index 0000000..e444c2f
--- /dev/null
+++ b/test/fixtures/readmes/README.md
@@ -0,0 +1 @@
+*markdown*
diff --git a/test/fixtures/readmes/package.json b/test/fixtures/readmes/package.json
new file mode 100644
index 0000000..b0c1a31
--- /dev/null
+++ b/test/fixtures/readmes/package.json
@@ -0,0 +1 @@
+{"name":"readmes", "version":"99.999.999999999"}
diff --git a/test/fixtures/readmes/readmexxx.yz b/test/fixtures/readmes/readmexxx.yz
new file mode 100644
index 0000000..662da91
--- /dev/null
+++ b/test/fixtures/readmes/readmexxx.yz
@@ -0,0 +1 @@
+extra noise
diff --git a/test/non-json.js b/test/non-json.js
index 09ee687..e8d989b 100644
--- a/test/non-json.js
+++ b/test/non-json.js
@@ -25,7 +25,8 @@ var expect =
      npmlog: '0',
      'graceful-fs': '~1.1.8' },
   devDependencies: { tap: '~0.2.5' },
-  optionalDependencies: { npmlog: '0', 'graceful-fs': '~1.1.8' },
+ homepage: "https://github.com/isaacs/read-package-json",
+ optionalDependencies: { npmlog: '0', 'graceful-fs': '~1.1.8' },
   _id: 'read-package-json at 0.1.1',
   readme: 'ERROR: No README data found!' }
 
diff --git a/test/readmes.js b/test/readmes.js
new file mode 100644
index 0000000..1c1cee1
--- /dev/null
+++ b/test/readmes.js
@@ -0,0 +1,29 @@
+// vim: set softtabstop=16 shiftwidth=16:
+var tap = require("tap")
+var readJson = require("../")
+var path = require("path")
+var fs = require("fs")
+var p = path.resolve(__dirname, "fixtures/readmes/package.json")
+
+var expect = {}
+var expect = {
+  "name" : "readmes",
+  "version" : "99.999.999999999",
+  "readme" : "*markdown*\n",
+  "readmeFilename" : "README.md",
+  "description" : "*markdown*",
+  "_id" : "readmes at 99.999.999999999"
+}
+
+console.error("readme test")
+tap.test("readme test", function (t) {
+                readJson(p, function (er, data) {
+                                if (er) throw er;
+                                test(t, data)
+                })
+})
+
+function test(t, data) {
+                t.deepEqual(data, expect)
+                t.end()
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-read-package-json.git



More information about the Pkg-javascript-commits mailing list