Skip to content

Commit

Permalink
Fixes contextual imports
Browse files Browse the repository at this point in the history
This fixes an issue where imports outside the base path throws a file not found error
  • Loading branch information
daftspunk committed Apr 25, 2021
1 parent 3dbcc8a commit cbff57a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Assetic/Asset/AssetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ public function getSourcePath()
{
}

/**
* getSourceDirectory returns the first available source directory, useful
* when extracting imports and a singular collection is returned
*/
public function getSourceDirectory()
{
foreach ($this as $asset) {
return $asset->getSourceDirectory();
}
}

public function getTargetPath()
Expand Down
11 changes: 7 additions & 4 deletions src/Assetic/Filter/ScssphpFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

use October\Rain\Assetic\Asset\AssetInterface;
use October\Rain\Assetic\Factory\AssetFactory;
use October\Rain\Assetic\Util\CssUtils;
use October\Rain\Assetic\Util\SassUtils;
use ScssPhp\ScssPhp\Compiler;

/**
* Loads SCSS files using the PHP implementation of scss, scssphp.
*
* Scss files are mostly compatible, but there are slight differences.
*
* @link http://leafo.net/scssphp/
* @link https://github.com/scssphp/scssphp
*
* @author Bart van den Burg <bart@samson-it.nl>
*/
Expand Down Expand Up @@ -131,12 +131,15 @@ public function getChildren(AssetFactory $factory, $content, $loadPath = null)
}

$children = array();
foreach (CssUtils::extractImports($content) as $match) {
foreach (SassUtils::extractImports($content) as $match) {
$file = $sc->findImport($match);
if ($file) {
$children[] = $child = $factory->createAsset($file, array(), array('root' => $loadPath));
$child->load();
$children = array_merge($children, $this->getChildren($factory, $child->getContent(), $loadPath));
$children = array_merge(
$children,
$this->getChildren($factory, $child->getContent(), $child->getSourceDirectory())
);
}
}

Expand Down

0 comments on commit cbff57a

Please sign in to comment.