Skip to content
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

Add support for Symfony 6 #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
81 changes: 81 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Test

on: [push]

jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- php-version: 8.1
symfony-version: 5.4.*
composer-args: prefer-lowest
node-version: 12
- php-version: 8.1
symfony-version: 6.4.*
composer-args: ''
node-version: 12
- php-version: 8.2
symfony-version: 5.4.*
composer-args: ''
node-version: 12
- php-version: 8.2
symfony-version: 6.4.*
composer-args: ''
node-version: 12

name: PHP ${{ matrix.php-version }} Test with Symfony ${{ matrix.symfony-version }} and ${{ matrix.composer-args }}
steps:
# —— Setup Github actions 🐙 —————————————————————————————————————————————
- name: Checkout
uses: actions/checkout@v3

# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, xml, ctype, iconv, intl
coverage: xdebug #optional

# https://github.com/marketplace/actions/setup-php-action#problem-matchers
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

# https://github.com/marketplace/actions/setup-php-action#problem-matchers
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

# —— Composer 🧙‍️ —————————————————————————————————————————————————————————
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php-version }}-${{ matrix.symfony-version }}--${{ matrix.stability }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.php-version }}-${{ matrix.symfony-version }}--${{ matrix.stability }}-

- name: Install NPM and Yarn
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Validate Composer.json
run: composer validate

- name: Install PHP dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
run: |
composer update --no-interaction --prefer-dist --optimize-autoloader --${{ matrix.composer-args }}

## —— Test ✅ ———————————————————————————————————————————————————————————
- name: Run Tests
run: php vendor/bin/codecept run
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
vendor
composer.phar
composer.lock
tests/_output/*
tests/_support/_generated
/tests/support/_generated/
/tests/functional/Fixtures/package.json
tests/functional/Fixtures/node_modules
tests/functional/Fixtures/root_v1/node_modules
/tests/functional/Fixtures/app/config/webpack.config.js
/tests/functional/Fixtures/var/
.php_cs.cache
.idea
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ is updated and as a task in your deployment). Of course, you could just add it t
git add package.json app/config/webpack.config.js
```

If you want to use Webpack 1 for some reason, pass `--useWebpack1` as a command line option to `setup` command.

Usage
----

Expand Down
8 changes: 5 additions & 3 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace: Test
support_namespace: Support
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
output: tests/_output
data: tests/support/Data
support: tests/support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
Expand Down
46 changes: 28 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
"name": "maba/webpack-bundle",
"type": "symfony-bundle",
"description": "Bundle to Integrate Webpack to Symfony",
"keywords": ["webpack", "assets", "symfony", "symfony2", "amd", "commonjs"],
"keywords": [
"webpack",
"assets",
"symfony",
"symfony2",
"amd",
"commonjs"
],
"license": "MIT",
"authors": [
{
Expand All @@ -11,26 +18,26 @@
}
],
"require": {
"php": "^5.5 || >=7.0",
"symfony/framework-bundle": "^2.7|^3.0|^4.0",
"symfony/templating": "^2.1|^3.0|^4.0",
"symfony/console": "^2.5|^3.0|^4.0",
"symfony/routing": "^2.7|^3.0|^4.0",
"symfony/process": "^2.5|^3.0|^4.0",
"symfony/dependency-injection": "^2.6|^3.0|^4.0",
"symfony/twig-bundle": "^2.3|^3.0|^4.0",
"symfony/monolog-bundle": "^2.3|^3.0|^4.0",
"twig/twig": "^1.27|^2.0",
"maba/dependency-injection-extra": "^0.1.1|^1.0"
"php": ">=8.1",
"maba/dependency-injection-extra": "^0.1.1|^1.0",
"symfony/console": "^5.0|^6.0",
"symfony/dependency-injection": "^5.0|^6.0",
"symfony/framework-bundle": "^5.0|^6.0",
"symfony/monolog-bundle": "^3.0",
"symfony/process": "^5.0|^6.0",
"symfony/routing": "^5.0|^6.0",
"symfony/templating": "^5.0|^6.0",
"symfony/twig-bundle": "^5.0|^6.0",
"twig/twig": "^2.0|^3.0"
},
"require-dev": {
"codeception/codeception": "^5.0",
"codeception/module-asserts": "^3.0",
"codeception/module-filesystem": "^3.0",
"codeception/module-symfony": "^3.1",
"friendsofphp/php-cs-fixer": "^2.2",
"symfony/framework-bundle": "^2.7.1|^3.0|^4.0",
"codeception/codeception": "~2.3@dev",
"symfony/translation": "^2.7|^3.0|^4.0",
"symfony/asset": "^2.7|^3.0|^4.0",
"doctrine/annotations": "^1.0",
"doctrine/cache": "^1.5"
"symfony/asset": "^5.0|^6.0",
"symfony/translation": "^5.0|^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -41,5 +48,8 @@
"psr-4": {
"Fixtures\\Maba\\Bundle\\": "tests/functional/Fixtures/src"
}
},
"config": {
"sort-packages": true
}
}
4 changes: 2 additions & 2 deletions src/AssetProvider/AssetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function setResource($resource)
}

/**
* @return null|string
* @return string|null
*/
public function getGroup()
{
return $this->group;
}

