gulp icon indicating copy to clipboard operation
gulp copied to clipboard

Exclude path from src not working ('!../folder')?

Open sabsaxo opened this issue 5 years ago • 13 comments

Why is this '!../frontend/admin/modules/login/*.scss' ignored from the gulp.src([ … ]) list?

And by ignored I mean it still gets included ; )

sabsaxo avatar Aug 22 '18 08:08 sabsaxo

The file globing is one of the core components of Gulp. A bug is still possible, but it is likely to be a configuration error. If you wish to report a bug, you need to use the issue template. Without this information it is hard to act on your report.

demurgos avatar Aug 22 '18 09:08 demurgos

What were you expecting to happen? Expected excluded files in gulp.src to be excluded

What actually happened? Excluded files with ../ where not excluded on Mac/Linux, seems to work on Windows

Please post a sample of your gulpfile (preferably reduced to just the bit that's not working)

gulp.task('jshint', function () {
    return gulp.src([
      '../src/app/scripts/**/*.js',
      '!../src/app/scripts/**/*.spec.js'
    ])
      .pipe(plugins.jshint())
      .pipe(plugins.jshint.reporter('default'));
  });

What version of gulp are you using? 4.0.0

What versions of npm and node are you using? npm 6.2.0 node 10.9.0

42tte avatar Aug 28 '18 12:08 42tte

I fixed my issue by moving the gulpfile to the root level, and made a bit of rearranging to avoid the ../ part of the path.

sabsaxo avatar Aug 28 '18 12:08 sabsaxo

Can also be done with gulp.src cwd option gulp.src([ 'src/app/scripts/**/*.js', '!src/app/scripts/**/*.spec.js' ], { cwd: '../'});

But I'd prefer not to rewrite all my scripts

42tte avatar Aug 28 '18 12:08 42tte

I am unable to replicate this. Can someone provide a repository and specific instructions on how to reproduce?

phated avatar Apr 27 '19 14:04 phated

I am unable to require in gulpfile.js the separate tasks in different .js files

darellwest avatar Oct 25 '19 23:10 darellwest

@42tte thanks, worked for me

andreyc0d3r avatar Feb 17 '20 10:02 andreyc0d3r

Created a repository that could be used for reproduction: https://github.com/marius-klimantavicius/gulp-repro-2211

As mentioned before - it does work correctly in Windows. For me it fails when being run in linux docker container (haven't tested full linux vm though).

To reproduce 1: npm install in /app npx gulp build in /app or docker build . in /

Expected result: *.spec.js file names are not printed to console.

Actual result: *.spec.js file name is printed but only from parent glob.

marius-klimantavicius avatar May 06 '20 05:05 marius-klimantavicius

Oh my god, this was killing me, couldn't figure out why the heck the negation didn't work for me and then I came across this. Sheesh. I'm on Ubuntu Linux 18.04. The cwd trick did it for me.

crowmagnumb avatar Oct 02 '20 05:10 crowmagnumb

Just experienced this today... Gulp4. Following @42tte workaround worked, also don't wanna rewrite everything. Thanks @42tte

totszwai avatar Nov 03 '20 16:11 totszwai

Thanks @42tte!

FlorentTorregrosa avatar Mar 08 '21 14:03 FlorentTorregrosa

Hello, a little question anyway: is it a bug or a feature since it was not working the same on Gulp v3? Thanks for your support!

lordfpx avatar Nov 29 '21 14:11 lordfpx

negation is not working for me on Windows. Or perhaps I am not doing it right and the documentation needs to be improved. My folder structure /root/project1/[html | src | etc] /root/build/preprocess/gulpfile.js

The following line does exclude all the contents within src: (project.directory is a relative path from the gulpfile: "../../*")

gulp.src([
            `${project.directory}/**`,
            `!${project.directory}/src/**`,
])

However, doing something like:

let task = gulp.src([
            `${project.directory}/**`,
            `!${project.directory}/src/*.js`,
        ])

or

let task = gulp.src([
            `${project.directory}/**`,
            `!${project.directory}/src/**/*.js`,
        ])

or

let task = gulp.src([
            `${project.directory}/**`,
            `!${project.directory}/src/**.js`,
        ])

does not work.

KarelChanivecky avatar Mar 18 '22 00:03 KarelChanivecky

This will be fixed in gulp v5 via glob-stream v8. See https://github.com/gulpjs/to-absolute-glob/pull/2 for more information.

phated avatar Jan 03 '23 23:01 phated