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

broccoli-caching-writer

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-caching-writer - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

61

index.js

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

var invalidateCache = false;
var key, dir;
var dir;
var lastKeys = [];

@@ -90,29 +90,38 @@

var fullPath = dir + '/' + relativePath;
var stats = fs.statSync(fullPath);
/*jshint validthis:true */
this._stats.stats++;
return new Key('file', fullPath, relativePath, fs.statSync(fullPath), undefined, this.debug);
return new Key({
relativePath: relativePath,
basePath: dir,
mode: stats.mode,
size: stats.size,
mtime: stats.mtime.getTime(),
isDirectory: function() {
return false;
}
}, undefined, this.debug);
}
for (var i = 0, l = writer.inputPaths.length; i < l; i++) {
dir = writer.inputPaths[i];
var inputFiles;
var files;
if (canUseInputFiles(this._inputFiles)) {
this.debug('using inputFiles directly');
inputFiles = this._inputFiles;
files = this._inputFiles.filter(shouldNotBeIgnored, this).map(keyForFile, this);
} else {
this.debug('walking %o', this.inputFiles);
inputFiles = walkSync(dir, this.inputFiles);
files = walkSync.entries(dir, this.inputFiles).filter(entriesShouldNotBeIgnored, this).map(keyForEntry, this);
}
var files = inputFiles.filter(shouldNotBeIgnored, this).map(keyForFile, this);
this._stats.files += files.length;
key = new Key('directory', dir, '/', fs.statSync(dir), files, this.debug);
var lastKey = writer._lastKeys[i];
var key = keyForDir(dir, files, this.debug);
var lastKey = writer._lastKeys[i];
lastKeys.push(key);
if (!invalidateCache /* short circuit */ && !key.equal(lastKey)) {
if (!invalidateCache /* short circuit */ && !key.isEqual(lastKey)) {
invalidateCache = true;

@@ -194,5 +203,3 @@ }

var key = keys[i];
if (key.type === 'file') {
files.push(key.fullPath);
} else {
if (key.isDirectory()) {
var children = key.children;

@@ -202,2 +209,4 @@ if(children && children.length > 0) {

}
} else {
files.push(key.fullPath);
}

@@ -211,1 +220,25 @@ }

module.exports = CachingWriter;
function keyForDir(dir, children, debug) {
// no need to stat dir, we don't care about anything other then that they are
// a dir
return new Key({
relativePath: '/',
basePath: dir,
mode: 16877,
size: 0,
mtime: 0,
isDirectory: function() { return true; }
}, children, debug);
}
function entriesShouldNotBeIgnored(entry) {
/*jshint validthis:true */
return !this.shouldBeIgnored(entry.relativePath);
}
function keyForEntry(entry) {
/*jshint validthis:true */
return new Key(entry, undefined, this.debug);
}
var EMPTY_ARRAY = [];
function Key(type, fullPath, path, stat, children, debug) {
this.type = type;
this.fullPath = fullPath;
this.path = path;
this.stat = stat;
function Key(entry, children, debug) {
this.entry = entry;
this.children = children || EMPTY_ARRAY;

@@ -13,8 +10,8 @@ this.debug = debug;

Key.prototype.toString = function() {
return ' type: ' + this.type +
' fullPath: ' + this.fullPath +
' path: ' + this.path +
' stat.mode: ' + this.stat.mode +
' stat.size: ' + this.stat.size +
' stat.mtime: ' + this.stat.mtime.getTime();
return ' type: ' + (this.isDirectory() ? 'directory' : 'file') +
' fullPath: ' + this.entry.fullPath +
' path: ' + this.entry.relativePath+
' mode: ' + this.netry.mode +
' size: ' + this.netry.size +
' mtime: ' + this.netry.mtime;
};

@@ -30,15 +27,35 @@

Object.defineProperty(Key.prototype, 'fullPath', {
get: function() {
return this.entry.fullPath;
}
});
Key.prototype.inspect = function() {
return [
this.type,
this.fullPath,
this.path,
this.stat.mode,
this.stat.size,
this.stat.size,
this.stat.mtime.getTime()
this.entry.isDirectory() ? 'directory' : 'file',
this.entry.fullPath,
this.entry.relativePath,
this.entry.mode,
this.entry.size,
this.entry.mtime
].join(', ');
};
Key.prototype.equal = function(otherKey) {
Key.prototype.isDirectory = function() {
return this.entry.isDirectory();
};
function isEntryEqual(a, b) {
if (a.isDirectory() && b.isDirectory()) {
return a.fullPath === b.fullPath;
} else {
return a.fullPath === b.fullPath &&
a.mode === b.mode &&
a.size === b.size &&
a.mtime === b.mtime;
}
}
Key.prototype.isEqual = function(otherKey) {
if (otherKey === undefined) {

@@ -49,3 +66,3 @@ logNotEqual(this, otherKey);

if (this.type === otherKey.type && this.type === 'directory') {
if (this.entry.isDirectory() && otherKey.entry.isDirectory()) {
var children = this.children;

@@ -56,3 +73,3 @@ var otherChildren = otherKey.children;

for (var i = 0; i < children.length; i++) {
if (children[i].equal(otherChildren[i])) {
if (children[i].isEqual(otherChildren[i])) {
// they are the same

@@ -69,8 +86,3 @@ } else {

// key represents a file, diff the file
if (this.type === otherKey.type &&
this.path === otherKey.path &&
this.stat.mode === otherKey.stat.mode &&
(this.type === 'directory' ? true : (this.stat.size === otherKey.stat.size &&
this.stat.mtime.getTime() === otherKey.stat.mtime.getTime()))) {
if (isEntryEqual(this.entry, otherKey.entry)) {
return true;

@@ -77,0 +89,0 @@ } else {

{
"name": "broccoli-caching-writer",
"version": "2.0.1",
"version": "2.0.2",
"description": "Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.",

@@ -28,3 +28,3 @@ "main": "index.js",

"symlink-or-copy": "^1.0.0",
"walk-sync": "^0.2.0"
"walk-sync": "^0.2.5"
},

@@ -31,0 +31,0 @@ "devDependencies": {

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