From 6c00109bca44cd226fd6f534b28dfb2884fbfd46 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Thu, 10 Feb 2022 12:53:54 +0700 Subject: [PATCH 01/12] Update composer.json to allow newer version mrclay/minify (#165) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c2ac9f4..986e32a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "mrclay/minify": "^2.2" + "mrclay/minify": "^2.2|^3.0" }, "require-dev": { "graham-campbell/testbench": "^3.1|^4.0|^5.0", From 79d5af0a03763eb866d7ebf23f3a0339e6e8fe3c Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Thu, 10 Feb 2022 06:56:24 +0100 Subject: [PATCH 02/12] Support Laravel 9 (#167) --- composer.json | 14 +++++++------- phpunit.xml.dist | 12 +++++++----- tests/AbstractTestCase.php | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 986e32a..f4c21a8 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,18 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", "mrclay/minify": "^2.2|^3.0" }, "require-dev": { "graham-campbell/testbench": "^3.1|^4.0|^5.0", "mockery/mockery": "^0.9.4|^1.0", - "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0" + "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 986bc30..bd51815 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,7 @@ -./tests - - + + ./src - - + + diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 2a1cd4d..cd75a82 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -29,7 +29,7 @@ abstract class AbstractTestCase extends AbstractPackageTestCase * * @return string */ - protected function getServiceProviderClass($app) + protected function getServiceProviderClass() { return HTMLMinServiceProvider::class; } From a5531cc9e5c0b97b3a416cb6fcaaab9f5d9cc95b Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 11:43:15 +0500 Subject: [PATCH 03/12] Use Github Actions. --- .github/workflows/tests.yml | 35 +++++++++++++++++++++++++++++++++++ src/Minifiers/JsMinifier.php | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a9ccf30 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,35 @@ +name: HTMLMinTests +on: [push, pull_request] +jobs: + htmlmin: + name: PHP ${{ matrix.php-versions }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP with Composer and extensions + with: + php-version: ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + - name: Get Composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + php-version: ${{ matrix.php-versions }} + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + env: + PHP_VERSION: ${{ matrix.php-versions }} + run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) + - name: Run tests with code coverage + env: + PHP_VERSION: ${{ matrix.php-versions }} + run: vendor/bin/phpunit $(if [ "$PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.dist.php72"; fi;) --coverage-clover build/logs/clover.xml diff --git a/src/Minifiers/JsMinifier.php b/src/Minifiers/JsMinifier.php index df30c7c..66ec879 100644 --- a/src/Minifiers/JsMinifier.php +++ b/src/Minifiers/JsMinifier.php @@ -12,7 +12,7 @@ namespace HTMLMin\HTMLMin\Minifiers; -use JSMin; +use JSMin\JSMin; /** * This is the js minifier class. From e8ab07a19fc79f041aef25002b86e6af6bd7fe9b Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 11:45:58 +0500 Subject: [PATCH 04/12] Fix build for PHP 7.2 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9ccf30..74c961d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,4 +32,4 @@ jobs: - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} - run: vendor/bin/phpunit $(if [ "$PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.dist.php72"; fi;) --coverage-clover build/logs/clover.xml + run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml From 678b9597fe69c0e2a3539582220b07c022bde8ab Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 12:08:56 +0500 Subject: [PATCH 05/12] Fix builds --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 74c961d..d59d14e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] steps: - name: Checkout uses: actions/checkout@v2 From b23349bb8fc3b15d256f56c78a6e484efe0a12de Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 14:45:30 +0500 Subject: [PATCH 06/12] Avoid resolving view when retrieving the previous compiler (Resolves #162). --- src/HTMLMinServiceProvider.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/HTMLMinServiceProvider.php b/src/HTMLMinServiceProvider.php index 0dd2ac4..8a78f4e 100644 --- a/src/HTMLMinServiceProvider.php +++ b/src/HTMLMinServiceProvider.php @@ -30,6 +30,11 @@ */ class HTMLMinServiceProvider extends ServiceProvider { + /** + * @var \Illuminate\View\Compilers\CompilerInterface|null + */ + protected $previousCompiler; + /** * Boot the service provider. * @@ -164,18 +169,22 @@ protected function registerBladeMinifier() */ protected function registerMinifyCompiler() { - $previousCompiler = $this->app->make('view') - ->getEngineResolver() - ->resolve('blade') - ->getCompiler(); + if (method_exists($this, 'callAfterResolving')) { + $this->callAfterResolving('view', function () { + $this->previousCompiler = $this->app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + }); + } - $this->app->singleton('htmlmin.compiler', function (Container $app) use ($previousCompiler) { + $this->app->singleton('htmlmin.compiler', function (Container $app) { $blade = $app['htmlmin.blade']; $files = $app['files']; $storagePath = $app->config->get('view.compiled'); $ignoredPaths = $app->config->get('htmlmin.ignore', []); - return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $previousCompiler); + return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler); }); $this->app->alias('htmlmin.compiler', MinifyCompiler::class); From 59c3297a8ce7d9b173c5262be4a786176fdc438d Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 14:54:47 +0500 Subject: [PATCH 07/12] Allow failures in build. --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d59d14e..46a0dd9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] steps: - name: Checkout uses: actions/checkout@v2 @@ -33,3 +33,4 @@ jobs: env: PHP_VERSION: ${{ matrix.php-versions }} run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml + continue-on-error: true From abbd504e58822d002609ad515497f1760454fcf3 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 15:14:10 +0500 Subject: [PATCH 08/12] Update badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 472c805..258792f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Laravel HTMLMin Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmklive), and is a simple HTML minifier for [Laravel](http://laravel.com). It utilises Mr Clay's [Minify](https://github.com/mrclay/minify) package to minify entire responses, but can also minify blade at compile time. Feel free to check out the [change log](CHANGELOG.md), [releases](https://github.com/HTMLMin/Laravel-HTMLMin/releases), [license](LICENSE), and [contribution guidelines](CONTRIBUTING.md).

-Build Status +Tests Software License Latest Version

From 2b112875f5f5c994907a82ea6d746de597e23be1 Mon Sep 17 00:00:00 2001 From: Scott Bedard Date: Wed, 10 Aug 2022 22:59:35 -0500 Subject: [PATCH 09/12] Update README (#168) --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 258792f..7194a4c 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,21 @@ To get the latest version, simply require the project using [Composer](https://g $ composer require htmlmin/htmlmin ``` -Once installed, you need to register the `HTMLMin\HTMLMin\HTMLMinServiceProvider` service provider in your `config/app.php`, and optionally alias our facade: +Once installed, register the service provider in your `config/app.php` ```php - 'HTMLMin' => HTMLMin\HTMLMin\Facades\HTMLMin::class, +'providers' => [ + HTMLMin\HTMLMin\HTMLMinServiceProvider::class +] ``` +If you want, a facade is available to alias + +```php +'aliases' => [ + 'HTMLMin' => HTMLMin\HTMLMin\Facades\HTMLMin::class +] +``` ## Configuration From 09b9cb44a113854cbe1f55e37fb98879e1417d49 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 11 Aug 2022 09:25:33 +0500 Subject: [PATCH 10/12] Fix #144 and tests for PHP 5.6 & 7.0. --- .github/workflows/tests.yml | 2 +- src/Compilers/MinifyCompiler.php | 10 +++++++++- src/HTMLMinServiceProvider.php | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 46a0dd9..fbaaae2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install Composer dependencies env: PHP_VERSION: ${{ matrix.php-versions }} - run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) + run: $(if [ "$PHP_VERSION" == "5.6" || "$PHP_VERSION" == "7.0" ]; then echo "composer config --no-plugins allow-plugins.kylekatarnls/update-helper true &&"; fi;) composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} diff --git a/src/Compilers/MinifyCompiler.php b/src/Compilers/MinifyCompiler.php index 54a898c..c0164ba 100644 --- a/src/Compilers/MinifyCompiler.php +++ b/src/Compilers/MinifyCompiler.php @@ -49,6 +49,7 @@ class MinifyCompiler extends BladeCompiler * @param string $cachePath * @param array $ignoredPaths * @param \Illuminate\View\Compilers\BladeCompiler $previousCompiler + * @param array $customDirectives * * @return void */ @@ -57,13 +58,20 @@ public function __construct( Filesystem $files, $cachePath, $ignoredPaths = [], - $previousCompiler = null + $previousCompiler = null, + $customDirectives = [] ) { parent::__construct($files, $cachePath); $this->blade = $blade; $this->ignoredPaths = $ignoredPaths; $this->compilers[] = 'Minify'; $this->previousCompiler = $previousCompiler; + + if (count($customDirectives)) { + foreach ($customDirectives as $key => $value) { + $this->directive($key, $value); + } + } } /** diff --git a/src/HTMLMinServiceProvider.php b/src/HTMLMinServiceProvider.php index 8a78f4e..7eed413 100644 --- a/src/HTMLMinServiceProvider.php +++ b/src/HTMLMinServiceProvider.php @@ -184,7 +184,7 @@ protected function registerMinifyCompiler() $storagePath = $app->config->get('view.compiled'); $ignoredPaths = $app->config->get('htmlmin.ignore', []); - return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler); + return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler, $this->previousCompiler->getCustomDirectives()); }); $this->app->alias('htmlmin.compiler', MinifyCompiler::class); From b628c87d1a6c9eac6a119f36ca1cdd577392abd2 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 11 Aug 2022 09:31:03 +0500 Subject: [PATCH 11/12] Allow plugin. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fbaaae2..019bb8a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install Composer dependencies env: PHP_VERSION: ${{ matrix.php-versions }} - run: $(if [ "$PHP_VERSION" == "5.6" || "$PHP_VERSION" == "7.0" ]; then echo "composer config --no-plugins allow-plugins.kylekatarnls/update-helper true &&"; fi;) composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) + run: composer config --no-plugins allow-plugins.kylekatarnls/update-helper true && composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} From 347d5776b321b8d6bf9fd0285984dcd1d2589f3f Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Tue, 14 Feb 2023 00:44:53 +0500 Subject: [PATCH 12/12] Laravel 10 compatibility --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f4c21a8..a686cac 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", "mrclay/minify": "^2.2|^3.0" }, "require-dev": {