/**
* @param null|string $group
* @param string|null $group
*/
public function setGroup($group)
{
Expand Down
1 change: 0 additions & 1 deletion src/AssetProvider/AssetResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function setAssets(array $assets)
}

/**
* @param AssetItem $asset
* @return $this
*/
public function addAsset(AssetItem $asset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class BundlesDirectoryProvider implements DirectoryProviderInterface
private $bundles;

/**
* @param KernelInterface $kernel
* @param string $relativeDirectory directory path relative to bundle. For example "/Resources/views"
* @param array $bundles
*/
public function __construct(KernelInterface $kernel, $relativeDirectory, array $bundles)
{
Expand Down
39 changes: 14 additions & 25 deletions src/AssetProvider/TwigAssetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Maba\Bundle\WebpackBundle\Exception\InvalidResourceException;
use Maba\Bundle\WebpackBundle\Exception\ResourceParsingException;
use Maba\Bundle\WebpackBundle\Twig\WebpackExtension;
use Twig_Environment as Environment;
use Twig_Error_Syntax as SyntaxException;
use Twig_Node as Node;
use Twig_Source as Source;
use Twig_Node_Expression_Constant as ConstantFunction;
use Twig_Node_Expression_Function as ExpressionFunction;
use Twig\Environment;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Node;
use Twig\Source;

class TwigAssetProvider
{
Expand Down Expand Up @@ -43,10 +43,7 @@ public function getAssets($fileName, $previousContext = null)
|| !isset($previousContext['assets'])
|| !is_array($previousContext['assets'])
) {
throw new InvalidContextException(
'Expected context with int `modified_at` and array `assets`',
$previousContext
);
throw new InvalidContextException('Expected context with int `modified_at` and array `assets`', $previousContext);
}

if ($previousContext['modified_at'] === filemtime($fileName)) {
Expand All @@ -60,7 +57,7 @@ public function getAssets($fileName, $previousContext = null)
try {
$tokens = $this->twig->tokenize(new Source(file_get_contents($fileName), $fileName));
$node = $this->twig->parse($tokens);
} catch (SyntaxException $exception) {
} catch (SyntaxError $exception) {
$this->errorHandler->processException(
new ResourceParsingException('Got twig syntax exception while parsing', 0, $exception)
);
Expand All @@ -78,7 +75,7 @@ public function getAssets($fileName, $previousContext = null)
private function loadNode(Node $node, $resource)
{
if ($this->isFunctionNode($node)) {
/* @var ExpressionFunction $node */
/* @var FunctionExpression $node */
return $this->parseFunctionNode($node, sprintf('File %s, line %s', $resource, $node->getTemplateLine()));
}

Expand All @@ -94,26 +91,22 @@ private function loadNode(Node $node, $resource)

private function isFunctionNode(Node $node)
{
if ($node instanceof ExpressionFunction) {
if ($node instanceof FunctionExpression) {
return $node->getAttribute('name') === WebpackExtension::FUNCTION_NAME;
}

return false;
}

private function parseFunctionNode(ExpressionFunction $functionNode, $context)
private function parseFunctionNode(FunctionExpression $functionNode, $context)
{
$arguments = iterator_to_array($functionNode->getNode('arguments'));
if (!is_array($arguments)) {
throw new ResourceParsingException('arguments is not an array');
}

if (count($arguments) < 1 || count($arguments) > 3) {
throw new ResourceParsingException(sprintf(
'Expected one to three arguments passed to function %s. %s',
WebpackExtension::FUNCTION_NAME,
$context
));
throw new ResourceParsingException(sprintf('Expected one to three arguments passed to function %s. %s', WebpackExtension::FUNCTION_NAME, $context));
}

$asset = new AssetItem();
Expand All @@ -137,12 +130,8 @@ private function parseFunctionNode(ExpressionFunction $functionNode, $context)

private function getArgumentValue(Node $argument, $context)
{
if (!$argument instanceof ConstantFunction) {
throw new ResourceParsingException(sprintf(
'Argument passed to function %s must be text node to parse without context. %s',
WebpackExtension::FUNCTION_NAME,
$context
));
if (!$argument instanceof ConstantExpression) {
throw new ResourceParsingException(sprintf('Argument passed to function %s must be text node to parse without context. %s', WebpackExtension::FUNCTION_NAME, $context));
}
return $argument->getAttribute('value');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Command/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->write($buffer);
}
});

return 0;
}
}
2 changes: 2 additions & 0 deletions src/Command/DevServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->write($buffer);
}
});

return 0;
}
}
Loading