Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

broccoli-persistent-filter

Package Overview
Dependencies
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-persistent-filter - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

README.md

5

CHANGELOG.md
# master
# 1.2.7
* switch to heimdalljs-logger, allowing logs to show context within the broccoli
graph
# 1.2.6

@@ -4,0 +9,0 @@

155

index.js

@@ -11,3 +11,3 @@ 'use strict';

var symlinkOrCopySync = require('symlink-or-copy').sync;
var debugGenerator = require('debug');
var debugGenerator = require('heimdalljs-logger');
var md5Hex = require('md5-hex');

@@ -19,4 +19,25 @@ var Processor = require('./lib/processor');

var FSTree = require('fs-tree-diff');
var IS_VERBOSE = !!process.env.DEBUG_VERBOSE;
var heimdall = require('heimdalljs');
function ApplyPatchesSchema() {
this.mkdir = 0;
this.rmdir = 0;
this.unlink = 0;
this.change = 0;
this.create = 0;
this.other = 0;
this.processed = 0;
this.linked = 0;
this.processString = 0;
this.persistentCacheHit = 0;
this.persistentCachePrime = 0;
}
function DerivePatchesSchema() {
this.patches = 0;
this.entries = 0;
}
module.exports = Filter;

@@ -39,3 +60,3 @@

this._debug = debugGenerator(name);
this._logger = debugGenerator(name);

@@ -49,4 +70,2 @@ Plugin.call(this, [inputTree]);

this.resetCounters();
/* Destructuring assignment in node 0.12.2 would be really handy for this! */

