question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The first usage example is incorrect and gives the wrong impression about how gulp-filter matches files.

See original GitHub issue

I’m referring to this

var gulp = require('gulp');
var jscs = require('gulp-jscs');
var gulpFilter = require('gulp-filter');

gulp.task('default', function () {
    // create filter instance inside task function
    var filter = gulpFilter(['*', '!src/vendor']);

    return gulp.src('src/*.js')
        // filter a subset of the files
        .pipe(filter)
        // run them through a plugin
        .pipe(jscs())
        .pipe(gulp.dest('dist'));
});

The intent seems to process everything in src but to exclude the files in src/vendor. Problems:

  1. The filter does no work because src/*.js won’t go into subdirectories in the first place. You could remove the filter and you’d still not get anything from src/vendor into dest.
  2. If we amend to src/**/*.js then this pattern will cover every .js file in src, including subdirectories but the filter still gives the wrong impression. It does the work of excluding files in src/vendor not because of !src/vendor but because of *, which matches only files that are not in a subdirectory. You could reduce the filter to gulpFilter('*') and it would still exclude src/vendor and everything in it.
  3. If we amend the filter so that we have ** instead of *, then the filter no longer works because !src/vendor does not match anything. Why? Because gulp-filter matches against the file’s relative path.

Ultimately, the code I see doing what the example seems to be illustrating should be:

var gulp = require('gulp');
var jscs = require('gulp-jscs');
var gulpFilter = require('gulp-filter');

gulp.task('default', function () {
    // create filter instance inside task function
    var filter = gulpFilter(['**', '!vendor/**']);

    return gulp.src('src/**/*.js')
        // filter a subset of the files
        .pipe(filter)
        // run them through a plugin
        .pipe(jscs())
        .pipe(gulp.dest('dist'));
});

The examples based off of this one should also be fixed.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Sep 19, 2016

The “Usage” section on the npm page still shows the example with a single asterisk: https://www.npmjs.com/package/gulp-filter#filter-only

const f = filter(['*', '!src/vendor']);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I stop ASP.NET Core 2.0 MVC minification from ...
As you may deduct from the name, the gulp-filter plugin is what we will use to exclude files from the minification process.
Read more >
Getting Started with Gulp.js - Semaphore Tutorial
Learn how to set up and use Gulp.js, a task runner for Node.js based on Node streams. ... Create a sample Sass file...
Read more >
PTE Reading Practice Class | Grammar Rules and Tricks
PTE Reading Practice Class✓In this video, our PTE Expert Ripan shares some important Tips to solve PTE Reading Blanks, Reading & Writing ...
Read more >
Release notes | U.S. Web Design System (USWDS) - Digital.gov
Tooltip now initializes on first interaction and checks if it has been ... Starting in USWDS 3.0, projects will use settings files that...
Read more >
license_scanning (#2758) · Jobs · osm / NG-UI · GitLab
n\n## Installing\n\nIf you use NPM, `npm install d3-transition`. ... If multiple typenames are specified, the first matching listener is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found