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

Feature request: negative patterns removing parent paths too #15

Open
derMart opened this issue Apr 21, 2015 · 4 comments
Open

Feature request: negative patterns removing parent paths too #15

derMart opened this issue Apr 21, 2015 · 4 comments

Comments

@derMart
Copy link

derMart commented Apr 21, 2015

If you have a match like ['parent/**','!/parent/level1/level2/test.txt']
currently the parent directories of test.txt will remain in the matching list:

'parent/'
'parent/level1/'
'parent/level1/level2/'

If you want to use f.e. https://github.com/sindresorhus/del to delete these matches test.txt will be removed too. To delete a directory, but preserve some subset, the parent directories of any negative match need to be removed too.
See also sindresorhus/del#3

@UltCombo
Copy link
Contributor

I believe that's the expected globbing behavior: ['parent/**','!/parent/level1/level2/test.txt'] gets all files and directories descendant of parent and excludes a single leaf file.

Adding your suggested magic does not only add complexity, it may also yield unexpected results for usages other than deleting. I believe the correct solution would be changing your glob patterns to:

['parent/**', '!parent/level1', '!parent/level1/level2', '!parent/level1/level2/test.txt']

@sindresorhus WDYT?

@derMart
Copy link
Author

derMart commented Apr 21, 2015

Of course I don't want the default behaviour to change. I would suggest adding an option preferably in the options object, like the 'nodir' option for node-glob.

For simple situations your suggested solution would of course work, but in more complex situations it might get impractical or even impossible. Think of patterns where you want to keep the intermediate parent directories dynamic / you just don't know them. F.e. if you have some wildcards inside the negative match (see also sindresorhus/del#3 (comment)). How would you handle this currently?

@UltCombo
Copy link
Contributor

I see.

like the 'nodir' option for node-glob.

If you want the exactly same behavior as node-glob, then you can pass { nodir: true } to globby -- globby uses node-glob under the hood and forwards the options object to it.

If you want negative globs to also "match" the directories which are ancestors of a match (thus removing them from the results set), then things are more tricky. Perhaps a config option would make sense.

@sindresorhus
Copy link
Owner

I think this will have to be resolved in fast-glob first. So I suggest opening in issue over there.

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

No branches or pull requests

3 participants