diff --git a/plugins/woocommerce/src/Blocks/Assets/Api.php b/plugins/woocommerce/src/Blocks/Assets/Api.php index da8374c523a..40262192272 100644 --- a/plugins/woocommerce/src/Blocks/Assets/Api.php +++ b/plugins/woocommerce/src/Blocks/Assets/Api.php @@ -108,7 +108,7 @@ class Api { * @return string|boolean False if metadata file is not found for the block. */ public function get_block_metadata_path( $block_name, $path = '' ) { - $path_to_metadata_from_plugin_root = $this->package->get_path( 'build/' . $path . $block_name . '/block.json' ); + $path_to_metadata_from_plugin_root = $this->package->get_path( 'assets/client/blocks/' . $path . $block_name . '/block.json' ); if ( ! file_exists( $path_to_metadata_from_plugin_root ) ) { return false; } @@ -284,7 +284,7 @@ class Api { * @param boolean $rtl Optional. Whether or not to register RTL styles. */ public function register_style( $handle, $relative_src, $deps = [], $media = 'all', $rtl = false ) { - $filename = str_replace( plugins_url( '/', __DIR__ ), '', $relative_src ); + $filename = str_replace( plugins_url( '/', dirname( __DIR__ ) ), '', $relative_src ); $src = $this->get_asset_url( $relative_src ); $ver = $this->get_file_version( $filename ); wp_register_style( $handle, $src, $deps, $ver, $media ); @@ -302,7 +302,7 @@ class Api { * @return string The generated path. */ public function get_block_asset_build_path( $filename, $type = 'js' ) { - return "build/$filename.$type"; + return "assets/client/blocks/$filename.$type"; } /** diff --git a/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php b/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php index f8fed09cc26..4bc59e0b34e 100644 --- a/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php +++ b/plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php @@ -373,7 +373,7 @@ class AssetDataRegistry { public function register_data_script() { $this->api->register_script( $this->handle, - 'build/wc-settings.js', + 'assets/client/blocks/wc-settings.js', [ 'wp-api-fetch' ], true ); diff --git a/plugins/woocommerce/src/Blocks/AssetsController.php b/plugins/woocommerce/src/Blocks/AssetsController.php index 7e81b6e948a..2e95c5e3fcc 100644 --- a/plugins/woocommerce/src/Blocks/AssetsController.php +++ b/plugins/woocommerce/src/Blocks/AssetsController.php @@ -46,26 +46,26 @@ final class AssetsController { * Register block scripts & styles. */ public function register_assets() { - $this->register_style( 'wc-blocks-packages-style', plugins_url( $this->api->get_block_asset_build_path( 'packages-style', 'css' ), __DIR__ ), [], 'all', true ); - $this->register_style( 'wc-blocks-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks', 'css' ), __DIR__ ), [], 'all', true ); - $this->register_style( 'wc-blocks-editor-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks-editor-style', 'css' ), __DIR__ ), [ 'wp-edit-blocks' ], 'all', true ); + $this->register_style( 'wc-blocks-packages-style', plugins_url( $this->api->get_block_asset_build_path( 'packages-style', 'css' ), dirname( __DIR__ ) ), [], 'all', true ); + $this->register_style( 'wc-blocks-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks', 'css' ), dirname( __DIR__ ) ), [], 'all', true ); + $this->register_style( 'wc-blocks-editor-style', plugins_url( $this->api->get_block_asset_build_path( 'wc-blocks-editor-style', 'css' ), dirname( __DIR__ ) ), [ 'wp-edit-blocks' ], 'all', true ); - $this->api->register_script( 'wc-blocks-middleware', 'build/wc-blocks-middleware.js', [], false ); - $this->api->register_script( 'wc-blocks-data-store', 'build/wc-blocks-data.js', [ 'wc-blocks-middleware' ] ); + $this->api->register_script( 'wc-blocks-middleware', 'assets/client/blocks/wc-blocks-middleware.js', [], false ); + $this->api->register_script( 'wc-blocks-data-store', 'assets/client/blocks/wc-blocks-data.js', [ 'wc-blocks-middleware' ] ); $this->api->register_script( 'wc-blocks-vendors', $this->api->get_block_asset_build_path( 'wc-blocks-vendors' ), [], false ); - $this->api->register_script( 'wc-blocks-registry', 'build/wc-blocks-registry.js', [], false ); + $this->api->register_script( 'wc-blocks-registry', 'assets/client/blocks/wc-blocks-registry.js', [], false ); $this->api->register_script( 'wc-blocks', $this->api->get_block_asset_build_path( 'wc-blocks' ), [ 'wc-blocks-vendors' ], false ); - $this->api->register_script( 'wc-blocks-shared-context', 'build/wc-blocks-shared-context.js' ); - $this->api->register_script( 'wc-blocks-shared-hocs', 'build/wc-blocks-shared-hocs.js', [], false ); + $this->api->register_script( 'wc-blocks-shared-context', 'assets/client/blocks/wc-blocks-shared-context.js' ); + $this->api->register_script( 'wc-blocks-shared-hocs', 'assets/client/blocks/wc-blocks-shared-hocs.js', [], false ); // The price package is shared externally so has no blocks prefix. - $this->api->register_script( 'wc-price-format', 'build/price-format.js', [], false ); + $this->api->register_script( 'wc-price-format', 'assets/client/blocks/price-format.js', [], false ); - $this->api->register_script( 'wc-blocks-checkout', 'build/blocks-checkout.js', [] ); - $this->api->register_script( 'wc-blocks-components', 'build/blocks-components.js', [] ); + $this->api->register_script( 'wc-blocks-checkout', 'assets/client/blocks/blocks-checkout.js', [] ); + $this->api->register_script( 'wc-blocks-components', 'assets/client/blocks/blocks-components.js', [] ); // Register the interactivity components here for now. - $this->api->register_script( 'wc-interactivity-dropdown', 'build/wc-interactivity-dropdown.js', [] ); + $this->api->register_script( 'wc-interactivity-dropdown', 'assets/client/blocks/wc-interactivity-dropdown.js', [] ); wp_add_inline_script( 'wc-blocks-middleware', @@ -83,8 +83,8 @@ final class AssetsController { * Register and enqueue assets for exclusive usage within the Site Editor. */ public function register_and_enqueue_site_editor_assets() { - $this->api->register_script( 'wc-blocks-classic-template-revert-button', 'build/wc-blocks-classic-template-revert-button.js' ); - $this->api->register_style( 'wc-blocks-classic-template-revert-button-style', 'build/wc-blocks-classic-template-revert-button-style.css' ); + $this->api->register_script( 'wc-blocks-classic-template-revert-button', 'assets/client/blocks/wc-blocks-classic-template-revert-button.js' ); + $this->api->register_style( 'wc-blocks-classic-template-revert-button-style', 'assets/client/blocks/wc-blocks-classic-template-revert-button-style.css' ); $current_screen = get_current_screen(); if ( $current_screen instanceof \WP_Screen && 'site-editor' === $current_screen->base ) { @@ -290,7 +290,7 @@ final class AssetsController { * @param boolean $rtl Optional. Whether or not to register RTL styles. */ protected function register_style( $handle, $src, $deps = [], $media = 'all', $rtl = false ) { - $filename = str_replace( plugins_url( '/', __DIR__ ), '', $src ); + $filename = str_replace( plugins_url( '/', dirname( __DIR__ ) ), '', $src ); $ver = self::get_file_version( $filename ); wp_register_style( $handle, $src, $deps, $ver, $media ); diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php index 571a927ea7a..f89d97c21f8 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php @@ -180,7 +180,7 @@ abstract class AbstractBlock { * @return string[] $chunks list of chunks to load. */ protected function get_chunks_paths( $chunks_folder ) { - $build_path = \Automattic\WooCommerce\Blocks\Package::get_path() . 'build/'; + $build_path = \Automattic\WooCommerce\Blocks\Package::get_path() . 'assets/client/blocks/'; $blocks = []; if ( ! is_dir( $build_path . $chunks_folder ) ) { return []; diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php b/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php index ae929ee084d..27be4c70c1f 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php @@ -206,7 +206,7 @@ class MiniCart extends AbstractBlock { * Prints the variable containing information about the scripts to lazy load. */ public function print_lazy_load_scripts() { - $script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' ); + $script_data = $this->asset_api->get_script_data( 'assets/client/blocks/mini-cart-component-frontend.js' ); $num_dependencies = is_countable( $script_data['dependencies'] ) ? count( $script_data['dependencies'] ) : 0; $wp_scripts = wp_scripts(); @@ -261,7 +261,7 @@ class MiniCart extends AbstractBlock { ); } foreach ( $inner_blocks_frontend_scripts as $inner_block_frontend_script ) { - $script_data = $this->asset_api->get_script_data( 'build/mini-cart-contents-block/' . $inner_block_frontend_script . '.js' ); + $script_data = $this->asset_api->get_script_data( 'assets/client/blocks/mini-cart-contents-block/' . $inner_block_frontend_script . '.js' ); $this->scripts_to_lazy_load[ 'wc-block-' . $inner_block_frontend_script ] = array( 'src' => $script_data['src'], 'version' => $script_data['version'], diff --git a/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php b/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php index a255178ed57..d37d40cd6c8 100644 --- a/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php +++ b/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php @@ -166,7 +166,7 @@ class Bootstrap { */ protected function is_built() { return file_exists( - $this->package->get_path( 'build/featured-product.js' ) + $this->package->get_path( 'assets/client/blocks/featured-product.js' ) ); } diff --git a/plugins/woocommerce/src/Blocks/Domain/Services/GoogleAnalytics.php b/plugins/woocommerce/src/Blocks/Domain/Services/GoogleAnalytics.php index 1123cd52016..91e297836b3 100644 --- a/plugins/woocommerce/src/Blocks/Domain/Services/GoogleAnalytics.php +++ b/plugins/woocommerce/src/Blocks/Domain/Services/GoogleAnalytics.php @@ -41,7 +41,7 @@ class GoogleAnalytics { * Register scripts. */ public function register_assets() { - $this->asset_api->register_script( 'wc-blocks-google-analytics', 'build/wc-blocks-google-analytics.js', [ 'google-tag-manager' ] ); + $this->asset_api->register_script( 'wc-blocks-google-analytics', 'assets/client/blocks/wc-blocks-google-analytics.js', [ 'google-tag-manager' ] ); } /** diff --git a/plugins/woocommerce/src/Blocks/Interactivity/scripts.php b/plugins/woocommerce/src/Blocks/Interactivity/scripts.php index 7b48834807c..4da1cd57cb9 100644 --- a/plugins/woocommerce/src/Blocks/Interactivity/scripts.php +++ b/plugins/woocommerce/src/Blocks/Interactivity/scripts.php @@ -28,7 +28,7 @@ function woocommerce_interactivity_register_runtime() { $plugin_path = \Automattic\WooCommerce\Blocks\Package::get_path(); $plugin_url = plugin_dir_url( $plugin_path . '/index.php' ); - $file = 'build/wc-interactivity.js'; + $file = 'assets/client/blocks/wc-interactivity.js'; $file_path = $plugin_path . $file; $file_url = $plugin_url . $file; diff --git a/plugins/woocommerce/src/Blocks/Payments/Integrations/BankTransfer.php b/plugins/woocommerce/src/Blocks/Payments/Integrations/BankTransfer.php index 8572fdbc2e0..af8c867096d 100644 --- a/plugins/woocommerce/src/Blocks/Payments/Integrations/BankTransfer.php +++ b/plugins/woocommerce/src/Blocks/Payments/Integrations/BankTransfer.php @@ -56,7 +56,7 @@ final class BankTransfer extends AbstractPaymentMethodType { public function get_payment_method_script_handles() { $this->asset_api->register_script( 'wc-payment-method-bacs', - 'build/wc-payment-method-bacs.js' + 'assets/client/blocks/wc-payment-method-bacs.js' ); return [ 'wc-payment-method-bacs' ]; } diff --git a/plugins/woocommerce/src/Blocks/Payments/Integrations/CashOnDelivery.php b/plugins/woocommerce/src/Blocks/Payments/Integrations/CashOnDelivery.php index 5822732464e..c01e9c8a483 100644 --- a/plugins/woocommerce/src/Blocks/Payments/Integrations/CashOnDelivery.php +++ b/plugins/woocommerce/src/Blocks/Payments/Integrations/CashOnDelivery.php @@ -79,7 +79,7 @@ final class CashOnDelivery extends AbstractPaymentMethodType { public function get_payment_method_script_handles() { $this->asset_api->register_script( 'wc-payment-method-cod', - 'build/wc-payment-method-cod.js' + 'assets/client/blocks/wc-payment-method-cod.js' ); return [ 'wc-payment-method-cod' ]; } diff --git a/plugins/woocommerce/src/Blocks/Payments/Integrations/Cheque.php b/plugins/woocommerce/src/Blocks/Payments/Integrations/Cheque.php index 318f6c84b44..76b8339c3aa 100644 --- a/plugins/woocommerce/src/Blocks/Payments/Integrations/Cheque.php +++ b/plugins/woocommerce/src/Blocks/Payments/Integrations/Cheque.php @@ -57,7 +57,7 @@ final class Cheque extends AbstractPaymentMethodType { public function get_payment_method_script_handles() { $this->asset_api->register_script( 'wc-payment-method-cheque', - 'build/wc-payment-method-cheque.js' + 'assets/client/blocks/wc-payment-method-cheque.js' ); return [ 'wc-payment-method-cheque' ]; } diff --git a/plugins/woocommerce/src/Blocks/Payments/Integrations/PayPal.php b/plugins/woocommerce/src/Blocks/Payments/Integrations/PayPal.php index 6becf7f81f3..21893647654 100644 --- a/plugins/woocommerce/src/Blocks/Payments/Integrations/PayPal.php +++ b/plugins/woocommerce/src/Blocks/Payments/Integrations/PayPal.php @@ -57,7 +57,7 @@ final class PayPal extends AbstractPaymentMethodType { public function get_payment_method_script_handles() { $this->asset_api->register_script( 'wc-payment-method-paypal', - 'build/wc-payment-method-paypal.js' + 'assets/client/blocks/wc-payment-method-paypal.js' ); return [ 'wc-payment-method-paypal' ]; } diff --git a/plugins/woocommerce/src/Blocks/Shipping/ShippingController.php b/plugins/woocommerce/src/Blocks/Shipping/ShippingController.php index a931b2881a3..087fa10315d 100644 --- a/plugins/woocommerce/src/Blocks/Shipping/ShippingController.php +++ b/plugins/woocommerce/src/Blocks/Shipping/ShippingController.php @@ -349,7 +349,7 @@ class ShippingController { * Load admin scripts. */ public function admin_scripts() { - $this->asset_api->register_script( 'wc-shipping-method-pickup-location', 'build/wc-shipping-method-pickup-location.js', [], true ); + $this->asset_api->register_script( 'wc-shipping-method-pickup-location', 'assets/client/blocks/wc-shipping-method-pickup-location.js', [], true ); } /** diff --git a/plugins/woocommerce/tests/php/src/Blocks/Domain/Package.php b/plugins/woocommerce/tests/php/src/Blocks/Domain/Package.php index 9bee03319ab..0849bb289b6 100644 --- a/plugins/woocommerce/tests/php/src/Blocks/Domain/Package.php +++ b/plugins/woocommerce/tests/php/src/Blocks/Domain/Package.php @@ -27,8 +27,8 @@ class Package extends WP_UnitTestCase { $this->assertEquals( __DIR__ . '/', $package->get_path() ); //test with relative - $expect = __DIR__ . '/build/test'; - $this->assertEquals( $expect, $package->get_path( 'build/test') ); + $expect = __DIR__ . '/assets/client/blocks/test'; + $this->assertEquals( $expect, $package->get_path( 'assets/client/blocks/test') ); } public function test_get_url() { @@ -39,8 +39,8 @@ class Package extends WP_UnitTestCase { //test with relative $this->assertEquals( - $test_url . 'build/test', - $package->get_url( 'build/test' ) + $test_url . 'assets/client/blocks', + $package->get_url( 'assets/client/blocks' ) ); } }