Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Bundle/Twig/Token/WebpackTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Hostnet\Bundle\WebpackBundle\Twig\Node\WebpackInlineNode;
use Hostnet\Bundle\WebpackBundle\Twig\Node\WebpackNode;
use Hostnet\Bundle\WebpackBundle\Twig\TwigExtension;
use Hostnet\Component\Webpack\Asset\TwigParser;

/**
* @author Harold Iedema <hiedema@hostnet.nl>
Expand Down Expand Up @@ -130,7 +131,7 @@ private function parseInline(\Twig_TokenStream $stream, $lineno)
$this->inline_blocks[$file] = 0;
}

$file_name = md5($file . $this->inline_blocks[$file]) . '.js';
$file_name = TwigParser::hashInlineFileName($file, $this->inline_blocks[$file]) . '.js';
$assets = $this->extension->webpackAsset('cache.' . $file_name);

$this->inline_blocks[$file]++;
Expand Down
19 changes: 18 additions & 1 deletion src/Component/Asset/TwigParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ public function __construct(Tracker $tracker, \Twig_Environment $twig, $cache_di
$this->cache_dir = $cache_dir;
}

/**
* Consistently calculate file name hashes.
*
* @param $template_file
* @param $block_index
* @return string
*/
public static function hashInlineFileName($template_file, $block_index)
{
// Work around path inconsistencies on Windows/XAMPP.
if (DIRECTORY_SEPARATOR == '\\') {
$template_file = str_replace('\\', '/', $template_file);
}
$hash = md5($template_file . $block_index);
return $hash;
}

/**
* Returns an array of split points from the given template file.
*
Expand Down Expand Up @@ -53,7 +70,7 @@ public function findSplitPoints($template_file)
$stream->next();

$token = $stream->next();
$file_name = md5($template_file . $inline_blocks);
$file_name = TwigParser::hashInlineFileName($template_file, $inline_blocks);

// Are we dealing with a custom extension? If not, fallback to javascript.
$extension = 'js'; // Default
Expand Down