Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

broccoli-caching-writer

ember-cli705kMIT3.0.3

Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.

broccoli-plugin, javascript

readme

Broccoli Caching Writer

Build Status Build status

Drop-in-replacement for broccoli-writer adding a thin caching layer based on the computed hash of the input directory trees. If any file in an input node has changed, the build method will be called, otherwise (if input is the same) the results of the last build call will be used instead.

Example

var Plugin = require('broccoli-caching-writer');

MyPlugin.prototype = Object.create(Plugin.prototype);
MyPlugin.prototype.constructor = MyPlugin;
function MyPlugin(inputNodes, options) {
  options = options || {};
  // options.inputFiles === array of globs, to consider for the cache key
  Plugin.call(this, inputNodes, {
    annotation: options.annotation
  });
}

MyPlugin.prototype.build = function() {
  // cache has been busted
  // do anything, for example:
  //   1. read from this.inputPaths
  //   2. do something based on the result
  //   3. and then, write to this.outputPath
};

Documentation

new CachingWriter(inputNodes, options)

Call this base class constructor from your subclass constructor.

  • inputNodes: An array of input nodes.

  • options:

    • name, annotation, persistentOutput: Same as broccoli-plugin; see there.

    • cacheInclude (default: []): An array of regular expressions that files and directories in an input node must pass (match at least one pattern) in order to be included in the cache hash for rebuilds. In other words, a whitelist of patterns that identify which files and/or directories can trigger a rebuild.

    • cacheExclude (default: []): An array of regular expressions that files and directories in an input node cannot pass in order to be included in the cache hash for rebuilds. In other words, a blacklist of patterns that identify which files and/or directories will never trigger a rebuild.

      Note, in the case when a file or directory matches both an include and exlude pattern, the exclude pattern wins

plugin.listFiles

list files matched, helpful as it allows us avoid a second glob, lexicographically sorted by relativePath.

plugin.listEntries

list entries (stat objects) of files matched, helpful when further FS information is required on rebuild, lexicographically sorted by relativePath.

ZOMG!!! TESTS?!?!!?

I know, right?

Running the tests:

npm install
npm test

License

This project is distributed under the MIT license.

changelog

master

3.0.0

  • listFiles and listEntries output is now lexicographically sorted (by related path)

2.3.1

  • [REVERT] listFiles and listEntries output is now lexicographically sorted (by related path) ember-cli uses concat inputFiles instead of headerFiles for files which much be ordered

2.3.0

  • listFiles and listEntries output is now lexicographically sorted (by related path)

2.2.0

  • add plugin.listEntries() – this returns a stat entry result, allowing subclasses access to the underlying stat information

2.1.0

  • Performance improvements

2.0.3

  • Fix bug

2.0.2

  • Performance improvements

2.0.1

  • Performance improvements

2.0.0

  • Derive from broccoli-plugin base class, and expose same interface. In particular:

    • updateCache(srcDirs, destDir) becomes build()
    • We no longer derive from CoreObject
    • We gain the name, annotation, and persistentOutput options
    • options no longer auto-assigns to this; unknown options are ignored
  • filterFromCache.include/filterFromCache.exclude are now called cacheInclude/cacheExclude; they must now be passed in through options, and can no longer be set on the prototype/instance

  • Remove enforceSingleInputTree option; we now always expect an array

1.0.0

  • Bump without changes

0.6.2

  • Improve logging

0.6.1

  • Ignore changes in directory size/mtime, so that excluded files can be added or removed without causing invalidations

0.6.0

0.5.5

  • Add ability to debug which files are causing an invalidation of the cache. The following will generate output indicating which path changed:
DEBUG=broccoli-caching-writer broccoli serve # if using broccoli-cli

0.5.4

  • Update to newer core-object version.

0.5.3

  • Ensure that errors are not thrown if _destDir has not been setup yet.

0.5.2

  • Use _destDir for tracking the internal destination directory. This prevents collisions if inheritors use the common destDir name as a property.

0.5.1

  • Allow easy inheritance. In your package's index.js:
var CachingWriter = require('broccoli-caching-writer');

module.exports = CachingWriter.extend({
  init: function(inputTrees, options) {
    /* do additional setup here */
  },

  updateCache: function(srcPaths, destDir) {
    /* do main processing */
  }
});

Then in a consuming Brocfile:

var MyFoo = require('my-foo'); // package from above

var tree = new MyFoo([someInput], { some: 'options' });

0.5.0

  • Allow filtering on files to include/exclude when determining when to invalidate the cache. This allows you to use simple regular expressions to prevent invalidating the cache when files that do not affect the tree in question are changed.
var outputTree = compileCompass(inputTree, {
  filterFromCache: {
    include: [
      /.(scss|sass)$/   // only base the input tree’s hash on *.scss and *.sass files
    ]
  }
});

This does not affect what files make it to the output tree at all, rather it only makes it easier for subclasses to only rebuild when file types they care about change.

  • Symlink from cache instead of manually hard-linking. This should be a speed improvement for posix platforms, and will soon be able to take advantage of improvements for Windows (for those curious stay tuned on Windows support here).

  • Allow multiple input trees. If an array of trees is passed to the constructor, all trees will be read and their collective output will be used to calculate the cache (any trees invalidating causes updateCache to be called).

    The default now is to assume that an array of trees is allowed, if you want to opt-out of this behavior set enforceSingleInputTree to true on your classes prototype.

    By default an array of paths will now be the first argument to updateCache (instead of a single path in prior versions). The enforceSingleInputTree property also controls this.

  • Due to the changes above (much more being done in our constructor), inheritors are now required to call the broccoli-caching-writer constructor from their own.