Fixed Blocks Asset Paths

This commit is contained in:
Christopher Allford 2023-12-09 21:15:57 -08:00
parent 386d0db969
commit 25d42b0c05
14 changed files with 34 additions and 34 deletions

View File

@ -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";
}
/**

View File

@ -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
);

View File

@ -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 );

View File

@ -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 [];

View File

@ -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'],

View File

@ -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' )
);
}

View File

@ -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' ] );
}
/**

View File

@ -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;

View File

@ -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' ];
}

View File

@ -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' ];
}

View File

@ -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' ];
}

View File

@ -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' ];
}

View File

@ -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 );
}
/**

View File

@ -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' )
);
}
}