@@ -70,14 +89,8 @@ if (options) {

Filter.prototype.build = function() {
var start = Date.now();
var srcDir = this.inputPaths[0];
var destDir = this.outputPath;
var entries = walkSync.entries(srcDir);
this._debug('buildng: %s, %o', '' + this, {
inputPath: srcDir,
outputPath: destDir,
entries: entries.length
});
var instrumentation = heimdall.start('derivePatches', DerivePatchesSchema);
var entries = walkSync.entries(srcDir);
var nextTree = new FSTree.fromEntries(entries);

@@ -87,75 +100,50 @@ var currentTree = this.currentTree;

this.currentTree = nextTree;
var patches = currentTree.calculatePatch(nextTree);
this._counters.patches = patches.length;
return mapSeries(patches, function(patch) {
var operation = patch[0];
var relativePath = patch[1];
var entry = patch[2];
var outputPath = destDir + '/' + (this.getDestFilePath(relativePath) || relativePath);
var outputFilePath = outputPath;
instrumentation.stats.patches = patches.length;
instrumentation.stats.entries = entries.length;
this._verboseDebug('[operation:%s] %s', operation, relativePath);
instrumentation.stop();
switch (operation) {
case 'mkdir': {
this._counters.operations.mkdir++;
return fs.mkdirSync(outputPath);
} case 'rmdir': {
this._counters.operations.rmdir++;
return fs.rmdirSync(outputPath);
} case 'unlink': {
this._counters.operations.unlink++;
return fs.unlinkSync(outputPath);
} case 'change': {
this._counters.operations.change++;
return this._handleFile(relativePath, srcDir, destDir, entry, outputFilePath, true);
} case 'create': {
this._counters.operations.create++;
return this._handleFile(relativePath, srcDir, destDir, entry, outputFilePath, false);
} default: {
this._counters.operations.other++;
}
}
}, this).then(function() {
this._debug('build complete: %s, in: %dms', '' + this, Date.now() - start);
this.debugLogCounters();
this.resetCounters();
}.bind(this));
};
return heimdall.node('applyPatches', ApplyPatchesSchema, function(instrumentation) {
return mapSeries(patches, function(patch) {
var operation = patch[0];
var relativePath = patch[1];
var entry = patch[2];
var outputPath = destDir + '/' + (this.getDestFilePath(relativePath) || relativePath);
var outputFilePath = outputPath;
Filter.prototype.debugLogCounters = function() {
this._debug(' - %o', this._counters);
};
this._logger.debug('[operation:%s] %s', operation, relativePath);
Filter.prototype._verboseDebug = function() {
if (IS_VERBOSE) {
this._debug.apply(this, arguments);
}
switch (operation) {
case 'mkdir': {
instrumentation.mkdir++;
return fs.mkdirSync(outputPath);
} case 'rmdir': {
instrumentation.rmdir++;
return fs.rmdirSync(outputPath);
} case 'unlink': {
instrumentation.unlink++;
return fs.unlinkSync(outputPath);
} case 'change': {
instrumentation.change++;
return this._handleFile(relativePath, srcDir, destDir, entry, outputFilePath, true, instrumentation);
} case 'create': {
instrumentation.create++;
return this._handleFile(relativePath, srcDir, destDir, entry, outputFilePath, false, instrumentation);
} default: {
instrumentation.other++;
}
}
}, this);
}, this);
};
Filter.prototype.resetCounters = function() {
this._counters = {
hit: 0,
prime: 0,
patches: 0,
operations: {
mkdir: 0,
rmdir: 0,
unlink: 0,
change: 0,
create: 0,
other: 0
},
linked: 0,
processed: 0
};
};
Filter.prototype._handleFile = function(relativePath, srcDir, destDir, entry, outputPath, isChange) {
Filter.prototype._handleFile = function(relativePath, srcDir, destDir, entry, outputPath, isChange, instrumentation) {
if (this.canProcessFile(relativePath)) {
this._counters.processed++;
return this.processAndCacheFile(srcDir, destDir, entry, isChange);
instrumentation.processed++;
return this.processAndCacheFile(srcDir, destDir, entry, isChange, instrumentation);
} else {
this._counters.linked++;
instrumentation.linked++;
if (isChange) {

@@ -227,3 +215,3 @@ fs.unlinkSync(outputPath);

Filter.prototype.processAndCacheFile = function(srcDir, destDir, entry, isChange) {
Filter.prototype.processAndCacheFile = function(srcDir, destDir, entry, isChange, instrumentation) {
var filter = this;

@@ -234,3 +222,3 @@ var relativePath = entry.relativePath;

then(function asyncProcessFile() {
return filter.processFile(srcDir, destDir, relativePath, isChange);
return filter.processFile(srcDir, destDir, relativePath, isChange, instrumentation);
}).

@@ -255,3 +243,3 @@ then(undefined,

Filter.prototype.processFile = function(srcDir, destDir, relativePath, isChange) {
Filter.prototype.processFile = function(srcDir, destDir, relativePath, isChange, instrumentation) {
var filter = this;

@@ -268,6 +256,6 @@ var inputEncoding = this.inputEncoding;

var string = invoke(this.processor, this.processor.processString, [this, contents, relativePath]);
instrumentation.processString++;
var string = invoke(this.processor, this.processor.processString, [this, contents, relativePath, instrumentation]);
return string.then(function asyncOutputFilteredFile(outputString) {
var outputPath = filter.getDestFilePath(relativePath);

@@ -286,6 +274,7 @@

if (isSame) {
this._verboseDebug('[change:%s] but was the same, skipping', relativePath, isSame);
this._logger.debug('[change:%s] but was the same, skipping', relativePath, isSame);
return;
} else {
this._verboseDebug('[change:%s] but was NOT the same, writing new file', relativePath);
this._logger.debug('[change:%s] but was NOT the same, writing new file', relativePath);
}

@@ -292,0 +281,0 @@ }

@@ -19,4 +19,4 @@ 'use strict';

Processor.prototype.processString = function(ctx, contents, relativePath) {
return this.processor.processString(ctx, contents, relativePath);
Processor.prototype.processString = function(ctx, contents, relativePath, instrumentation) {
return this.processor.processString(ctx, contents, relativePath, instrumentation);
};

@@ -25,3 +25,3 @@ 'use strict';

processString: function(ctx, contents, relativePath) {
processString: function(ctx, contents, relativePath, instrumentation) {
var key = ctx.cacheKeyProcessString(contents, relativePath);

@@ -33,4 +33,3 @@ var cache = this._cache;

if (entry.isCached) {
ctx._counters.hit++;
ctx._verboseDebug('persistent cache hit: %s', relativePath);
instrumentation.persistentCacheHit++;

@@ -41,4 +40,4 @@ string = Promise.resolve(entry.value).then(function(value) {

} else {
ctx._counters.prime++;
ctx._verboseDebug('persistent cache prime: %s', relativePath);
instrumentation.persistentCachePrime++;
string = new Promise(function(resolve) {

@@ -45,0 +44,0 @@ resolve(ctx.processString(contents, relativePath));

{
"name": "broccoli-persistent-filter",
"version": "1.2.6",
"version": "1.2.7",
"description": "broccoli filter but with a persistent cache",

@@ -37,2 +37,4 @@ "author": "Stefan Penner <stefan.penner@gmail.com>",

"hash-for-dep": "^1.0.2",
"heimdalljs": "^0.1.0",
"heimdalljs-logger": "^0.1.6",
"md5-hex": "^1.0.2",

@@ -53,5 +55,5 @@ "mkdirp": "^0.5.1",

"minimatch": "^3.0.2",
"mocha": "^2.2.5",
"mocha": "^3.0.0",
"mocha-jshint": "^2.3.1",
"rimraf": "^2.4.2",
"rimraf": "^2.5.4",
"sinon": "^1.15.3",

@@ -58,0 +60,0 @@ "sinon-chai": "^2.8.0"

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc