Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative glob not working as expected #2275

Closed
plesiecki opened this issue Dec 22, 2018 · 9 comments
Closed

Negative glob not working as expected #2275

plesiecki opened this issue Dec 22, 2018 · 9 comments
Labels

Comments

@plesiecki
Copy link

Hello,

I think I noticed issue with negative glob 🤔

Files structures looks like this:

foo/foo.html
bar/bar.html
gulpfile.js

Here goes the task

const {src, dest} = require('gulp');

module.exports.default = () => src(['**/*.html', '!bar/']).pipe(dest('dest'));

After running this task dest dir contains bar.

I expected dest dir not to include bar.

I made repl.it for this issue https://repl.it/@plesiecki/InvolvedIndianredProgramminglanguages. You can reproduce with single click (by clicking green run button at the top of the page). Remember to delete dest directory before you run the task (if it exists)

Gulp 4
Node 10.12.0
Npm 6.4.1

@plesiecki
Copy link
Author

@nstungcom
Copy link

Can you try this:

const {src, dest} = require('gulp');

module.exports.default = () => src(['**/*.html', '!**/bar/**']).pipe(dest('dest'));

@phated
Copy link
Member

phated commented Feb 26, 2019

I just ran the repl.it in the original link and the output is correct. There is no bar in the dest/ directory.

screen shot 2019-02-25 at 8 59 09 pm

@phated phated closed this as completed Feb 26, 2019
@phated phated added the invalid label Feb 26, 2019
@nstungcom
Copy link

@phated The original link contain edited code!

This still not working: module.exports.default = () => src(['**/*.html', '!bar/']).pipe(dest('dest'));

This work : module.exports.default = () => src(['**/*.html', '!**/bar/**']).pipe(dest('dest'));

image

image

But when it's working for OP then this can stay closed.

@plesiecki
Copy link
Author

@phated Sorry, repl.it example was modified with @nstungcom idea:

Can you try this:

const {src, dest} = require('gulp');

module.exports.default = () => src(['**/*.html', '!**/bar/**']).pipe(dest('dest'));

I restored original code.

@nstungcom What does OP stand for?

@phated
Copy link
Member

phated commented Mar 3, 2019

@plesiecki this seems to be an issue with node-glob

I just ran this test:

const glob = require('glob');

console.log(glob.sync('**/*.html', { ignore: 'bar/' }))

and the results are the same as what you are seeing with gulp (we use node-glob as a dependency)

You can also use:

src(['**/*.html', '!bar/**/*']).pipe(dest('dest'));

as an alternative, but I'd recommend scoping your original glob better because it picks up dest on subsequent runs.

I'll create a followup issue to fix the docs.

@plesiecki
Copy link
Author

@phated Awesome.
Just noticed fast-glob doesn't have this issue. fast-glob is a drop-in replacement for node-glob. I can send a PR.

@phated
Copy link
Member

phated commented Apr 27, 2019

@plesiecki I would have to do a ton of research to figure out if we could use it. Even then, it might cause unexpected issues which would require a major bump.

However, I did more investigating here and found that I was mistaken with the way ignores work. You need to specify node_modules/** and then node-glob removes the /** part and just matches the base directory. See the code at https://github.com/isaacs/node-glob/blob/master/common.js#L42 - so it wasn't actually a regression and I just need to update our docs.

@plesiecki
Copy link
Author

Awesome, great work ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants