-
Notifications
You must be signed in to change notification settings - Fork 20
Description
I'd like to turn FSTree into an abstraction that can represent directory trees including their file contents.
Let me start with my current use case:
I'm working on generalizing the broccoli-filter baseclass to allow for outputting multiple files per input file. Let us call it BetterFilter. Here's what I'm planning to do -- bear with me, FSTree will come in in a bit. Say we have an input node IN
containing
IN/
foo.hbs
bar.hbs
and we want to write a plugin that outputs
OUT/
foo.js
foo.js.map
bar.js
bar.js.map
To facilitate this, the BetterFilter baseclass will for each input file create a directory in its cache, like CACHE/foo.js-output/
, into which the plugin can write all of its files, like so:
CACHE/
foo.js-output/
foo.js
foo.js.map
bar.js-output/
bar.js
bar.js.map
On each rebuild, BetterFilter checks the mtimes of each input file and rebuilds those that have changed. Then, it merges all the CACHE/*-output
directories into its OUT
(outputPath
) directory.
I'd like to use FSTree to address two problems the following problem:
-
Merging every time will likely be a bottleneck. So I'd like to do the merging in-memory and enlist FSTree's help to update only the files that have changed. At the moment,
FSTree.applyPatch
assumes that all files come from the sameinput
directory, so this isn't yet possible.To address this, we could imagine adding something like an
entries.contentPath
property to tell FSTree where the file comes from (i.e. where the symlink should point). -
Some plugins might not need to write the file to disk. For example, we could re-implement the current Filter by subclassing BetterFilter. But then we would end up writing the result ofprocessString
into the cache directory and symlink it, rather than writing it directly into the output directory. So it would be great if BetterFilter allowed plugins, as an alternative to writing files intoCACHE/foo.js-output/
, to return an FSTree instance that stores all the file contents in memory.To address this, we could imagine adding something like anentries.contentBuffer
property to tell FSTree to write out the buffer directly rather than symlinking some file.
Before I take a stab at implementing something along these lines, I just wanted to check if you're conceptually on board with this. Then I'll send PRs (for fs-tree-diff and for node-walk-sync) and we can discuss details.
One particular question: I suspect that for a clean implementation, rather than being able to specify a different input path every time we call applyPatch
, we may have to require that the input
directory be fixed when we create the FSTree, so that we can store paths in entry.contentPath
. My guess is that this will be OK, since in Broccoli >=1.0, input paths are stable, but I wanted to double-check if that's actually the case.