gulp main-bower-files regular expression filter not working
bower, gulp, javascript, node.js, regex
Solution
You don't need to create a `RegExp` to filter for files with main-bower-files.
Indeed, you can simply pass an array or a string of glob to check only for `.js` files:
gulp.task('default', function () {
var bowerFiles = mainBowerFiles('**/*.js');
console.log('bower files: ', bowerFiles);
});
If you really want to use the regex, you have to use the `filter` option, you can't directly pass it as an argument:
gulp.task('default', function () {
var bowerFiles = mainBowerFiles({ filter: new RegExp('.*js$', 'i') });
console.log('bower files: ', bowerFiles);
});
Problem
Why is the second array, `bowerFiles`, not filtered to just javascript files. ``` var gulp = require('gulp'); var mainBowerFiles = require('main-bower-files'); gulp.task('default', function () { var unfiltered = mainBowerFiles(); console.log('unfiltered files:', unfiltered); // 11 FILES //var jsRegEx = /js$/i; // tried this way too... var jsRegEx = new RegExp('js$', 'i'); var bowerFiles = mainBowerFiles(jsRegEx); console.log('bower files:', bowerFiles); // 11 FILES }); ``` I have tried to mimic what bower-main-files is doing here, and it works.