broccoli-caching-writer
Advanced tools
Comparing version 0.1.2 to 0.2.0
57
index.js
@@ -43,3 +43,3 @@ var fs = require('fs'); | ||
linkRecursivelySync(self.getCacheDir(), destDir); | ||
helpers.copyRecursivelySync(self.getCacheDir(), destDir); | ||
}) | ||
@@ -58,56 +58,1 @@ }; | ||
module.exports = CachingWriter; | ||
/********************************************************************** | ||
* Implementation from broccoli-kitchen-sink-helpers v0.1.1. | ||
* | ||
* Note this code was removed due to issues on OSX where hardlinks | ||
* could cause data loss. This is only used here to link from the cached copy | ||
* (which we KNOW was copied and not linked) to the final destination dir. | ||
* | ||
* Do NOT use this if you are not 100% certain that the source is NOT a link itself. | ||
* | ||
* YOU HAVE BEEN WARNED | ||
**********************************************************************/ | ||
// If src is a file, dest is a file name. If src is a directory, dest is the | ||
// directory that the contents of src will be copied into. | ||
// | ||
// This will overwrite dest if necessary. (This does not work when src is a | ||
// file and dest is a directory.) | ||
// | ||
// This does not resolve symlinks. It is not clear whether it should. | ||
// | ||
// Note that unlike cp(1), we do not special-case if dest is an existing | ||
// directory, because relying on things to exist when we're in the middle of | ||
// assembling a new tree is too brittle. | ||
function linkRecursivelySync (src, dest, _mkdirp) { | ||
if (_mkdirp == null) _mkdirp = true | ||
// Note: We could try readdir'ing and catching ENOTDIR exceptions, but that | ||
// is 3x slower than stat'ing in the common case that we have a file. | ||
var srcStats = fs.lstatSync(src) | ||
if (srcStats.isDirectory()) { | ||
mkdirp.sync(dest) | ||
var entries = fs.readdirSync(src) | ||
for (var i = 0; i < entries.length; i++) { | ||
// Set _mkdirp to false when recursing to avoid extra mkdirp calls. | ||
linkRecursivelySync(src + '/' + entries[i], dest + '/' + entries[i], false) | ||
} | ||
} else { | ||
if (_mkdirp) { | ||
mkdirp.sync(path.dirname(dest)) | ||
} | ||
linkAndOverwrite(src, dest) | ||
} | ||
} | ||
function linkAndOverwrite (srcFile, destFile) { | ||
try { | ||
fs.linkSync(srcFile, destFile) | ||
} catch (err) { | ||
if (err.code !== 'EEXIST') throw err | ||
fs.unlinkSync(destFile) | ||
fs.linkSync(srcFile, destFile) | ||
} | ||
} | ||
// END |
{ | ||
"name": "broccoli-caching-writer", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"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", |
@@ -111,3 +111,3 @@ 'use strict'; | ||
builder = new broccoli.Builder(tree); | ||
return builder.build().finally(function(dir) { | ||
return builder.build().then(function(dir) { | ||
expect(fs.readFileSync(dir + '/something-cool.js', {encoding: 'utf8'})).to.eql('zomg blammo'); | ||
@@ -114,0 +114,0 @@ }); |
7652
151