@wordpress/build 0.5.0 → 0.5.1-next.06ee73755.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.
- package/.cache/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +0 -2
- package/LICENSE.md +1 -1
- package/README.md +47 -5
- package/{src → lib}/build.mjs +272 -137
- package/{src → lib}/dependency-graph.mjs +36 -110
- package/{src → lib}/package-utils.mjs +45 -10
- package/{src → lib}/php-generator.mjs +5 -6
- package/{src → lib}/route-utils.mjs +13 -4
- package/{src → lib}/wordpress-externals-plugin.mjs +77 -15
- package/package.json +11 -8
- package/templates/constants.php.template +14 -0
- package/templates/index.php.template +0 -6
- package/templates/module-registration.php.template +3 -1
- package/templates/page-wp-admin.php.template +68 -28
- package/templates/page.php.template +13 -4
- package/templates/routes-registration.php.template +4 -2
- package/templates/script-registration.php.template +4 -2
- package/templates/style-registration.php.template +6 -2
- package/tsconfig.json +1 -1
- package/templates/version.php.template +0 -11
|
@@ -128,11 +128,22 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' ) )
|
|
|
128
128
|
* @param string $hook_suffix The current admin page.
|
|
129
129
|
*/
|
|
130
130
|
function {{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suffix ) {
|
|
131
|
-
//
|
|
132
|
-
|
|
131
|
+
// Check all possible ways this page can be accessed:
|
|
132
|
+
// 1. Menu page via admin.php?page={{PAGE_SLUG}}-wp-admin (plugin)
|
|
133
|
+
// 2. Direct file via {{PAGE_SLUG}}.php (Core) - screen ID will be '{{PAGE_SLUG}}'
|
|
134
|
+
$current_screen = get_current_screen();
|
|
135
|
+
$is_our_page = (
|
|
136
|
+
( isset( $_GET['page'] ) && '{{PAGE_SLUG}}-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
137
|
+
( $current_screen && '{{PAGE_SLUG}}' === $current_screen->id )
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if ( ! $is_our_page ) {
|
|
133
141
|
return;
|
|
134
142
|
}
|
|
135
143
|
|
|
144
|
+
// Load build constants
|
|
145
|
+
$build_constants = require __DIR__ . '/../../constants.php';
|
|
146
|
+
|
|
136
147
|
// Fire init action for extensions to register routes and menu items
|
|
137
148
|
do_action( '{{PAGE_SLUG}}-wp-admin_init' );
|
|
138
149
|
|
|
@@ -143,7 +154,7 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' ) )
|
|
|
143
154
|
$routes = get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes();
|
|
144
155
|
|
|
145
156
|
// Get boot module asset file for dependencies
|
|
146
|
-
$asset_file =
|
|
157
|
+
$asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
|
|
147
158
|
if ( file_exists( $asset_file ) ) {
|
|
148
159
|
$asset = require $asset_file;
|
|
149
160
|
|
|
@@ -198,7 +209,7 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' ) )
|
|
|
198
209
|
// Dummy script module to ensure dependencies are loaded
|
|
199
210
|
wp_register_script_module(
|
|
200
211
|
'{{PAGE_SLUG}}-wp-admin',
|
|
201
|
-
|
|
212
|
+
$build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
|
|
202
213
|
$boot_dependencies
|
|
203
214
|
);
|
|
204
215
|
|
|
@@ -218,6 +229,59 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page' ) ) {
|
|
|
218
229
|
*/
|
|
219
230
|
function {{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
|
|
220
231
|
?>
|
|
232
|
+
<style>
|
|
233
|
+
/* Critical styles to prevent layout shifts - inlined for immediate application */
|
|
234
|
+
|
|
235
|
+
/* Background colors */
|
|
236
|
+
#wpwrap {
|
|
237
|
+
background: var(--wpds-color-fg-content-neutral, #1e1e1e);
|
|
238
|
+
overflow-y: auto;
|
|
239
|
+
}
|
|
240
|
+
body {
|
|
241
|
+
background: #fff;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* Reset wp-admin padding */
|
|
245
|
+
#wpcontent {
|
|
246
|
+
padding-left: 0;
|
|
247
|
+
}
|
|
248
|
+
#wpbody-content {
|
|
249
|
+
padding-bottom: 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* Hide legacy admin elements */
|
|
253
|
+
#wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
|
|
254
|
+
display: none;
|
|
255
|
+
}
|
|
256
|
+
#wpfooter {
|
|
257
|
+
display: none;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* Accessibility regions */
|
|
261
|
+
.a11y-speak-region {
|
|
262
|
+
left: -1px;
|
|
263
|
+
top: -1px;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/* Admin menu indicators */
|
|
267
|
+
ul#adminmenu a.wp-has-current-submenu::after,
|
|
268
|
+
ul#adminmenu > li.current > a.current::after {
|
|
269
|
+
border-right-color: #fff;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* Media frame fix */
|
|
273
|
+
.media-frame select.attachment-filters:last-of-type {
|
|
274
|
+
width: auto;
|
|
275
|
+
max-width: 100%;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* Responsive overflow fix for #wpwrap */
|
|
279
|
+
@media (min-width: 782px) {
|
|
280
|
+
#wpwrap {
|
|
281
|
+
overflow-y: initial;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
</style>
|
|
221
285
|
<div id="{{PAGE_SLUG}}-wp-admin-app" class="boot-layout-container"></div>
|
|
222
286
|
<?php
|
|
223
287
|
}
|
|
@@ -226,27 +290,3 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page' ) ) {
|
|
|
226
290
|
// Hook the enqueue function to admin_enqueue_scripts
|
|
227
291
|
add_action( 'admin_enqueue_scripts', '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' );
|
|
228
292
|
|
|
229
|
-
if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_register_page' ) ) {
|
|
230
|
-
/**
|
|
231
|
-
* Register the {{PAGE_SLUG}}-wp-admin base page handler.
|
|
232
|
-
* This is hidden from the menu but provides the page callback for URL routing.
|
|
233
|
-
* Visible menu items should use the full URL pattern with query parameters.
|
|
234
|
-
*
|
|
235
|
-
* Example:
|
|
236
|
-
* $url = admin_url( 'admin.php?page={{PAGE_SLUG}}-wp-admin&p=' . urlencode( '/your/route' ) );
|
|
237
|
-
* add_menu_page( 'Title', 'Menu', 'capability', $url, '', 'icon', 10 );
|
|
238
|
-
*/
|
|
239
|
-
function {{PAGE_SLUG_UNDERSCORE}}_wp_admin_register_page() {
|
|
240
|
-
add_submenu_page(
|
|
241
|
-
'nothing-{{PAGE_SLUG}}', // Hidden page (no parent)
|
|
242
|
-
__( '{{PAGE_SLUG}} (WP Admin)', '{{PREFIX}}' ), // Page title
|
|
243
|
-
__( '{{PAGE_SLUG}} (WP Admin)', '{{PREFIX}}' ), // Menu title (not visible)
|
|
244
|
-
'read', // Minimum capability
|
|
245
|
-
'{{PAGE_SLUG}}-wp-admin', // Menu slug for URL routing
|
|
246
|
-
'{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page' // Callback function
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Hook the registration to admin_menu
|
|
252
|
-
add_action( 'admin_menu', '{{PAGE_SLUG_UNDERSCORE}}_wp_admin_register_page' );
|
|
@@ -127,6 +127,9 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
127
127
|
* Call this function from add_menu_page or add_submenu_page.
|
|
128
128
|
*/
|
|
129
129
|
function {{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
130
|
+
// Load build constants
|
|
131
|
+
$build_constants = require __DIR__ . '/../../constants.php';
|
|
132
|
+
|
|
130
133
|
// Set current screen
|
|
131
134
|
set_current_screen();
|
|
132
135
|
|
|
@@ -144,6 +147,11 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
144
147
|
// Fire init action for extensions to register routes and menu items
|
|
145
148
|
do_action( '{{PAGE_SLUG}}_init' );
|
|
146
149
|
|
|
150
|
+
// Enqueue command palette assets for boot-based pages
|
|
151
|
+
if ( function_exists( 'wp_enqueue_command_palette_assets' ) ) {
|
|
152
|
+
wp_enqueue_command_palette_assets();
|
|
153
|
+
}
|
|
154
|
+
|
|
147
155
|
// Preload REST API data
|
|
148
156
|
{{PAGE_SLUG_UNDERSCORE}}_preload_data();
|
|
149
157
|
|
|
@@ -152,7 +160,7 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
152
160
|
$routes = get_{{PAGE_SLUG_UNDERSCORE}}_routes();
|
|
153
161
|
|
|
154
162
|
// Get boot module asset file for dependencies
|
|
155
|
-
$asset_file =
|
|
163
|
+
$asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
|
|
156
164
|
if ( file_exists( $asset_file ) ) {
|
|
157
165
|
$asset = require $asset_file;
|
|
158
166
|
|
|
@@ -166,11 +174,12 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
166
174
|
wp_add_inline_script(
|
|
167
175
|
'{{PAGE_SLUG}}-prerequisites',
|
|
168
176
|
sprintf(
|
|
169
|
-
'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s}));',
|
|
177
|
+
'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));',
|
|
170
178
|
'{{PAGE_SLUG}}-app',
|
|
171
179
|
wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
172
180
|
wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
173
|
-
wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
|
181
|
+
wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
182
|
+
esc_url( admin_url( '/' ) )
|
|
174
183
|
)
|
|
175
184
|
);
|
|
176
185
|
|
|
@@ -213,7 +222,7 @@ if ( ! function_exists( '{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
|
|
|
213
222
|
// Dummy script module to ensure dependencies are loaded
|
|
214
223
|
wp_register_script_module(
|
|
215
224
|
'{{PAGE_SLUG}}',
|
|
216
|
-
|
|
225
|
+
$build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
|
|
217
226
|
$boot_dependencies
|
|
218
227
|
);
|
|
219
228
|
|
|
@@ -28,6 +28,8 @@ foreach ( $routes as $route ) {
|
|
|
28
28
|
// Helper function to register routes for a page
|
|
29
29
|
$register_routes_callback = function ( $page_routes, $page_slug_underscore, $register_function_name ) {
|
|
30
30
|
return function () use ( $page_routes, $page_slug_underscore, $register_function_name ) {
|
|
31
|
+
// Load build constants
|
|
32
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
31
33
|
foreach ( $page_routes as $route ) {
|
|
32
34
|
$content_handle = null;
|
|
33
35
|
$route_handle = null;
|
|
@@ -41,7 +43,7 @@ $register_routes_callback = function ( $page_routes, $page_slug_underscore, $reg
|
|
|
41
43
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
42
44
|
wp_register_script_module(
|
|
43
45
|
$content_handle,
|
|
44
|
-
|
|
46
|
+
$build_constants['build_url'] . 'routes/' . $route['name'] . '/content' . $extension,
|
|
45
47
|
$content_asset['module_dependencies'] ?? array(),
|
|
46
48
|
$content_asset['version'] ?? false
|
|
47
49
|
);
|
|
@@ -57,7 +59,7 @@ $register_routes_callback = function ( $page_routes, $page_slug_underscore, $reg
|
|
|
57
59
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
58
60
|
wp_register_script_module(
|
|
59
61
|
$route_handle,
|
|
60
|
-
|
|
62
|
+
$build_constants['build_url'] . 'routes/' . $route['name'] . '/route' . $extension,
|
|
61
63
|
$route_asset['module_dependencies'] ?? array(),
|
|
62
64
|
$route_asset['version'] ?? false
|
|
63
65
|
);
|
|
@@ -53,7 +53,9 @@ if ( ! function_exists( '{{PREFIX}}_register_package_scripts' ) ) {
|
|
|
53
53
|
* Register all package scripts.
|
|
54
54
|
*/
|
|
55
55
|
function {{PREFIX}}_register_package_scripts( $scripts ) {
|
|
56
|
-
|
|
56
|
+
// Load build constants
|
|
57
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
58
|
+
$default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
|
|
57
59
|
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
58
60
|
|
|
59
61
|
$scripts_dir = __DIR__ . '/scripts';
|
|
@@ -75,7 +77,7 @@ if ( ! function_exists( '{{PREFIX}}_register_package_scripts' ) ) {
|
|
|
75
77
|
{{PREFIX}}_override_script(
|
|
76
78
|
$scripts,
|
|
77
79
|
$script_data['handle'],
|
|
78
|
-
|
|
80
|
+
$build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension,
|
|
79
81
|
$dependencies,
|
|
80
82
|
$version,
|
|
81
83
|
true
|
|
@@ -43,7 +43,10 @@ if ( ! function_exists( '{{PREFIX}}_register_package_styles' ) ) {
|
|
|
43
43
|
* @param WP_Styles $styles WP_Styles instance.
|
|
44
44
|
*/
|
|
45
45
|
function {{PREFIX}}_register_package_styles( $styles ) {
|
|
46
|
-
|
|
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';
|
|
47
50
|
|
|
48
51
|
$styles_dir = __DIR__ . '/styles';
|
|
49
52
|
$styles_file = $styles_dir . '/index.php';
|
|
@@ -59,13 +62,14 @@ if ( ! function_exists( '{{PREFIX}}_register_package_styles' ) ) {
|
|
|
59
62
|
{{PREFIX}}_override_style(
|
|
60
63
|
$styles,
|
|
61
64
|
$style_data['handle'],
|
|
62
|
-
|
|
65
|
+
$build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css',
|
|
63
66
|
$style_data['dependencies'],
|
|
64
67
|
$default_version
|
|
65
68
|
);
|
|
66
69
|
|
|
67
70
|
// Enable RTL support (WordPress automatically loads -rtl.css variant)
|
|
68
71
|
$styles->add_data( $style_data['handle'], 'rtl', 'replace' );
|
|
72
|
+
$styles->add_data( $style_data['handle'], 'suffix', $suffix );
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|
package/tsconfig.json
CHANGED