broccoli-caching-writer
Advanced tools
Comparing version 0.2.1 to 0.2.2
40
index.js
@@ -36,3 +36,3 @@ var fs = require('fs'); | ||
return readTree(this.inputTree).then(function (srcDir) { | ||
var inputTreeKeys = relativeKeysForTree(srcDir); | ||
var inputTreeKeys = keysForTree(srcDir); | ||
var inputTreeHash = helpers.hashStrings(inputTreeKeys); | ||
@@ -62,6 +62,11 @@ | ||
function relativeKeysForTree (root, relativePath, _stack, _followSymlink) { | ||
var stats, statKeys | ||
if (!relativePath) { relativePath = ''; } | ||
var fullPath = path.join(root, relativePath); | ||
function keysForTree (fullPath, options) { | ||
options = options || {} | ||
var _stack = options._stack | ||
var _followSymlink = options._followSymlink | ||
var relativePath = options.relativePath || '.' | ||
var stats | ||
var statKeys | ||
try { | ||
@@ -79,2 +84,7 @@ if (_followSymlink) { | ||
var childKeys = [] | ||
if (stats) { | ||
statKeys = ['stats', stats.mode, stats.size] | ||
} else { | ||
statKeys = ['stat failed'] | ||
} | ||
if (stats && stats.isDirectory()) { | ||
@@ -97,7 +107,11 @@ var fileIdentity = stats.dev + '\x00' + stats.ino | ||
for (var i = 0; i < entries.length; i++) { | ||
childKeys = childKeys.concat(relativeKeysForTree(root, path.join(relativePath, entries[i]), _stack)) | ||
var keys = keysForTree(path.join(fullPath, entries[i]), { | ||
_stack: _stack, | ||
relativePath: path.join(relativePath, entries[i]) | ||
}) | ||
childKeys = childKeys.concat(keys) | ||
} | ||
} | ||
} | ||
statKeys = ['dir - stats', stats.mode, stats.size]; | ||
} else if (stats && stats.isSymbolicLink()) { | ||
@@ -111,12 +125,12 @@ if (_stack == null) { | ||
} | ||
childKeys = relativeKeysForTree(root, relativePath, _stack, true) // follow symlink | ||
childKeys = keysForTree(fullPath, {_stack: _stack, relativePath: relativePath, _followSymlink: true}) // follow symlink | ||
statKeys.push(stats.mtime.getTime()) | ||
} else if (stats && stats.isFile()) { | ||
statKeys.push(stats.mtime.getTime()) | ||
} | ||
if (!statKeys) { | ||
statKeys = ['stats', stats.mode, stats.size, stats.mtime.getTime()]; | ||
} | ||
// Perhaps we should not use basename to infer the file name | ||
return ['path', path.basename(relativePath)] | ||
.concat(stats ? statKeys : ['stat failed']) | ||
return ['path', relativePath] | ||
.concat(statKeys) | ||
.concat(childKeys) | ||
} |
{ | ||
"name": "broccoli-caching-writer", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
10160
220