Coverage

100%
20
20
0

/Users/jwomack/Projects/github/jameswomack/paqman/lib/paqman.js

100%
20
20
0
LineHitsSource
11var Path = require('path'),
2 LRU = require('lru-cache')
3
41module.exports = Object.create({
5 CWD: process.cwd(), // For overrides
6 pathPrefix: './', // Also for overrides
7 packageFileName: 'package.json', // Also for overrides
8 didCachePackageMembers: false, // For package member caching
9 allowCacheOverwrites: false,
10 cache: LRU(),
11 previousRequireCwd: null,
12 fromCache: function (key, creationLambda) {
1313 var retVal
1413 if (!(retVal = this.cache.get(key))) {
153 this.cache.set(key, (retVal = creationLambda(key)))
16 }
1713 return retVal
18 },
19 relativePath: function relativePath(pathRelativeToCwd) {
202 return this.fromCache(this.pathPrefix + pathRelativeToCwd, Path.join.bind(Path, this.CWD))
21 },
22 relativeRequire: function relativeRequire(pathRelativeToCwd) {
232 var path = this.relativePath(pathRelativeToCwd)
242 return require(path)
25 },
26 uninstallRelativeRequire: function installRelativeRequire() {
274 global.requireCwd = this.previousRequireCwd
284 this.previousRequireCwd = null
29 },
30 installRelativeRequire: function installRelativeRequire() {
312 this.previousRequireCwd = global.requireCwd
322 global.requireCwd = this.relativeRequire.bind(this)
33 },
34 get packageJSON() {
3511 var packageJSON = this.fromCache(this.packageFileName, this.relativeRequire.bind(this, this.packageFileName))
3611 if (!this.didCachePackageMembers) {
371 Object.keys(packageJSON).forEach(function (key) {
3814 if (!this.cache.has(key) || this.allowCacheOverwrites) {
3914 this.cache.set(key, packageJSON[key])
40 }
41 }.bind(this))
421 this.didCachePackageMembers = true
43 }
4411 return packageJSON
45 }
46})
47