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

feat: support negative globs #1324

Merged
merged 1 commit into from Nov 30, 2023
Merged

feat: support negative globs #1324

merged 1 commit into from Nov 30, 2023

Conversation

pd93
Copy link
Member

@pd93 pd93 commented Sep 7, 2023

Fixes #225

This PR adds native support for negating a glob pattern in Task. e.g.

version: '3'

tasks:
  css:
    sources:
      - 'mysources/**/*.css'
      - '!mysources/ignoreme.css'
    generates:
      - 'public/bundle.css'

It works by looping over an array of patterns in order. If a pattern is normal, the files are added to a map with a value of true (i.e. the files should be included). if a pattern begins with a !, then all the files matched by that pattern are added to (or updated in) the map with a value of false (i.e. they should not be included). We then loop through the map and convert all keys with a value of true into a slice. This slice is then sorted and returned.

@pd93 pd93 mentioned this pull request Sep 7, 2023
@krystian-panek-wttech
Copy link

krystian-panek-wttech commented Sep 7, 2023

I just tested it. thank you @pd93

It works like a charm <3 however the '!' needs special care as it is special character in YML. without it it is possible to encounter:

image

https://stackoverflow.com/a/22235064

my working example:

  aem:build:
    desc: build AEM application using Maven
    sources:
      - pom.xml
      - all/pom.xml
      - all/src/**/*
      - core/pom.xml
      - core/src/**/*
      - ui.apps/pom.xml
      - ui.apps/src/**/*
      - '!ui.apps/src/main/content/jcr_root/apps/mysite/clientlibs/clientlib-{site,dependencies}/**/*'
      - ui.apps.structure/pom.xml
      - ui.apps.structure/src/**/*
      - ui.config/pom.xml
      - ui.config/src/**/*
      - ui.content/pom.xml
      - ui.content/src/**/*
      - ui.frontend/pom.xml
      - ui.frontend/*.js
      - ui.frontend/*.json
      - '!ui.frontend/package-lock.json'
      - ui.frontend/src/**/*

I hope it will be released soon ;)

Copy link
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid YAML issues with ! we could move to a proper key like not:, ignore: or exclude:. What do you think?

version: '3'

tasks:
  css:
    sources:
      - mysources/**/*.css
      - exclude: mysources/ignoreme.css
    generates:
      - public/bundle.css

I think I would chose exclude:, but I'm open to opinions.

@krystian-panek-wttech
Copy link

krystian-panek-wttech commented Sep 8, 2023

yep, it's nice ;) also opting for exclude

@krystian-panek-wttech
Copy link

can't wait to see it released ;) @andreynering

@leaanthony
Copy link
Contributor

Yeah, exclude: is great 👍

@andreynering
Copy link
Member

Hey @pd93,

Can you change to use exclude:? Once done, we're ready to merge this.

@andreynering andreynering added the type: feature A new feature or functionality. label Oct 7, 2023
@krystian-panek-wttech
Copy link

@pd93 any chance that you will do it this month? :) From my perspective it's pretty annoying and I would be glad to have it improved. If you have no time to complete this, just let me know I will improve it.

Co-authored-by: Andrey Nering <andrey@nering.com.br>
@andreynering andreynering merged commit ec35d43 into main Nov 30, 2023
11 checks passed
@andreynering andreynering deleted the glob-negation branch November 30, 2023 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature or functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extended globbing support
4 participants