read-package-json
Advanced tools
Comparing version 0.1.9 to 0.1.10
{ | ||
"name": "read-package-json", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
@@ -5,0 +5,0 @@ "description": "The thing npm uses to read package.json files with semantics and defaults and validation", |
@@ -32,3 +32,12 @@ // vim: set softtabstop=16 shiftwidth=16: | ||
// 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 | ||
] | ||
@@ -307,2 +316,37 @@ var typoWarned = {} | ||
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) { | ||
@@ -309,0 +353,0 @@ var ret = validName(file, data) |
@@ -8,2 +8,9 @@ // vim: set softtabstop=16 shiftwidth=16: | ||
var package = require("../package.json") | ||
var isGit | ||
try { | ||
fs.readFileSync(path.resolve(__dirname, '../.git/HEAD')); | ||
isGit = true | ||
} catch (e) { | ||
isGit = false | ||
} | ||
@@ -29,2 +36,4 @@ console.error("basic test") | ||
if (isGit) t.similar(data.gitHead, /^[a-f0-9]{40}$/); | ||
// optional deps are folded in. | ||
@@ -31,0 +40,0 @@ t.deepEqual(data.optionalDependencies, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35868
743