cached-loader
Advanced tools
Comparing version 0.0.3 to 0.0.4
39
index.js
@@ -11,13 +11,13 @@ var mkdirp = require('mkdirp'); | ||
var query = loaderUtils.parseQuery(this.query); | ||
if (!query.cacheDir) { | ||
throw new Error('required query arg "cacheDir" not set'); | ||
if (!query.cacheDirectory) { | ||
throw new Error('required query arg "cacheDirectory" not set'); | ||
} | ||
ensureCacheDir(query.cacheDir); | ||
data.cacheDir = query.cacheDir; | ||
data.cacheKeyRoot = query.cacheKeyRoot || ''; | ||
ensureCacheDir(query.cacheDirectory); | ||
data.cacheDirectory = query.cacheDirectory; | ||
data.cacheIdentifier = query.cacheIdentifier || ''; | ||
data.debug = query.debug; | ||
var cacheRecord = readCache( | ||
query.cacheKeyRoot, | ||
query.cacheDir, | ||
query.cacheIdentifier, | ||
query.cacheDirectory, | ||
this.resourcePath, | ||
@@ -38,8 +38,8 @@ query.debug ? logToStderr : logToNull | ||
if (!this.data.cacheDir) return content; | ||
ensureCacheDir(this.data.cacheDir); | ||
if (!this.data.cacheDirectory) return content; | ||
ensureCacheDir(this.data.cacheDirectory); | ||
writeCache( | ||
this.data.cacheKeyRoot, | ||
this.data.cacheDir, | ||
this.data.cacheIdentifier, | ||
this.data.cacheDirectory, | ||
this.resourcePath, | ||
@@ -60,4 +60,4 @@ content, | ||
function writeCache(cacheKeyRoot, cacheDir, resourcePath, content, fileDependencies, log) { | ||
var key = digest(cacheKeyRoot + readFile(resourcePath)); | ||
function writeCache(cacheIdentifier, cacheDirectory, resourcePath, content, fileDependencies, log) { | ||
var key = digest(cacheIdentifier + readFile(resourcePath)); | ||
@@ -67,3 +67,3 @@ var dependencies = {}; | ||
fileDependencies.forEach(function(depFile) { | ||
dependencies[depFile] = digest(cacheKeyRoot + readFile(depFile)); | ||
dependencies[depFile] = digest(cacheIdentifier + readFile(depFile)); | ||
}); | ||
@@ -77,10 +77,9 @@ | ||
log('writeCache', key, resourcePath); | ||
writeFile(path.join(cacheDir, key), JSON.stringify(cacheRecord)); | ||
writeFile(path.join(cacheDirectory, key), JSON.stringify(cacheRecord)); | ||
} | ||
function readCache(cacheKeyRoot, cacheDir, resourcePath, log) { | ||
var key = digest(cacheKeyRoot + readFile(resourcePath)); | ||
function readCache(cacheIdentifier, cacheDirectory, resourcePath, log) { | ||
var key = digest(cacheIdentifier + readFile(resourcePath)); | ||
@@ -91,3 +90,3 @@ log('readCache', key, resourcePath); | ||
try { | ||
cacheRecord = JSON.parse(readFile(path.join(cacheDir, key))); | ||
cacheRecord = JSON.parse(readFile(path.join(cacheDirectory, key))); | ||
} catch (err) { | ||
@@ -103,3 +102,3 @@ log('readCache miss', err + ''); | ||
var cachedVersionDigest = cacheRecord.dependencies[depFiles[i]]; | ||
var currentDigest = digest(cacheKeyRoot + readFile(depFile)); | ||
var currentDigest = digest(cacheIdentifier + readFile(depFile)); | ||
@@ -106,0 +105,0 @@ // if digest of any dependency has changed, the cached version is invalid |
{ | ||
"name": "cached-loader", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -29,4 +29,4 @@ # cached-loader | ||
query: { | ||
cacheDir: path.join(opts.rootDir, 'tmp/cache/cached-loader'), | ||
cacheKeyRoot: JSON.stringify(opts) + JSON.stringify(sassConfig), | ||
cacheDirectory: path.join(opts.rootDir, 'tmp/cache/cached-loader'), | ||
cacheIdentifier: JSON.stringify(opts) + JSON.stringify(sassConfig), | ||
}, | ||
@@ -33,0 +33,0 @@ }, |
7265