broccoli-caching-writer
Advanced tools
Comparing version 2.2.1 to 2.3.0
## master | ||
## 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 underyling stat information | ||
subclasses access to the underlying stat information | ||
@@ -8,0 +12,0 @@ ## 2.1.0 |
18
index.js
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var RSVP = require('rsvp'); | ||
var rimraf = RSVP.denodeify(require('rimraf')); | ||
var helpers = require('broccoli-kitchen-sink-helpers'); | ||
var symlinkOrCopy = require('symlink-or-copy'); | ||
var assign = require('lodash.assign'); | ||
var Plugin = require('broccoli-plugin'); | ||
@@ -221,3 +218,16 @@ var debugGenerator = require('debug'); | ||
} | ||
return listEntries(this._lastKeys, []); | ||
return listEntries(this._lastKeys, []).sort(function (a, b) { | ||
var pathA = a.relativePath; | ||
var pathB = b.relativePath; | ||
if (pathA === pathB) { | ||
return 0; | ||
} else if (pathA < pathB) { | ||
return -1; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
); | ||
}; | ||
@@ -224,0 +234,0 @@ |
{ | ||
"name": "broccoli-caching-writer", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.", | ||
@@ -24,12 +24,11 @@ "main": "index.js", | ||
"debug": "^2.1.1", | ||
"lodash.assign": "^3.2.0", | ||
"rimraf": "^2.2.8", | ||
"rsvp": "^3.0.17", | ||
"symlink-or-copy": "^1.0.0", | ||
"walk-sync": "^0.2.5" | ||
}, | ||
"devDependencies": { | ||
"broccoli": "^0.13.0", | ||
"broccoli": "^0.16.9", | ||
"chai": "^3.2.0", | ||
"chai-as-promised": "^5.1.0", | ||
"chai-files": "^1.2.0", | ||
"mocha": "^2.2.5", | ||
@@ -36,0 +35,0 @@ "mocha-jshint": "~2.2.3" |
@@ -59,6 +59,6 @@ # Broccoli Caching Writer | ||
## `plugin.listFiles` | ||
list files matched, helpful as it allows us avoid a second glob | ||
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. | ||
list entries (stat objects) of files matched, helpful when further FS information is required on rebuild, lexicographically sorted by relativePath. | ||
@@ -65,0 +65,0 @@ ## ZOMG!!! TESTS?!?!!? |
@@ -7,3 +7,5 @@ 'use strict'; | ||
var chaiAsPromised = require('chai-as-promised'); | ||
var chaiFiles = require('chai-files'), file = chaiFiles.file; | ||
chai.use(chaiAsPromised); | ||
chai.use(chaiFiles); | ||
var broccoli = require('broccoli'); | ||
@@ -153,8 +155,4 @@ var CachingWriter = require('..'); | ||
setupCachingWriter([sourcePath, secondaryPath], {}, function() { | ||
expect(fs.readFileSync(this.inputPaths[0] + '/core.js', { | ||
encoding: 'utf8' | ||
})).to.contain('"YIPPIE"'); | ||
expect(fs.readFileSync(this.inputPaths[1] + '/bar.js', { | ||
encoding: 'utf8' | ||
})).to.contain('"BLAMMO!"'); | ||
expect(file(this.inputPaths[0] + '/core.js')).to.contain('"YIPPIE"'); | ||
expect(file(this.inputPaths[1] + '/bar.js')).to.contain('"BLAMMO!"'); | ||
}); | ||
@@ -172,5 +170,3 @@ | ||
.then(function(outputPath) { | ||
expect(fs.readFileSync(outputPath + '/something-cool.js', { | ||
encoding: 'utf8' | ||
})).to.equal('zomg blammo'); | ||
expect(file(outputPath + '/something-cool.js')).to.equal('zomg blammo'); | ||
}); | ||
@@ -291,12 +287,17 @@ }); | ||
describe('listEntries', function() { | ||
var listFiles; | ||
describe('listFiles', function() { | ||
function getListFilesFor(options, sourcePaths) { | ||
var listFiles; | ||
function getListFilesFor(options) { | ||
setupCachingWriter([sourcePath], options, function() { | ||
if (arguments.length < 2) { | ||
sourcePaths = [sourcePath]; | ||
} | ||
setupCachingWriter(sourcePaths, options, function() { | ||
var writer = this; | ||
listFiles = this.listFiles().map(function(p) { | ||
return path.relative(writer.inputPaths[0], p); | ||
listFiles = this.listFiles().map(function(fullPath) { | ||
return path.basename(fullPath); | ||
}); | ||
}); | ||
return expectRebuild().then(function() { | ||
@@ -329,12 +330,28 @@ return listFiles; | ||
}); | ||
it('returns a sorted array', function() { | ||
return expect(getListFilesFor( | ||
{}, [sourcePath, secondaryPath] | ||
)).to.eventually.deep.equal([ | ||
'bar.js', | ||
'core.js', | ||
'foo-baz.js', | ||
'foo.js', | ||
'main.js', | ||
]); | ||
}); | ||
}); | ||
describe('listEntries', function() { | ||
var listEntries; | ||
function getListEntriesFor(options, sourcePaths) { | ||
var listEntries; | ||
function getListFilesFor(options) { | ||
setupCachingWriter([sourcePath], options, function() { | ||
if (arguments.length < 2) { | ||
sourcePaths = [sourcePath]; | ||
} | ||
setupCachingWriter(sourcePaths, options, function() { | ||
var writer = this; | ||
listEntries = this.listEntries().map(function(p) { | ||
return path.relative(writer.inputPaths[0], p.fullPath); | ||
listEntries = this.listEntries().map(function(entry) { | ||
return path.basename(entry.fullPath); | ||
}); | ||
@@ -349,7 +366,7 @@ }); | ||
it('returns an array of files keyed', function() { | ||
return expect(getListFilesFor({})).to.eventually.deep.equal(['core.js', 'main.js']); | ||
return expect(getListEntriesFor({})).to.eventually.deep.equal(['core.js', 'main.js']); | ||
}); | ||
it('returns an array of files keyed including only those in the include filter', function() { | ||
return expect(getListFilesFor({ | ||
return expect(getListEntriesFor({ | ||
cacheInclude: [ /core\.js$/ ] | ||
@@ -360,3 +377,3 @@ })).to.eventually.deep.equal(['core.js']); | ||
it('returns an array of files keyed ignoring those in the exclude filter', function() { | ||
return expect(getListFilesFor({ | ||
return expect(getListEntriesFor({ | ||
cacheExclude: [ /main\.js$/ ] | ||
@@ -367,3 +384,3 @@ })).to.eventually.deep.equal(['core.js']); | ||
it('returns an array of files keyed both include & exclude filters', function() { | ||
return expect(getListFilesFor({ | ||
return expect(getListEntriesFor({ | ||
cacheInclude: [ /\.js$/ ], | ||
@@ -373,2 +390,15 @@ cacheExclude: [ /core\.js$/ ] | ||
}); | ||
it('returns a sorted array', function() { | ||
return expect(getListEntriesFor( | ||
{}, [sourcePath, secondaryPath] | ||
)).to.eventually.deep.equal([ | ||
'bar.js', | ||
'core.js', | ||
'foo-baz.js', | ||
'foo.js', | ||
'main.js', | ||
]); | ||
}); | ||
}); | ||
@@ -381,32 +411,32 @@ }); | ||
it('is false for no input', function() { | ||
expect(canUseInputFiles()).to.eql(false); | ||
expect(canUseInputFiles()).to.be.false; | ||
}); | ||
it('is false for non array input', function() { | ||
expect(canUseInputFiles({})).to.eql(false); | ||
expect(canUseInputFiles({length: 1})).to.eql(false); | ||
expect(canUseInputFiles(true)).to.eql(false); | ||
expect(canUseInputFiles(false)).to.eql(false); | ||
expect(canUseInputFiles('')).to.eql(false); | ||
expect(canUseInputFiles('asdf')).to.eql(false); | ||
expect(canUseInputFiles({})).to.be.false; | ||
expect(canUseInputFiles({length: 1})).to.be.false; | ||
expect(canUseInputFiles(true)).to.be.false; | ||
expect(canUseInputFiles(false)).to.be.false; | ||
expect(canUseInputFiles('')).to.be.false; | ||
expect(canUseInputFiles('asdf')).to.be.false; | ||
}); | ||
it('is true for array input', function() { | ||
expect(canUseInputFiles([])).to.eql(true); | ||
expect(canUseInputFiles([1])).to.eql(true); | ||
expect(canUseInputFiles([])).to.be.true; | ||
expect(canUseInputFiles([1])).to.be.true; | ||
}); | ||
it('true for non glob entries', function() { | ||
expect(canUseInputFiles(['foo'])).to.eql(true); | ||
expect(canUseInputFiles(['foo', 'bar'])).to.eql(true); | ||
expect(canUseInputFiles(['foo/bar', 'bar/baz'])).to.eql(true); | ||
expect(canUseInputFiles(['foo/bar.js', 'bar/baz-apple'])).to.eql(true); | ||
expect(canUseInputFiles(['foo'])).to.be.true; | ||
expect(canUseInputFiles(['foo', 'bar'])).to.be.true; | ||
expect(canUseInputFiles(['foo/bar', 'bar/baz'])).to.be.true; | ||
expect(canUseInputFiles(['foo/bar.js', 'bar/baz-apple'])).to.be.true; | ||
}); | ||
it('false for glob entries', function() { | ||
expect(canUseInputFiles(['f*oo'])).to.eql(false); | ||
expect(canUseInputFiles(['foo', 'bar*'])).to.eql(false); | ||
expect(canUseInputFiles(['foo/bar}', 'bar{baz'])).to.eql(false); | ||
expect(canUseInputFiles(['foo{bar.js', 'bar}baz{apple'])).to.eql(false); | ||
expect(canUseInputFiles(['f*oo'])).to.be.false; | ||
expect(canUseInputFiles(['foo', 'bar*'])).to.be.false; | ||
expect(canUseInputFiles(['foo/bar}', 'bar{baz'])).to.be.false; | ||
expect(canUseInputFiles(['foo{bar.js', 'bar}baz{apple'])).to.be.false; | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35126
6
23
694
6
- Removedlodash.assign@^3.2.0
- Removedsymlink-or-copy@^1.0.0
- Removedlodash._baseassign@3.2.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._bindcallback@3.0.1(transitive)
- Removedlodash._createassigner@3.1.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash.assign@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)