diff --git a/assets.php b/assets.php index e6d15fb..6ba87e2 100644 --- a/assets.php +++ b/assets.php @@ -2,7 +2,7 @@ /** * Plugin Name: Assets * Description: Asset library with a plugin bootstrap file for automated testing. - * Version: 1.0.0 + * Version: 1.2.3 * Author: StellarWP * Author URI: https://stellarwp.com */ diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index 89346d4..8d3ad06 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -914,7 +914,7 @@ public function maybe_get_min_file( $url ) { // Strip the plugin URL and make this relative. $relative_location = str_replace( $base_url . '/', '', $url ); - if ( $script_debug ) { + if ( Config::should_ignore_script_debug() || $script_debug ) { // Add the actual url after having the min file added. $urls[] = $relative_location; } @@ -934,7 +934,7 @@ public function maybe_get_min_file( $url ) { } } - if ( ! $script_debug ) { + if ( Config::should_ignore_script_debug() || ! $script_debug ) { // Add the actual url after having the min file added. $urls[] = $relative_location; } diff --git a/src/Assets/Config.php b/src/Assets/Config.php index 2c521a2..6b804da 100644 --- a/src/Assets/Config.php +++ b/src/Assets/Config.php @@ -29,6 +29,13 @@ class Config { */ protected static array $path_urls = []; + /** + * Determine if we should ignore SCRIPT_DEBUG when including `.min` files in the asset loading. + * + * @var bool + */ + protected static bool $ignore_script_debug = false; + /** * Gets the hook prefix. * @@ -64,6 +71,15 @@ public static function get_relative_asset_path(): string { return static::$relative_asset_path; } + /** + * Gets wether this project shiuld ignore SCRIPT_DEBUG. + * + * @return bool + */ + public static function should_ignore_script_debug(): bool { + return static::$ignore_script_debug; + } + /** * Gets the root path of the project. * @@ -95,6 +111,8 @@ public static function reset() { static::$root_path = ''; static::$path_urls = []; static::$version = ''; + + static::set_ignore_script_debug( false ); } /** @@ -147,6 +165,17 @@ public static function set_path( string $path ) { static::$root_path = trailingslashit( $path ); } + /** + * Sets the ignore script debug of the project. + * + * @param bool $value The value to set for ignoring SCRIPT_DEBUG. + * + * @return void + */ + public static function set_ignore_script_debug( bool $value ) { + static::$ignore_script_debug = $value; + } + /** * Sets the version of the project. * diff --git a/tests/wpunit/AssetsTest.php b/tests/wpunit/AssetsTest.php index 9c2d638..375af2f 100644 --- a/tests/wpunit/AssetsTest.php +++ b/tests/wpunit/AssetsTest.php @@ -77,6 +77,20 @@ public function it_should_locate_minified_versions_of_external_assets() { } } + /** + * @test + */ + public function it_should_locate_minified_versions_of_external_assets() { + + Asset::add( 'fake3-script', 'fake3.js' )->register(); + + $this->assertTrue( Assets::init()->exists( 'fake3-script' ) ); + $this->assertTrue( wp_script_is( 'fake3-script', 'registered' ) ); + $this->assertEquals( 'fake3-script', Assets::init()->get( 'fake3-script' )->get_slug() ); + + $this->assert_minified_found( 'fake3', true, true, true ); + } + /** * @test */ diff --git a/tests/wpunit/ConfigTest.php b/tests/wpunit/ConfigTest.php index 871957f..0d94703 100644 --- a/tests/wpunit/ConfigTest.php +++ b/tests/wpunit/ConfigTest.php @@ -50,6 +50,15 @@ public function should_set_version() { $this->assertEquals( '1.1.0', Config::get_version() ); } + /** + * @test + */ + public function should_set_ignore_script_debug() { + Config::set_ignore_script_debug( true ); + + $this->assertTrue( Config::should_ignore_script_debug() ); + } + /** * @test */ @@ -58,10 +67,12 @@ public function should_reset() { Config::set_version( '1.1.0' ); Config::set_path( dirname( dirname( __DIR__ ) ) ); Config::set_relative_asset_path( 'src/resources/' ); + Config::set_ignore_script_debug( true ); Config::reset(); $this->assertEquals( 'src/assets/', Config::get_relative_asset_path() ); $this->assertEquals( '', Config::get_version() ); + $this->assertFalse( Config::should_ignore_script_debug() ); try { Config::get_hook_prefix();