From 5e0a9c24a6fc29ba68638aea294b11b3ebcb144d Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 24 Mar 2022 22:07:24 +1100 Subject: [PATCH] Roll back previous test commit. There were build errors that might best be resolved in another PR. --- lib/block-supports/spacing.php | 3 +- lib/load.php | 8 ++-- .../class-wp-style-engine-gutenberg.php | 38 +++++++++++++---- .../class-wp-style-engine-gutenberg-test.php | 3 +- tools/webpack/packages.js | 42 +++---------------- 5 files changed, 43 insertions(+), 51 deletions(-) rename packages/style-engine/class-wp-style-engine.php => lib/style-engine/class-wp-style-engine-gutenberg.php (80%) diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php index c23e58ca30e80c..bb24d3d7b052f0 100644 --- a/lib/block-supports/spacing.php +++ b/lib/block-supports/spacing.php @@ -51,10 +51,11 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) { return $attributes; } + $style_engine = WP_Style_Engine_Gutenberg::get_instance(); $spacing_block_styles = array(); $spacing_block_styles['padding'] = $has_padding_support ? _wp_array_get( $block_styles, array( 'spacing', 'padding' ), null ) : null; $spacing_block_styles['margin'] = $has_margin_support ? _wp_array_get( $block_styles, array( 'spacing', 'margin' ), null ) : null; - $inline_styles = WP_Style_Engine_Gutenberg::generate( + $inline_styles = $style_engine->generate( array( 'spacing' => $spacing_block_styles ), array( 'inline' => true, diff --git a/lib/load.php b/lib/load.php index 368d7b87117c9c..5d1933c16738e9 100644 --- a/lib/load.php +++ b/lib/load.php @@ -121,10 +121,10 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/global-styles.php'; require __DIR__ . '/pwa.php'; -// Copied package PHP files . -if ( file_exists( __DIR__ . '/style-engine/class-wp-style-engine-gutenberg.php' ) ) { - require __DIR__ . '/style-engine/class-wp-style-engine-gutenberg.php'; -} +// TODO: Before this PR merges, move this to be a part of the style engine package. +// Part of the build process should be to copy the PHP file to the correct location, +// similar to the loading behaviour in `blocks.php`. +require __DIR__ . '/style-engine/class-wp-style-engine-gutenberg.php'; require __DIR__ . '/block-supports/elements.php'; require __DIR__ . '/block-supports/colors.php'; diff --git a/packages/style-engine/class-wp-style-engine.php b/lib/style-engine/class-wp-style-engine-gutenberg.php similarity index 80% rename from packages/style-engine/class-wp-style-engine.php rename to lib/style-engine/class-wp-style-engine-gutenberg.php index 0b2770625fc062..d80ed2e0440e01 100644 --- a/packages/style-engine/class-wp-style-engine.php +++ b/lib/style-engine/class-wp-style-engine-gutenberg.php @@ -1,13 +1,13 @@ get_block_style_css_rules( $style_value, $options['path'] ) ); } else { // Otherwise build them all. foreach ( self::BLOCK_STYLE_DEFINITIONS_METADATA as $definition_group ) { @@ -104,7 +126,7 @@ public static function generate( $block_styles, $options = array() ) { if ( empty( $style_value ) ) { continue; } - $rules = array_merge( $rules, static::get_block_style_css_rules( $style_value, $style_definition['path'] ) ); + $rules = array_merge( $rules, $this->get_block_style_css_rules( $style_value, $style_definition['path'] ) ); } } } @@ -132,7 +154,7 @@ public static function generate( $block_styles, $options = array() ) { * * @return array The class name for the added style. */ - protected static function get_css_box_rules( $style_value, $style_property ) { + public static function get_css_box_rules( $style_value, $style_property ) { $rules = array(); if ( ! $style_value ) { diff --git a/phpunit/style-engine/class-wp-style-engine-gutenberg-test.php b/phpunit/style-engine/class-wp-style-engine-gutenberg-test.php index 3c422758e80bf6..a3e017d0b87444 100644 --- a/phpunit/style-engine/class-wp-style-engine-gutenberg-test.php +++ b/phpunit/style-engine/class-wp-style-engine-gutenberg-test.php @@ -16,7 +16,8 @@ class WP_Style_Engine_Gutenberg_Test extends WP_UnitTestCase { * @dataProvider data_block_styles_fixtures */ function test_generate_css( $block_styles, $options, $expected_output ) { - $generated_styles = WP_Style_Engine_Gutenberg::generate( + $style_engine = WP_Style_Engine_Gutenberg::get_instance(); + $generated_styles = $style_engine->generate( $block_styles, $options ); diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index b2781379159afe..4d02b4b6e2f817 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -26,15 +26,6 @@ const BUNDLED_PACKAGES = [ '@wordpress/style-engine', ]; -// PHP files in packages that have to be copied over to /lib. -const BUNDLED_PACKAGES_PHP = [ - { - from: './packages/style-engine/', - to: 'lib/style-engine/', - replaceClasses: [ 'WP_Style_Engine' ], - }, -]; - const gutenbergPackages = Object.keys( dependencies ) .filter( ( packageName ) => @@ -108,38 +99,15 @@ module.exports = { ...plugins, new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ), new CopyWebpackPlugin( { - patterns: [].concat( - gutenbergPackages.map( ( packageName ) => ( { + patterns: gutenbergPackages + .map( ( packageName ) => ( { from: '*.css', + context: `./packages/${ packageName }/build-style`, to: `./build/${ packageName }`, transform: stylesTransform, noErrorOnMissing: true, - } ) ), - // Packages with PHP files to be parsed and copied to ./lib. - BUNDLED_PACKAGES_PHP.map( - ( { from, to, replaceClasses } ) => ( { - from: `${ from }/*.php`, - to: ( { absoluteFilename } ) => { - const [ , filename ] = absoluteFilename.match( - /([\w-]+)(\.php){1,1}$/ - ); - return join( to, `${ filename }-gutenberg.php` ); - }, - transform: ( content ) => { - const classSuffix = '_Gutenberg'; - content = content.toString(); - // Replace class names. - content = content.replace( - new RegExp( replaceClasses.join( '|' ), 'g' ), - ( match ) => `${ match }${ classSuffix }` - ); - return content; - }, - noErrorOnMissing: true, - } ) - ), - vendorsCopyConfig - ), + } ) ) + .concat( vendorsCopyConfig ), } ), ].filter( Boolean ), };