You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
664 B
43 lines
664 B
/**
|
|
* Modules
|
|
*/
|
|
|
|
var path = require('path')
|
|
|
|
/**
|
|
* Vars
|
|
*/
|
|
|
|
var relative = path.relative
|
|
var lastCwd = process.cwd()
|
|
var cache = Object.create(null)
|
|
|
|
/**
|
|
* Expose cachedPathRelative
|
|
*/
|
|
|
|
module.exports = cachedPathRelative
|
|
|
|
/**
|
|
* cachedPathRelative
|
|
*/
|
|
|
|
function cachedPathRelative (from, to) {
|
|
// If the current working directory changes, we need
|
|
// to invalidate the cache
|
|
var cwd = process.cwd()
|
|
if (cwd !== lastCwd) {
|
|
cache = {}
|
|
lastCwd = cwd
|
|
}
|
|
|
|
if (cache[from] && cache[from][to]) return cache[from][to]
|
|
|
|
var result = relative.call(path, from, to)
|
|
|
|
cache[from] = cache[from] || {}
|
|
cache[from][to] = result
|
|
|
|
return result
|
|
|
|
}
|