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

Add generic pipe filters #60

Merged
merged 5 commits into from
Jun 3, 2020
Merged

Conversation

berarma
Copy link
Contributor

@berarma berarma commented May 10, 2020

There's an input and an output filter that can be configured to execute an external command passing the file as a parameter. I've called them pipes although I'm not using system pipes.

In the input filter, the dependencies setting changes how dependencies are handled. We can choose not having dependencies calculated but use the source file timestamp (none), use CSS dependency calculation (css), or always run the filter (other).

@codecov-io
Copy link

codecov-io commented May 10, 2020

Codecov Report

Merging #60 into master will increase coverage by 3.70%.
The diff coverage is 90.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #60      +/-   ##
============================================
+ Coverage     73.16%   76.87%   +3.70%     
- Complexity      445      453       +8     
============================================
  Files            50       52       +2     
  Lines          1226     1241      +15     
============================================
+ Hits            897      954      +57     
+ Misses          329      287      -42     
Impacted Files Coverage Δ Complexity Δ
src/Output/FreshTrait.php 92.30% <75.00%> (-3.35%) 13.00 <0.00> (+1.00) ⬇️
src/Filter/PipeInputFilter.php 92.85% <92.85%> (ø) 6.00 <6.00> (?)
src/Filter/PipeOutputFilter.php 100.00% <100.00%> (ø) 1.00 <1.00> (?)
src/Filter/AssetFilter.php 46.15% <0.00%> (+23.07%) 11.00% <0.00%> (ø%)
src/AssetProcess.php 94.28% <0.00%> (+94.28%) 10.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f72b70...f96cee9. Read the comment docs.

@berarma
Copy link
Contributor Author

berarma commented May 10, 2020

As discussed in markstory/asset_compress#344.

*/
protected $optionalDependencyPrefix = null;

public function getDependencies(\MiniAsset\AssetTarget $file)
Copy link
Owner

Choose a reason for hiding this comment

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

Could this class be added to the use list? That would be more consistent with the rest of this project.

public function getDependencies(\MiniAsset\AssetTarget $file)
{
if ($this->_settings['dependencies'] !== 'none' && $this->_settings['dependencies'] !== 'css') {
return false;
Copy link
Owner

Choose a reason for hiding this comment

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

You should return [] here to be consistent with other implementations.

if (substr($filename, strlen($this->_settings['ext']) * -1) !== $this->_settings['ext']) {
return $input;
}
$filename = preg_replace('/ /', '\\ ', $filename);
Copy link
Owner

Choose a reason for hiding this comment

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

You could use escapeshellarg() instead.

Comment on lines 93 to 96
$dependencies = $filter->getDependencies($target);
if ($dependencies === false) {
return false;
}
Copy link
Owner

Choose a reason for hiding this comment

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

This feels like conflating concerns. Overloading the dependency detection to hand mtime overrides feels wrong. Could we add a new filter hook that allows filters to overrule the mtime value and only implement in the pipe filters.

@codecov-commenter
Copy link

codecov-commenter commented May 26, 2020

Codecov Report

Merging #60 into master will increase coverage by 3.26%.
The diff coverage is 80.95%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #60      +/-   ##
============================================
+ Coverage     73.16%   76.43%   +3.26%     
- Complexity      445      459      +14     
============================================
  Files            50       52       +2     
  Lines          1226     1256      +30     
============================================
+ Hits            897      960      +63     
+ Misses          329      296      -33     
Impacted Files Coverage Δ Complexity Δ
src/Output/FreshTrait.php 92.00% <50.00%> (-3.66%) 13.00 <0.00> (+1.00) ⬇️
src/Filter/PipeInputFilter.php 78.57% <78.57%> (ø) 5.00 <5.00> (?)
src/Filter/AssetFilter.php 50.00% <100.00%> (+26.92%) 12.00 <1.00> (+1.00)
src/Filter/PipeOutputFilter.php 100.00% <100.00%> (ø) 1.00 <1.00> (?)
src/AssetConfig.php 94.05% <0.00%> (-0.03%) 92.00% <0.00%> (ø%)
src/Filter/ScssPHP.php 0.00% <0.00%> (ø) 5.00% <0.00%> (+2.00%)
src/Filter/CssDependencyTrait.php 98.11% <0.00%> (+0.24%) 21.00% <0.00%> (+2.00%)
src/Filter/ScssFilter.php 16.66% <0.00%> (+16.66%) 4.00% <0.00%> (+2.00%)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f72b70...eb8b436. Read the comment docs.

if ($this->_settings['dependencies']) {
$this->optionalDependencyPrefix = $this->_settings['optional_dependency_prefix'];

return $this->getCssDependencies($file);
Copy link
Owner

Choose a reason for hiding this comment

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

How do you know that the file being processed is CSS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the dependencies setting is true the CSS-like dependencies are used. I was previously using a text setting in case there were more dependency types added later but I've decided to simplify. It should be set to false when there's no CSS-like imports.

Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't a safer default be false then? In the docblock for the settings/filter the usage could be explained.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't a safer default be false then? In the docblock for the settings/filter the usage could be explained.

I think I did it because the default extension is .css. Maybe I should change that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markstory, please, review the settings changes in the new commit.

@markstory markstory merged commit 67e7789 into markstory:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants