read-package-json
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "read-package-json", | ||
"version": "0.0.2", | ||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
"name": "read-package-json", | ||
"description": "The thing npm uses to read package.json files with semantics and defaults and validation", | ||
"version": "0.0.1", | ||
"repository": { | ||
@@ -7,0 +7,0 @@ "type": "git", |
@@ -0,5 +1,7 @@ | ||
// vim: set softtabstop=16 shiftwidth=16: | ||
try { | ||
var log = require("npmlog") | ||
readJson.log = require("npmlog") | ||
} catch (er) { | ||
var log = { | ||
readJson.log = { | ||
info: function () {}, | ||
@@ -22,3 +24,3 @@ verbose: function () {}, | ||
var LRU = require("lru-cache") | ||
var cache = new LRU(1000) | ||
readJson.cache = new LRU(1000) | ||
var path = require("path") | ||
@@ -30,3 +32,4 @@ var glob = require("glob") | ||
var extraSet = [gypfile, wscript, serverjs, authors, readme, mans, bins] | ||
// put more stuff on here to customize. | ||
readJson.extraSet = [gypfile, wscript, serverjs, authors, readme, mans, bins] | ||
@@ -61,11 +64,11 @@ var typoWarned = {} | ||
function readJson (file, cb) { | ||
var c = cache.get(file) | ||
var c = readJson.cache.get(file) | ||
if (c) { | ||
log.verbose("from cache", file) | ||
readJson.log.verbose("from cache", file) | ||
cb = cb.bind(null, null, c) | ||
return process.nextTick(cb); | ||
} | ||
log.verbose("read json", file) | ||
readJson.log.verbose("read json", file) | ||
cb = (function (orig) { return function (er, data) { | ||
if (data) cache.set(file, data); | ||
if (data) readJson.cache.set(file, data); | ||
return orig(er, data) | ||
@@ -109,4 +112,5 @@ } })(cb) | ||
readJson.extras = extras | ||
function extras (file, data, cb) { | ||
asyncMap(extraSet, function (fn, cb) { | ||
asyncMap(readJson.extraSet, function (fn, cb) { | ||
return fn(file, data, cb) | ||
@@ -263,3 +267,3 @@ }, function (er) { | ||
cache.set(file, data) | ||
readJson.cache.set(file, data) | ||
cb(null, data) | ||
@@ -441,8 +445,4 @@ } | ||
function warn (f, d, m) { | ||
log.warn("package.json", d._id, m) | ||
readJson.log.warn("package.json", d._id, m) | ||
} | ||
@@ -449,0 +449,0 @@ |
24667
488