/** * @return string */ public function compile() { $this->stopwatch->start('webpack.total'); $this->stopwatch->start('webpack.prepare'); // Recompile twig templates where its needed. $this->addSplitPoints(); $this->addResolveConfig(); // Write the webpack configuration file. file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.config.js', $this->generator->getConfiguration()); $this->profiler->set('compiler.performance.prepare', $this->stopwatch->stop('webpack.prepare')->getDuration()); $this->stopwatch->start('webpack.compiler'); $this->process->run(); $output = $this->process->getOutput() . $this->process->getErrorOutput(); $this->profiler->set('compiler.executed', true); $this->profiler->set('compiler.successful', strpos($output, 'Error:') === false); $this->profiler->set('compiler.last_output', $output); 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.total', $this->stopwatch->stop('webpack.total')->getDuration()); return $output; }
public function testTracker() { $profiler = new Profiler(); $finder = $this->getMock(TemplateFinderInterface::class); $fixture_path = realpath(__DIR__ . '/../../Fixture'); $temp_file = $fixture_path . '/Bundle/tempfile.txt'; $temp_file2 = $fixture_path . '/Bundle/tempfile2.txt'; $temp_file3 = $fixture_path . '/Bundle/tempfile3.txt'; $tracker = new Tracker($profiler, $finder, $fixture_path . '/cache', $fixture_path, 'Resources', ['FooBundle' => $fixture_path . '/Bundle/FooBundle', 'BarBundle' => $fixture_path . '/Bundle/BarBundle']); touch($temp_file); $tracker->addPath($temp_file); $tracker->addPath($fixture_path . '/Bundle'); $finder->expects($this->once())->method('findAllTemplates')->willReturn([new TemplateReference('dont_parse_me', 'php'), new TemplateReference('@FooBundle/foo.html.twig', 'twig'), new TemplateReference('@AcmeBundle/foo.html.twig', 'twig'), new TemplateReference('template.html.twig', 'twig'), new TemplateReference('i_dont_exist', 'twig')]); $this->assertEquals('/i/cant/be/resolved', $tracker->resolveResourcePath('/i/cant/be/resolved')); // Start by removing the cache file, if it exists. if (file_exists($fixture_path . '/cache/webpack.asset_tracker.cache')) { unlink($fixture_path . '/cache/webpack.asset_tracker.cache'); } $this->assertTrue($tracker->isOutdated()); // Start by rebuilding the cache $tracker->rebuild(); // Since cache is fresh, isOutdated should return false. $this->assertFalse($tracker->isOutdated()); // Modify something. touch($temp_file, time() + 1 + mt_rand(1, 100)); $this->assertTrue($tracker->isOutdated()); // Create something $tracker->rebuild(); touch($temp_file2); $this->assertTrue($tracker->isOutdated()); unlink($temp_file); unlink($temp_file2); touch($temp_file3); $this->assertTrue($tracker->isOutdated()); $tracker->rebuild(); touch($temp_file, time() + 10); $this->assertTrue($tracker->isOutdated()); unlink($temp_file3); }