Socket
Socket
Sign inDemoInstall

broccoli-persistent-filter

Package Overview
Dependencies
57
Maintainers
3
Versions
59
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.8 to 1.2.0

5

CHANGELOG.md
# master
# 1.2.0
* [#50](https://github.com/stefanpenner/broccoli-persistent-filter/pull/50) Add ability to return an object (must be `JSON.stringify`able) from `processString`.
* [#50](https://github.com/stefanpenner/broccoli-persistent-filter/pull/50) Add `postProcess` hook that is called after `processString` (both when cached and not cached).
# 1.0.0
* Forked from broccoli-filter

4

index.js

@@ -247,1 +247,5 @@ 'use strict';

};
Filter.prototype.postProcess = function(result /*, relativePath */) {
return result;
};
'use strict';
var Promise = require('rsvp').Promise;
module.exports = {

@@ -7,4 +9,25 @@ init: function() {},

processString: function(ctx, contents, relativePath) {
return ctx.processString(contents, relativePath);
var string = new Promise(function(resolve) {
resolve(ctx.processString(contents, relativePath));
});
return string.then(function(value) {
var normalizedValue = value;
if (typeof value === 'string') {
normalizedValue = { output: value };
}
return new Promise(function(resolve) {
resolve(ctx.postProcess(normalizedValue, relativePath));
})
.then(function(result) {
if (result === undefined) {
throw new Error('You must return an object from `Filter.prototype.postProcess`.');
}
return result.output;
});
});
}
};

@@ -28,2 +28,3 @@ 'use strict';

var cache = this._cache;
var string;

@@ -33,15 +34,44 @@ return cache.get(key).then(function(entry) {

ctx._debug('persistent cache hit: %s', relativePath);
return entry.value;
string = Promise.resolve(entry.value)
.then(function(value) {
return JSON.parse(value);
});
} else {
ctx._debug('persistent cache prime: %s', relativePath);
var string = Promise.resolve(ctx.processString(contents, relativePath));
string = new Promise(function(resolve) {
resolve(ctx.processString(contents, relativePath));
})
.then(function(result) {
if (typeof result === 'string') {
return { output: result };
} else {
return result;
}
})
.then(function(value) {
var stringValue = JSON.stringify(value);
return string.then(function(string) {
return cache.set(key, string).then(function() {
return string;
return cache.set(key, stringValue).then(function() {
return value;
});
});
}
return string
.then(function(object) {
return new Promise(function(resolve) {
resolve(ctx.postProcess(object, relativePath));
})
.then(function(result) {
if (result === undefined) {
throw new Error('You must return an object from `Filter.prototype.postProcess`.');
}
return result.output;
});
});
}
});
}
};

12

package.json
{
"name": "broccoli-persistent-filter",
"version": "1.1.8",
"version": "1.2.0",
"description": "broccoli filter but with a persistent cache",

@@ -33,7 +33,7 @@ "author": "Stefan Penner <stefan.penner@gmail.com>",

"blank-object": "^1.0.1",
"broccoli-kitchen-sink-helpers": "^0.2.7",
"broccoli-kitchen-sink-helpers": "^0.3.1",
"broccoli-plugin": "^1.0.0",
"copy-dereference": "^1.0.0",
"debug": "^2.2.0",
"fs-tree-diff": "^0.3.0",
"fs-tree-diff": "^0.4.4",
"hash-for-dep": "^1.0.2",

@@ -49,8 +49,8 @@ "md5-hex": "^1.0.2",

"broccoli": "^0.16.3",
"broccoli-test-helpers": "^0.0.8",
"broccoli-test-helpers": "^0.0.9",
"chai": "^3.0.0",
"chai-as-promised": "^5.1.0",
"coveralls": "^2.11.4",
"istanbul": "^0.3.17",
"minimatch": "^2.0.8",
"istanbul": "^0.4.2",
"minimatch": "^3.0.0",
"mocha": "^2.2.5",

@@ -57,0 +57,0 @@ "rimraf": "^2.4.2",

@@ -25,5 +25,11 @@ # broccoli-persistent-filter

*
* The return value is written as the contents of the output file
* The resolved return value can either be an object or a string.
*
* An object can be used to cache additional meta-data that is not part of the
* final output. When an object is returned, the `.output` property of that
* object is used as the resulting file contents.
*
* When a string is returned it is used as the file contents.
*/
abstract processString(contents: string, relativePath: string): string;
abstract processString(contents: string, relativePath: string): {string | object };

@@ -43,2 +49,19 @@ /**

virtual getDestFilePath(relativePath: string): string;
/**
* Method `postProcess`: may be implemented on subclasses of
* Filter.
*
* This method can be used in subclasses to do processing on the results of
* each files `processString` method.
*
* A common scenario for this is linting plugins, where on initial build users
* expect to get console warnings for lint errors, but we do not want to re-lint
* each file on every boot (since most of them will be able to be served from the
* cache).
*
* The `.output` property of the return value is used as the emitted file contents.
*/
postProcess(results: object, relativePath: string): object
}

@@ -45,0 +68,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc