@wordpress/build 0.9.0 → 0.10.1-next.v.202603102151.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,57 +32,61 @@ foreach ( $routes_by_page as $page_slug => $page_routes ) {
32
32
  $GLOBALS[ $global_name ] = $page_routes;
33
33
  }
34
34
 
35
- if ( ! function_exists( '{{PREFIX}}_register_page_routes' ) ) {
36
- /**
37
- * Generic helper function to register routes for a page.
38
- *
39
- * @param array $page_routes Array of route data for the page.
40
- * @param string $register_function_name Name of the function to call for registering each route.
41
- */
42
- function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name ) {
43
- // Load build constants
44
- $build_constants = require __DIR__ . '/constants.php';
35
+ /**
36
+ * Generic helper function to register routes for a page.
37
+ *
38
+ * @param array $page_routes Array of route data for the page.
39
+ * @param string $register_function_name Name of the function to call for registering each route.
40
+ */
41
+ function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name ) {
42
+ // Load build constants
43
+ $build_constants = require __DIR__ . '/constants.php';
45
44
 
46
- foreach ( $page_routes as $route ) {
47
- $content_handle = null;
48
- $route_handle = null;
45
+ foreach ( $page_routes as $route ) {
46
+ $content_handle = null;
47
+ $route_handle = null;
49
48
 
50
- // Register content module if exists
51
- if ( $route['has_content'] ) {
52
- $content_asset_path = __DIR__ . "/routes/{$route['name']}/content.min.asset.php";
53
- if ( file_exists( $content_asset_path ) ) {
54
- $content_asset = require $content_asset_path;
55
- $content_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/content';
56
- $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
57
- wp_register_script_module(
58
- $content_handle,
59
- $build_constants['build_url'] . 'routes/' . $route['name'] . '/content' . $extension,
60
- $content_asset['module_dependencies'] ?? array(),
61
- $content_asset['version'] ?? false
62
- );
63
- }
49
+ // Register content module if exists
50
+ if ( $route['has_content'] ) {
51
+ $content_asset_path = __DIR__ . "/routes/{$route['name']}/content.min.asset.php";
52
+ if ( file_exists( $content_asset_path ) ) {
53
+ $content_asset = require $content_asset_path;
54
+ $content_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/content';
55
+ $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
56
+ // Deregister first to override any previously registered version
57
+ // (e.g., Core's default modules when running as a plugin).
58
+ wp_deregister_script_module( $content_handle );
59
+ wp_register_script_module(
60
+ $content_handle,
61
+ $build_constants['build_url'] . 'routes/' . $route['name'] . '/content' . $extension,
62
+ $content_asset['module_dependencies'] ?? array(),
63
+ $content_asset['version'] ?? false
64
+ );
64
65
  }
66
+ }
65
67
 
66
- // Register route module if exists
67
- if ( $route['has_route'] ) {
68
- $route_asset_path = __DIR__ . "/routes/{$route['name']}/route.min.asset.php";
69
- if ( file_exists( $route_asset_path ) ) {
70
- $route_asset = require $route_asset_path;
71
- $route_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/route';
72
- $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
73
- wp_register_script_module(
74
- $route_handle,
75
- $build_constants['build_url'] . 'routes/' . $route['name'] . '/route' . $extension,
76
- $route_asset['module_dependencies'] ?? array(),
77
- $route_asset['version'] ?? false
78
- );
79
- }
68
+ // Register route module if exists
69
+ if ( $route['has_route'] ) {
70
+ $route_asset_path = __DIR__ . "/routes/{$route['name']}/route.min.asset.php";
71
+ if ( file_exists( $route_asset_path ) ) {
72
+ $route_asset = require $route_asset_path;
73
+ $route_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/route';
74
+ $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
75
+ // Deregister first to override any previously registered version
76
+ // (e.g., Core's default modules when running as a plugin).
77
+ wp_deregister_script_module( $route_handle );
78
+ wp_register_script_module(
79
+ $route_handle,
80
+ $build_constants['build_url'] . 'routes/' . $route['name'] . '/route' . $extension,
81
+ $route_asset['module_dependencies'] ?? array(),
82
+ $route_asset['version'] ?? false
83
+ );
80
84
  }
85
+ }
81
86
 
82
- // Register route with page
83
- if ( function_exists( $register_function_name ) ) {
84
- call_user_func( $register_function_name, $route['path'], $content_handle, $route_handle );
85
- }
87
+ // Register route with page
88
+ if ( function_exists( $register_function_name ) ) {
89
+ call_user_func( $register_function_name, $route['path'], $content_handle, $route_handle );
86
90
  }
87
91
  }
88
92
  }
@@ -6,84 +6,80 @@
6
6
  * @package {{PREFIX}}
7
7
  */
8
8
 
9
- if ( ! function_exists( '{{PREFIX}}_override_script' ) ) {
10
- /**
11
- * Registers a script according to `wp_register_script`. Honors this request by
12
- * reassigning internal dependency properties of any script handle already
13
- * registered by that name. It does not deregister the original script, to
14
- * avoid losing inline scripts which may have been attached.
15
- *
16
- * @param WP_Scripts $scripts WP_Scripts instance.
17
- * @param string $handle Name of the script. Should be unique.
18
- * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
19
- * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
20
- * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
21
- * as a query string for cache busting purposes. If version is set to false, a version
22
- * number is automatically added equal to current installed WordPress version.
23
- * If set to null, no version is added.
24
- * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
25
- * Default 'false'.
26
- */
27
- function {{PREFIX}}_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
28
- $script = $scripts->query( $handle, 'registered' );
29
- if ( $script ) {
30
- /*
31
- * In many ways, this is a reimplementation of `wp_register_script` but
32
- * bypassing consideration of whether a script by the given handle had
33
- * already been registered.
34
- */
9
+ /**
10
+ * Registers a script according to `wp_register_script`. Honors this request by
11
+ * reassigning internal dependency properties of any script handle already
12
+ * registered by that name. It does not deregister the original script, to
13
+ * avoid losing inline scripts which may have been attached.
14
+ *
15
+ * @param WP_Scripts $scripts WP_Scripts instance.
16
+ * @param string $handle Name of the script. Should be unique.
17
+ * @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
18
+ * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
19
+ * @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
20
+ * as a query string for cache busting purposes. If version is set to false, a version
21
+ * number is automatically added equal to current installed WordPress version.
22
+ * If set to null, no version is added.
23
+ * @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
24
+ * Default 'false'.
25
+ */
26
+ function {{PREFIX}}_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
27
+ $script = $scripts->query( $handle, 'registered' );
28
+ if ( $script ) {
29
+ /*
30
+ * In many ways, this is a reimplementation of `wp_register_script` but
31
+ * bypassing consideration of whether a script by the given handle had
32
+ * already been registered.
33
+ */
35
34
 
36
- // See: `_WP_Dependency::__construct` .
37
- $script->src = $src;
38
- $script->deps = $deps;
39
- $script->ver = $ver;
40
- $script->args = $in_footer ? 1 : null;
41
- } else {
42
- $scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) );
43
- }
35
+ // See: `_WP_Dependency::__construct` .
36
+ $script->src = $src;
37
+ $script->deps = $deps;
38
+ $script->ver = $ver;
39
+ $script->args = $in_footer ? 1 : null;
40
+ } else {
41
+ $scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) );
42
+ }
44
43
 
45
- if ( in_array( 'wp-i18n', $deps, true ) ) {
46
- $scripts->set_translations( $handle );
47
- }
44
+ if ( in_array( 'wp-i18n', $deps, true ) ) {
45
+ $scripts->set_translations( $handle );
48
46
  }
49
47
  }
50
48
 
51
- if ( ! function_exists( '{{PREFIX}}_register_package_scripts' ) ) {
52
- /**
53
- * Register all package scripts.
54
- */
55
- function {{PREFIX}}_register_package_scripts( $scripts ) {
56
- // Load build constants
57
- $build_constants = require __DIR__ . '/constants.php';
58
- $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
59
- $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
49
+ /**
50
+ * Register all package scripts.
51
+ */
52
+ function {{PREFIX}}_register_package_scripts( $scripts ) {
53
+ // Load build constants
54
+ $build_constants = require __DIR__ . '/constants.php';
55
+ $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
56
+ $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
60
57
 
61
- $scripts_dir = __DIR__ . '/scripts';
62
- $scripts_file = $scripts_dir . '/registry.php';
58
+ $scripts_dir = __DIR__ . '/scripts';
59
+ $scripts_file = $scripts_dir . '/registry.php';
63
60
 
64
- if ( ! file_exists( $scripts_file ) ) {
65
- return;
66
- }
61
+ if ( ! file_exists( $scripts_file ) ) {
62
+ return;
63
+ }
67
64
 
68
- $scripts_data = require $scripts_file;
69
- $plugin_dir = dirname( __FILE__ );
65
+ $scripts_data = require $scripts_file;
66
+ $plugin_dir = dirname( __FILE__ );
70
67
 
71
- foreach ( $scripts_data as $script_data ) {
72
- $asset_file = $scripts_dir . '/' . $script_data['asset'];
73
- $asset = file_exists( $asset_file ) ? require $asset_file : array();
74
- $dependencies = $asset['dependencies'] ?? array();
75
- $version = $asset['version'] ?? $default_version;
68
+ foreach ( $scripts_data as $script_data ) {
69
+ $asset_file = $scripts_dir . '/' . $script_data['asset'];
70
+ $asset = file_exists( $asset_file ) ? require $asset_file : array();
71
+ $dependencies = $asset['dependencies'] ?? array();
72
+ $version = $asset['version'] ?? $default_version;
76
73
 
77
- {{PREFIX}}_override_script(
78
- $scripts,
79
- $script_data['handle'],
80
- $build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension,
81
- $dependencies,
82
- $version,
83
- true
84
- );
85
- }
74
+ {{PREFIX}}_override_script(
75
+ $scripts,
76
+ $script_data['handle'],
77
+ $build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension,
78
+ $dependencies,
79
+ $version,
80
+ true
81
+ );
86
82
  }
87
-
88
- add_action( 'wp_default_scripts', '{{PREFIX}}_register_package_scripts' );
89
83
  }
84
+
85
+ add_action( 'wp_default_scripts', '{{PREFIX}}_register_package_scripts' );
@@ -9,69 +9,65 @@
9
9
  * @package {{PREFIX}}
10
10
  */
11
11
 
12
- if ( ! function_exists( '{{PREFIX}}_override_style' ) ) {
13
- /**
14
- * Registers a style according to `wp_register_style`. Honors this request by
15
- * deregistering any style by the same handler before registration.
16
- *
17
- * @param WP_Styles $styles WP_Styles instance.
18
- * @param string $handle Name of the stylesheet. Should be unique.
19
- * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
20
- * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
21
- * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
22
- * as a query string for cache busting purposes. If version is set to false, a version
23
- * number is automatically added equal to current installed WordPress version.
24
- * If set to null, no version is added.
25
- * @param string $media Optional. The media for which this stylesheet has been defined.
26
- * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
27
- * '(orientation: portrait)' and '(max-width: 640px)'.
28
- */
29
- function {{PREFIX}}_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
30
- $style = $styles->query( $handle, 'registered' );
31
- if ( $style ) {
32
- $styles->remove( $handle );
33
- }
34
- $styles->add( $handle, $src, $deps, $ver, $media );
12
+ /**
13
+ * Registers a style according to `wp_register_style`. Honors this request by
14
+ * deregistering any style by the same handler before registration.
15
+ *
16
+ * @param WP_Styles $styles WP_Styles instance.
17
+ * @param string $handle Name of the stylesheet. Should be unique.
18
+ * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
19
+ * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
20
+ * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
21
+ * as a query string for cache busting purposes. If version is set to false, a version
22
+ * number is automatically added equal to current installed WordPress version.
23
+ * If set to null, no version is added.
24
+ * @param string $media Optional. The media for which this stylesheet has been defined.
25
+ * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
26
+ * '(orientation: portrait)' and '(max-width: 640px)'.
27
+ */
28
+ function {{PREFIX}}_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
29
+ $style = $styles->query( $handle, 'registered' );
30
+ if ( $style ) {
31
+ $styles->remove( $handle );
35
32
  }
33
+ $styles->add( $handle, $src, $deps, $ver, $media );
36
34
  }
37
35
 
38
- if ( ! function_exists( '{{PREFIX}}_register_package_styles' ) ) {
39
- /**
40
- * Register all package styles (simple cases only).
41
- * Complex cases should be manually registered in lib/client-assets.php.
42
- *
43
- * @param WP_Styles $styles WP_Styles instance.
44
- */
45
- function {{PREFIX}}_register_package_styles( $styles ) {
46
- // Load build constants
47
- $build_constants = require __DIR__ . '/constants.php';
48
- $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
49
- $suffix = SCRIPT_DEBUG ? '' : '.min';
36
+ /**
37
+ * Register all package styles (simple cases only).
38
+ * Complex cases should be manually registered in lib/client-assets.php.
39
+ *
40
+ * @param WP_Styles $styles WP_Styles instance.
41
+ */
42
+ function {{PREFIX}}_register_package_styles( $styles ) {
43
+ // Load build constants
44
+ $build_constants = require __DIR__ . '/constants.php';
45
+ $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
46
+ $suffix = SCRIPT_DEBUG ? '' : '.min';
50
47
 
51
- $styles_dir = __DIR__ . '/styles';
52
- $styles_file = $styles_dir . '/registry.php';
48
+ $styles_dir = __DIR__ . '/styles';
49
+ $styles_file = $styles_dir . '/registry.php';
53
50
 
54
- if ( ! file_exists( $styles_file ) ) {
55
- return;
56
- }
51
+ if ( ! file_exists( $styles_file ) ) {
52
+ return;
53
+ }
57
54
 
58
- $styles_data = require $styles_file;
59
- $plugin_dir = dirname( __FILE__ );
55
+ $styles_data = require $styles_file;
56
+ $plugin_dir = dirname( __FILE__ );
60
57
 
61
- foreach ( $styles_data as $style_data ) {
62
- {{PREFIX}}_override_style(
63
- $styles,
64
- $style_data['handle'],
65
- $build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css',
66
- $style_data['dependencies'],
67
- $default_version
68
- );
58
+ foreach ( $styles_data as $style_data ) {
59
+ {{PREFIX}}_override_style(
60
+ $styles,
61
+ $style_data['handle'],
62
+ $build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css',
63
+ $style_data['dependencies'],
64
+ $default_version
65
+ );
69
66
 
70
- // Enable RTL support (WordPress automatically loads -rtl.css variant)
71
- $styles->add_data( $style_data['handle'], 'rtl', 'replace' );
72
- $styles->add_data( $style_data['handle'], 'suffix', $suffix );
73
- }
67
+ // Enable RTL support (WordPress automatically loads -rtl.css variant)
68
+ $styles->add_data( $style_data['handle'], 'rtl', 'replace' );
69
+ $styles->add_data( $style_data['handle'], 'suffix', $suffix );
74
70
  }
75
-
76
- add_action( 'wp_default_styles', '{{PREFIX}}_register_package_styles' );
77
71
  }
72
+
73
+ add_action( 'wp_default_styles', '{{PREFIX}}_register_package_styles' );