postcss / postcss-cli

CLI for postcss
Other
824 stars 93 forks source link

Add support for glob matching when watching dir-dependency #391

Closed 1st8 closed 2 years ago

1st8 commented 2 years ago

This extends #383 to pass glob information on to chokidar, with the intention of reducing outputs when unrelated files are modified.

In my test example the output should only be triggered when files matching the glob: '**/*.css' are modified, but not when the unrelated.md file is modified.

A real world example where I thought watching a whole directory without applying the glob could be problematic, would be a full stack project where tailwind checks backend templates by file type for purging:

  {
    plugin: 'tailwindcss',
    parent: '/home/1st8/sample_phoenix_project/assets/css/app.css',
    type: 'dir-dependency',
    dir: '/home/1st8/sample_phoenix_project',
    glob: '**/*.heex'
  }

In this case I really only want to trigger rebuilds when changing one of the listed file types.

Chokidar supports all this out of the box btw.

Let me know what you think and thanks for the great project! Cheers!

RyanZim commented 2 years ago

I'm not closed to this idea; are there any plugins that use this .glob property? Dependency messages are standardized across the ecosystem, all runners will have to support this, cc @ai for thoughts.

ai commented 2 years ago

postcss-mixins uses glob https://github.com/postcss/postcss-mixins/blob/main/index.js#L81-L86

It is part of standard https://github.com/postcss/postcss/blob/main/docs/guidelines/runner.md#31-rebuild-when-dependencies-change

RyanZim commented 2 years ago

Ah, wasn't up on the standards changes, in that case, LGTM.