@wordpress/build 0.27.0 → 0.29.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/CHANGELOG.md +35 -0
- package/README.md +46 -9
- package/lib/build.mjs +350 -378
- package/lib/copy-files.mjs +165 -0
- package/lib/package-utils.mjs +14 -0
- package/lib/style-dependencies.mjs +69 -0
- package/lib/translator-comments-plugin.mjs +347 -0
- package/package.json +10 -11
- package/templates/build.php.template +4 -0
- package/templates/constants.php.template +7 -2
- package/templates/module-registration.php.template +5 -2
- package/templates/module-registry.php.template +4 -0
- package/templates/page-wp-admin.php.template +65 -52
- package/templates/page.php.template +25 -19
- package/templates/pages.php.template +4 -0
- package/templates/route-registry.php.template +4 -0
- package/templates/routes-registration.php.template +12 -2
- package/templates/script-registration.php.template +9 -1
- package/templates/script-registry.php.template +4 -0
- package/templates/style-registration.php.template +9 -1
- package/templates/style-registry.php.template +4 -0
- package/templates/widget-registration.php.template +8 -1
- package/templates/widget-registry.php.template +4 -0
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* @package {{PREFIX}}
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
10
|
+
exit;
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Register all script modules.
|
|
11
15
|
*/
|
|
@@ -35,10 +39,9 @@ function {{PREFIX}}_register_script_modules() {
|
|
|
35
39
|
|
|
36
40
|
$modules = require $modules_file;
|
|
37
41
|
$base_url = $build_constants['build_url'] . 'modules/';
|
|
38
|
-
|
|
39
42
|
foreach ( $modules as $module ) {
|
|
40
43
|
// WASM-only modules (e.g., vips worker) only have .min.js; use it even when SCRIPT_DEBUG is `true`.
|
|
41
|
-
$extension = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && empty( $module['min_only'] ) )
|
|
44
|
+
$extension = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] && empty( $module['min_only'] ) )
|
|
42
45
|
? '.js'
|
|
43
46
|
: '.min.js';
|
|
44
47
|
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* @package {{PREFIX}}
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
14
|
+
exit;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
// Global storage for {{PAGE_SLUG}} routes and menu items
|
|
14
18
|
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes, ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items;
|
|
15
19
|
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes = array();
|
|
@@ -134,10 +138,17 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
134
138
|
// Check all possible ways this page can be accessed:
|
|
135
139
|
// 1. Menu page via admin.php?page={{PAGE_SLUG}}-wp-admin (plugin)
|
|
136
140
|
// 2. Direct file via {{PAGE_SLUG}}.php (Core) - screen ID will be '{{PAGE_SLUG}}'
|
|
141
|
+
// The screen ID alone is not enough: a Core screen can share it with the page
|
|
142
|
+
// slug (for example, index.php has the screen ID 'dashboard').
|
|
137
143
|
$current_screen = get_current_screen();
|
|
138
144
|
$is_our_page = (
|
|
139
145
|
( isset( $_GET['page'] ) && '{{PAGE_SLUG}}-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
140
|
-
(
|
|
146
|
+
(
|
|
147
|
+
$current_screen &&
|
|
148
|
+
'{{PAGE_SLUG}}' === $current_screen->id &&
|
|
149
|
+
isset( $GLOBALS['pagenow'] ) &&
|
|
150
|
+
'{{PAGE_SLUG}}.php' === $GLOBALS['pagenow']
|
|
151
|
+
)
|
|
141
152
|
);
|
|
142
153
|
|
|
143
154
|
if ( ! $is_our_page ) {
|
|
@@ -217,6 +228,58 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
217
228
|
);
|
|
218
229
|
wp_register_style( '{{PAGE_SLUG}}-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
|
|
219
230
|
|
|
231
|
+
// Critical styles to prevent layout shifts.
|
|
232
|
+
$page_styles = <<<'CSS'
|
|
233
|
+
#wpwrap {
|
|
234
|
+
overflow-y: auto;
|
|
235
|
+
}
|
|
236
|
+
body.js {
|
|
237
|
+
background: #fff;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* Reset wp-admin padding */
|
|
241
|
+
body.js #wpcontent {
|
|
242
|
+
padding-inline-start: 0;
|
|
243
|
+
}
|
|
244
|
+
body.js #wpbody-content {
|
|
245
|
+
padding-bottom: 0;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Hide legacy admin elements */
|
|
249
|
+
body.js #wpbody-content > div:not(#{{PAGE_SLUG}}-wp-admin-app):not(#screen-meta) {
|
|
250
|
+
display: none;
|
|
251
|
+
}
|
|
252
|
+
body.js #wpfooter {
|
|
253
|
+
display: none;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* Accessibility regions */
|
|
257
|
+
.a11y-speak-region {
|
|
258
|
+
inset-inline-start: -1px;
|
|
259
|
+
top: -1px;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* Admin menu indicators */
|
|
263
|
+
ul#adminmenu a.wp-has-current-submenu::after,
|
|
264
|
+
ul#adminmenu > li.current > a.current::after {
|
|
265
|
+
border-inline-end-color: #fff;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* Media frame fix */
|
|
269
|
+
.media-frame select.attachment-filters:last-of-type {
|
|
270
|
+
width: auto;
|
|
271
|
+
max-width: 100%;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Responsive overflow fix for #wpwrap */
|
|
275
|
+
@media (min-width: 782px) {
|
|
276
|
+
#wpwrap {
|
|
277
|
+
overflow-y: initial;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
CSS;
|
|
281
|
+
wp_add_inline_style( '{{PAGE_SLUG}}-wp-admin-prerequisites', $page_styles );
|
|
282
|
+
|
|
220
283
|
// Build dependencies for {{PAGE_SLUG}}-wp-admin module
|
|
221
284
|
$boot_dependencies = array(
|
|
222
285
|
array(
|
|
@@ -280,61 +343,11 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
|
|
|
280
343
|
*/
|
|
281
344
|
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
|
|
282
345
|
?>
|
|
283
|
-
<style>
|
|
284
|
-
/* Critical styles to prevent layout shifts - inlined for immediate application */
|
|
285
|
-
|
|
286
|
-
#wpwrap {
|
|
287
|
-
overflow-y: auto;
|
|
288
|
-
}
|
|
289
|
-
body.js {
|
|
290
|
-
background: #fff;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/* Reset wp-admin padding */
|
|
294
|
-
body.js #wpcontent {
|
|
295
|
-
padding-inline-start: 0;
|
|
296
|
-
}
|
|
297
|
-
body.js #wpbody-content {
|
|
298
|
-
padding-bottom: 0;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/* Hide legacy admin elements */
|
|
302
|
-
body.js #wpbody-content > div:not(#{{PAGE_SLUG}}-wp-admin-app):not(#screen-meta) {
|
|
303
|
-
display: none;
|
|
304
|
-
}
|
|
305
|
-
body.js #wpfooter {
|
|
306
|
-
display: none;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/* Accessibility regions */
|
|
310
|
-
.a11y-speak-region {
|
|
311
|
-
inset-inline-start: -1px;
|
|
312
|
-
top: -1px;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/* Admin menu indicators */
|
|
316
|
-
ul#adminmenu a.wp-has-current-submenu::after,
|
|
317
|
-
ul#adminmenu > li.current > a.current::after {
|
|
318
|
-
border-inline-end-color: #fff;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/* Media frame fix */
|
|
322
|
-
.media-frame select.attachment-filters:last-of-type {
|
|
323
|
-
width: auto;
|
|
324
|
-
max-width: 100%;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/* Responsive overflow fix for #wpwrap */
|
|
328
|
-
@media (min-width: 782px) {
|
|
329
|
-
#wpwrap {
|
|
330
|
-
overflow-y: initial;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
</style>
|
|
334
346
|
<div class="wrap hide-if-js">
|
|
335
347
|
<h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
|
336
348
|
<?php
|
|
337
349
|
wp_admin_notice(
|
|
350
|
+
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core string, translated in the default text domain.
|
|
338
351
|
__( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
|
|
339
352
|
array( 'type' => 'error' )
|
|
340
353
|
);
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* @package {{PREFIX}}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
11
|
+
exit;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
// Global storage for {{PAGE_SLUG}} routes and menu items
|
|
11
15
|
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes, ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items;
|
|
12
16
|
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes = array();
|
|
@@ -189,6 +193,23 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
189
193
|
);
|
|
190
194
|
wp_register_style( '{{PAGE_SLUG}}-prerequisites', false, $style_dependencies, $asset['version'] );
|
|
191
195
|
|
|
196
|
+
// Base styles for the full-page screen, which renders without the wp-admin stylesheets.
|
|
197
|
+
// `:where()` lets a page that shows the admin bar override the rule hiding it.
|
|
198
|
+
$page_styles = <<<'CSS'
|
|
199
|
+
html {
|
|
200
|
+
background: #f1f1f1;
|
|
201
|
+
color: #444;
|
|
202
|
+
font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
203
|
+
font-size: 13px;
|
|
204
|
+
line-height: 1.4em;
|
|
205
|
+
}
|
|
206
|
+
body {
|
|
207
|
+
margin: 0;
|
|
208
|
+
}
|
|
209
|
+
:where(#wpadminbar) { display: none; }
|
|
210
|
+
CSS;
|
|
211
|
+
wp_add_inline_style( '{{PAGE_SLUG}}-prerequisites', $page_styles );
|
|
212
|
+
|
|
192
213
|
// Build dependencies for {{PAGE_SLUG}} module
|
|
193
214
|
$boot_dependencies = array(
|
|
194
215
|
array(
|
|
@@ -252,19 +273,6 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
252
273
|
<meta charset="<?php bloginfo( 'charset' ); ?>">
|
|
253
274
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
254
275
|
<title><?php echo esc_html( get_admin_page_title() ); ?></title>
|
|
255
|
-
<style>
|
|
256
|
-
html {
|
|
257
|
-
background: #f1f1f1;
|
|
258
|
-
color: #444;
|
|
259
|
-
font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
260
|
-
font-size: 13px;
|
|
261
|
-
line-height: 1.4em;
|
|
262
|
-
}
|
|
263
|
-
body {
|
|
264
|
-
margin: 0;
|
|
265
|
-
}
|
|
266
|
-
#wpadminbar { display: none; }
|
|
267
|
-
</style>
|
|
268
276
|
<?php
|
|
269
277
|
global $hook_suffix;
|
|
270
278
|
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
@@ -285,17 +293,14 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
|
285
293
|
<body class="{{PAGE_SLUG}} no-js">
|
|
286
294
|
<?php
|
|
287
295
|
// BEGIN see wp-admin/admin-header.php
|
|
288
|
-
|
|
289
|
-
<script type="text/javascript">
|
|
290
|
-
document.body.className = document.body.className.replace( 'no-js', 'js' );
|
|
291
|
-
</script>
|
|
292
|
-
<?php
|
|
296
|
+
wp_print_inline_script_tag( "document.body.className = document.body.className.replace( 'no-js', 'js' );" );
|
|
293
297
|
// END see wp-admin/admin-header.php
|
|
294
298
|
?>
|
|
295
299
|
<div class="wrap hide-if-js" style="margin: 20px;">
|
|
296
300
|
<h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
|
|
297
301
|
<?php
|
|
298
302
|
wp_admin_notice(
|
|
303
|
+
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core string, translated in the default text domain.
|
|
299
304
|
__( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
|
|
300
305
|
array( 'type' => 'error' )
|
|
301
306
|
);
|
|
@@ -343,7 +348,8 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() {
|
|
|
343
348
|
|
|
344
349
|
if ( ! current_user_can( '{{CAPABILITY}}' ) ) {
|
|
345
350
|
wp_die(
|
|
346
|
-
|
|
351
|
+
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Core string, translated in the default text domain.
|
|
352
|
+
esc_html__( 'Sorry, you are not allowed to access this page.' ),
|
|
347
353
|
403
|
|
348
354
|
);
|
|
349
355
|
}
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* @package {{PREFIX}}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
11
|
+
exit;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
// Load routes registry
|
|
11
15
|
$routes_file = __DIR__ . '/routes/registry.php';
|
|
12
16
|
if ( ! file_exists( $routes_file ) ) {
|
|
@@ -52,7 +56,10 @@ function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name
|
|
|
52
56
|
if ( file_exists( $content_asset_path ) ) {
|
|
53
57
|
$content_asset = require $content_asset_path;
|
|
54
58
|
$content_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/content';
|
|
55
|
-
$extension =
|
|
59
|
+
$extension = '.min.js';
|
|
60
|
+
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] ) {
|
|
61
|
+
$extension = '.js';
|
|
62
|
+
}
|
|
56
63
|
// Deregister first to override any previously registered version
|
|
57
64
|
// (e.g., Core's default modules when running as a plugin).
|
|
58
65
|
wp_deregister_script_module( $content_handle );
|
|
@@ -71,7 +78,10 @@ function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name
|
|
|
71
78
|
if ( file_exists( $route_asset_path ) ) {
|
|
72
79
|
$route_asset = require $route_asset_path;
|
|
73
80
|
$route_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/route';
|
|
74
|
-
$extension =
|
|
81
|
+
$extension = '.min.js';
|
|
82
|
+
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] ) {
|
|
83
|
+
$extension = '.js';
|
|
84
|
+
}
|
|
75
85
|
// Deregister first to override any previously registered version
|
|
76
86
|
// (e.g., Core's default modules when running as a plugin).
|
|
77
87
|
wp_deregister_script_module( $route_handle );
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* @package {{PREFIX}}
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
10
|
+
exit;
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Registers a script according to `wp_register_script`. Honors this request by
|
|
11
15
|
* reassigning internal dependency properties of any script handle already
|
|
@@ -53,7 +57,6 @@ function {{PREFIX}}_register_package_scripts( $scripts ) {
|
|
|
53
57
|
// Load build constants
|
|
54
58
|
$build_constants = require __DIR__ . '/constants.php';
|
|
55
59
|
$default_version = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $build_constants['version'];
|
|
56
|
-
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
57
60
|
|
|
58
61
|
$scripts_dir = __DIR__ . '/scripts';
|
|
59
62
|
$scripts_file = $scripts_dir . '/registry.php';
|
|
@@ -63,6 +66,11 @@ function {{PREFIX}}_register_package_scripts( $scripts ) {
|
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
$scripts_data = require $scripts_file;
|
|
69
|
+
|
|
70
|
+
$extension = '.min.js';
|
|
71
|
+
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] ) {
|
|
72
|
+
$extension = '.js';
|
|
73
|
+
}
|
|
66
74
|
$plugin_dir = dirname( __FILE__ );
|
|
67
75
|
|
|
68
76
|
foreach ( $scripts_data as $script_data ) {
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* @package {{PREFIX}}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
13
|
+
exit;
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
/**
|
|
13
17
|
* Registers a style according to `wp_register_style`. Honors this request by
|
|
14
18
|
* deregistering any style by the same handler before registration.
|
|
@@ -43,7 +47,11 @@ function {{PREFIX}}_register_package_styles( $styles ) {
|
|
|
43
47
|
// Load build constants
|
|
44
48
|
$build_constants = require __DIR__ . '/constants.php';
|
|
45
49
|
$default_version = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $build_constants['version'];
|
|
46
|
-
|
|
50
|
+
|
|
51
|
+
$suffix = '.min';
|
|
52
|
+
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] ) {
|
|
53
|
+
$suffix = '';
|
|
54
|
+
}
|
|
47
55
|
|
|
48
56
|
$styles_dir = __DIR__ . '/styles';
|
|
49
57
|
$styles_file = $styles_dir . '/registry.php';
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* @package {{PREFIX}}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
11
|
+
exit;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Register widget script modules.
|
|
12
16
|
*
|
|
@@ -24,7 +28,10 @@ function {{PREFIX}}_register_widget_modules() {
|
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
$build_constants = require __DIR__ . '/constants.php';
|
|
27
|
-
$extension =
|
|
31
|
+
$extension = '.min.js';
|
|
32
|
+
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] ) {
|
|
33
|
+
$extension = '.js';
|
|
34
|
+
}
|
|
28
35
|
|
|
29
36
|
foreach ( $widgets as $widget ) {
|
|
30
37
|
$widget_name = $widget['dir_name'];
|