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
16 changes: 11 additions & 5 deletions src/Bundle/DependencyInjection/WebpackCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ public function process(ContainerBuilder $container)
$bundle_paths[$name] = realpath(dirname((new \ReflectionClass($class))->getFileName()));
}

$asset_tracker->replaceArgument(4, $asset_res_path);
$asset_tracker->replaceArgument(3, $asset_res_path);
$asset_tracker->replaceArgument(4, $path);
$asset_tracker->replaceArgument(5, $bundle_paths);

// add all aliases to the tracker
if (isset($config['resolve']['alias']) && is_array($config['resolve']['alias'])) {
foreach ($config['resolve']['alias'] as $alias => $path) {
if (!file_exists($path)) {
foreach ($config['resolve']['alias'] as $alias_path) {
if (!file_exists($alias_path)) {
continue;
}
$asset_tracker->addMethodCall('addPath', [$path]);
$asset_tracker->addMethodCall('addPath', [$alias_path]);
}
}

Expand Down Expand Up @@ -73,7 +74,12 @@ public function process(ContainerBuilder $container)

// Ensure webpack is installed in the given (or detected) node_modules directory.
if (false === ($webpack = realpath($config['node']['node_modules_path'] . '/webpack/bin/webpack.js'))) {
throw new \RuntimeException(sprintf('Webpack is not installed in path "%s".', $config['node']['node_modules_path']));
throw new \RuntimeException(
sprintf(
'Webpack is not installed in path "%s".',
$config['node']['node_modules_path']
)
);
}

$process_definition = $container
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/Resources/config/webpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ services:
arguments:
- '@hostnet_webpack.bridge.profiler'
- '@templating.finder'
- '%kernel.cache_dir%'
- '%kernel.root_dir%'
- '' # asset_path
- '' # output dir
- [] # bundles

hostnet_webpack.bridge.asset_dumper:
Expand Down
12 changes: 6 additions & 6 deletions src/Component/Asset/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ public function compile()
$output = $this->process->getOutput() . $this->process->getErrorOutput();
$this->profiler->set('compiler.executed', true);
$this->profiler->set('compiler.last_output', $output);
$this->profiler->set('compiler.successful',
$this->profiler->set(
'compiler.successful',
strpos($output, 'Error:') === false &&
strpos($output, 'parse failed') === false
);

if ($this->profiler->get('compiler.successful')) {
$this->tracker->rebuild();
}

// Finally, write some logging for later use.
file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.compiler.log', $output);

$this->profiler->set('compiler.performance.compiler', $this->stopwatch->stop('webpack.compiler')->getDuration());
$this->profiler->set(
'compiler.performance.compiler',
$this->stopwatch->stop('webpack.compiler')->getDuration()
);
$this->profiler->set('compiler.performance.total', $this->stopwatch->stop('webpack.total')->getDuration());

return $output;
Expand Down
77 changes: 77 additions & 0 deletions src/Component/Asset/TrackedFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
namespace Hostnet\Component\Webpack\Asset;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

/**
* This class tracks a set of files, and offers a function to see if one of the files is changed after a certain time.
*/
class TrackedFiles
{

/**
* The last modified time for the set of files, in a Unix timestamp.
*
* @var int
*/
private $modification_time;

/**
* Track a set of paths
*
* @param array $paths the list of directories or files to track / follow
*/
public function __construct(array $paths)
{
//Filter out the files, the Finder class can not handle files in the ->in() call.
$files = array_filter(
$paths,
function ($possible_file) {
return is_file($possible_file);
}
);

//Filter out the directories to be used for searching using the Filter class.
$dirs = array_filter(
$paths,
function ($possible_dir) {
return is_dir($possible_dir);
}
);

$finder = new Finder();

//Add the given 'stand-alone-files'
$finder->append($files);

//Add the Directores recursively
$finder = $finder->in($dirs);

//Filter out non readable files
$finder = $finder->filter(
function (SplFileInfo $finder) {
return $finder->isReadable();
}
);

//Loop through all the files and save the latest modification time.
foreach ($finder->files() as $file) {
/*@var $file \SplFileInfo */
if ($this->modification_time < $file->getMTime()) {
$this->modification_time = $file->getMTime();
}
}
}

/**
* Is one of the Tracked files in this set changed later than the other set.
*
* @param TrackedFiles $other the other set of files to compare to.
* @return boolean true if this set if this set is modified after (later) the other set.
*/
public function modifiedAfter(TrackedFiles $other)
{
return $this->modification_time > $other->modification_time;
}
}
Loading