Skip to content

Commit

Permalink
Replace fileset with plain glob 7
Browse files Browse the repository at this point in the history
fileset is deprecated gotwarlost/istanbul#638
and glob 7 supports everything we need
  • Loading branch information
johanneswuerbach committed Jun 18, 2016
1 parent bd03b4a commit 1b56c81
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var fs = require('fs');
var yaml = require('js-yaml');
var log = require('npmlog');
var path = require('path');
var fileset = require('fileset');
var glob = require('glob');
var url = require('url');
var querystring = require('querystring');
var Bluebird = require('bluebird');
Expand All @@ -28,7 +28,7 @@ var isa = require('./isa');
var fileExists = require('./fileutils').fileExists;

var knownBrowsers = require('./utils/known-browsers');
var filesetAsync = Bluebird.promisify(fileset);
var globAsync = Bluebird.promisify(glob);

function Config(appMode, progOptions, config) {
this.appMode = appMode;
Expand Down Expand Up @@ -367,10 +367,23 @@ Config.prototype.getFileSet = function(want, dontWant, callback) {
if (isa(dontWant, String)) {
dontWant = [dontWant]; // dontWant is an Array
}

// Filter glob < 6 negation patterns to still support them
// See https://github.com/isaacs/node-glob/tree/3f883c43#comments-and-negation
var positiveWants = [];
want.forEach(function(patternEntry) {
var pattern = isa(patternEntry, String) ? patternEntry : patternEntry.src;
if (pattern.indexOf('!') === 0) {
return dontWant.push(pattern.substring(1));
}

positiveWants.push(patternEntry);
});

dontWant = dontWant.map(function(p) {
return p ? self.resolvePath(p) : p;
});
Bluebird.reduce(want, function(allThatIWant, patternEntry) {
Bluebird.reduce(positiveWants, function(allThatIWant, patternEntry) {
var pattern = isa(patternEntry, String) ? patternEntry : patternEntry.src;
var attrs = patternEntry.attrs || [];
var patternUrl = url.parse(pattern);
Expand All @@ -381,7 +394,7 @@ Config.prototype.getFileSet = function(want, dontWant, callback) {
return allThatIWant.concat({src: pattern, attrs: attrs});
}

return filesetAsync([self.resolvePath(pattern)], dontWant).then(function(files) {
return globAsync(self.resolvePath(pattern), { ignore: dontWant }).then(function(files) {
return allThatIWant.concat(files.map(function(f) {
f = self.reverseResolvePath(f);
return {src: f, attrs: attrs};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"cross-spawn": "^4.0.0",
"did_it_work": "0.0.6",
"express": "^4.10.7",
"fileset": "^0.2.1",
"fireworm": "^0.7.0",
"glob": "^7.0.4",
"http-proxy": "^1.13.1",
"js-yaml": "^3.2.5",
"lodash": "^4.0.0",
Expand Down
9 changes: 9 additions & 0 deletions tests/config_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ describe('Config', function() {
done();
});
});
it('excludes using src_files', function(done) {
config.set('src_files', ['ci/*', '!**/report*.js']);
config.getSrcFiles(function(err, files) {
expect(files).to.deep.equal([
fileEntry(path.join('ci', 'ci_tests.js'))
]);
done();
});
});
it('can read files from directories with spaces', function(done) {
config.set('cwd', 'tests/space test/');
config.set('src_files', 'test.js');
Expand Down

0 comments on commit 1b56c81

Please sign in to comment.