-
-
Notifications
You must be signed in to change notification settings - Fork 84
Allow to define multiple entrypoints and load assets from each of them. #17
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
Changes from all commits
ebe61d9
0f69516
59bbd29
2c38514
a238fe7
0f3134b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony WebpackEncoreBundle package. | ||
* (c) Fabien Potencier <[email protected]> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\WebpackEncoreBundle\Asset; | ||
|
||
use Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Aggregate the different entry points configured in the container. | ||
* | ||
* Retrieve the EntrypointLookup instance from the given key. | ||
* | ||
* @final | ||
*/ | ||
class EntrypointLookupCollection | ||
{ | ||
private $buildEntrypoints; | ||
|
||
public function __construct(ContainerInterface $buildEntrypoints) | ||
{ | ||
$this->buildEntrypoints = $buildEntrypoints; | ||
} | ||
|
||
public function getEntrypointLookup(string $buildName): EntrypointLookupInterface | ||
{ | ||
if (!$this->buildEntrypoints->has($buildName)) { | ||
throw new UndefinedBuildException(sprintf('Given entry point "%s" is not configured', $buildName)); | ||
} | ||
|
||
return $this->buildEntrypoints->get($buildName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony WebpackEncoreBundle package. | ||
* (c) Fabien Potencier <[email protected]> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\WebpackEncoreBundle\Exception; | ||
|
||
class UndefinedBuildException extends \InvalidArgumentException | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,33 +34,34 @@ public function getFunctions() | |
]; | ||
} | ||
|
||
public function getWebpackJsFiles(string $entryName): array | ||
public function getWebpackJsFiles(string $entryName, string $entrypointName = '_default'): array | ||
{ | ||
return $this->getEntrypointLookup() | ||
return $this->getEntrypointLookup($entrypointName) | ||
->getJavaScriptFiles($entryName); | ||
} | ||
|
||
public function getWebpackCssFiles(string $entryName): array | ||
public function getWebpackCssFiles(string $entryName, string $entrypointName = '_default'): array | ||
{ | ||
return $this->getEntrypointLookup() | ||
return $this->getEntrypointLookup($entrypointName) | ||
->getCssFiles($entryName); | ||
} | ||
|
||
public function renderWebpackScriptTags(string $entryName, string $packageName = null): string | ||
public function renderWebpackScriptTags(string $entryName, string $packageName = null, string $entrypointName = '_default'): string | ||
{ | ||
return $this->getTagRenderer() | ||
->renderWebpackScriptTags($entryName, $packageName); | ||
->renderWebpackScriptTags($entryName, $packageName, $entrypointName); | ||
} | ||
|
||
public function renderWebpackLinkTags(string $entryName, string $packageName = null): string | ||
public function renderWebpackLinkTags(string $entryName, string $packageName = null, string $entrypointName = '_default'): string | ||
{ | ||
return $this->getTagRenderer() | ||
->renderWebpackLinkTags($entryName, $packageName); | ||
->renderWebpackLinkTags($entryName, $packageName, $entrypointName); | ||
} | ||
|
||
private function getEntrypointLookup(): EntrypointLookupInterface | ||
private function getEntrypointLookup(string $entrypointName): EntrypointLookupInterface | ||
{ | ||
return $this->container->get('webpack_encore.entrypoint_lookup'); | ||
return $this->container->get('webpack_encore.entrypoint_lookup_collection') | ||
->getEntrypointLookup($entrypointName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've removed the lookup / collection usage to rely only on collection. |
||
} | ||
|
||
private function getTagRenderer(): TagRenderer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Symfony\WebpackEncoreBundle\Tests\Asset; | ||
|
||
use Symfony\Component\DependencyInjection\ServiceLocator; | ||
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class EntrypointLookupCollectionTest extends TestCase | ||
{ | ||
/** | ||
* @expectedException Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException | ||
* @expectedExceptionMessage Given entry point "something" is not configured | ||
*/ | ||
public function testExceptionOnMissingEntry() | ||
{ | ||
$collection = new EntrypointLookupCollection(new ServiceLocator([])); | ||
$collection->getEntrypointLookup('something'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reordering of the args breaks BC. What if we did this:
EntrypointLookupCollection
EntrypointLookupCollection
(as that would be a BC break). Instead, we would do aninstanceof
check in the constructor: if the user is passing anEntrypointLookupInterface
, we would trigger a BC warning (example: https://github.com/symfony/symfony/blob/63d34515a51819a6a6b3a94d598e8e37068e85ce/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php#L36). In this situation, we would instantiate anew EntrypountLookupCollection()
and pass in just the oneEntrypointLookupInterface
object. If they pass something that is neither of these 2 types, we would throw aTypeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I understand the point about BC breaks 😄
Only one question about the exception message. For the TypeError, I think:
For the BC warning :
We do you think ?