From 5e0b87d950fd5e2dbb308f301f36e9c181638145 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 8 May 2026 19:11:17 +0100 Subject: [PATCH 1/2] Fix fatal errors from missing files during deploys --- packages/wp-build/lib/build.mjs | 5 ++++- .../wp-build/templates/module-registration.php.template | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 96005adb2234a0..80f26b8a791ec5 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -1243,7 +1243,10 @@ async function generatePagesPhp( pageData, replacements ) { // Generate pages.php loader const pageIncludes = pageData .map( ( page ) => { - return `require_once __DIR__ . '/pages/${ page.slug }/page.php';\nrequire_once __DIR__ . '/pages/${ page.slug }/page-wp-admin.php';`; + return [ + `if ( file_exists( __DIR__ . '/pages/${ page.slug }/page.php' ) ) {\n\trequire_once __DIR__ . '/pages/${ page.slug }/page.php';\n}`, + `if ( file_exists( __DIR__ . '/pages/${ page.slug }/page-wp-admin.php' ) ) {\n\trequire_once __DIR__ . '/pages/${ page.slug }/page-wp-admin.php';\n}`, + ].join( '\n' ); } ) .join( '\n' ); diff --git a/packages/wp-build/templates/module-registration.php.template b/packages/wp-build/templates/module-registration.php.template index d2c87122737ebe..49ca9ab3330263 100644 --- a/packages/wp-build/templates/module-registration.php.template +++ b/packages/wp-build/templates/module-registration.php.template @@ -21,7 +21,11 @@ function {{PREFIX}}_register_script_modules() { $already_registered = true; // Load build constants - $build_constants = require __DIR__ . '/constants.php'; + $constants_file = __DIR__ . '/constants.php'; + if ( ! file_exists( $constants_file ) ) { + return; + } + $build_constants = require $constants_file; $modules_dir = __DIR__ . '/modules'; $modules_file = $modules_dir . '/registry.php'; From b3ff68dfd3a5314cae25019eb99c868a97b48c80 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Sat, 9 May 2026 10:41:17 +0100 Subject: [PATCH 2/2] Build single array of page files --- packages/wp-build/lib/build.mjs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 80f26b8a791ec5..39e746630bec46 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -1241,14 +1241,19 @@ async function generatePagesPhp( pageData, replacements ) { await Promise.all( pageGenerationPromises ); // Generate pages.php loader - const pageIncludes = pageData - .map( ( page ) => { - return [ - `if ( file_exists( __DIR__ . '/pages/${ page.slug }/page.php' ) ) {\n\trequire_once __DIR__ . '/pages/${ page.slug }/page.php';\n}`, - `if ( file_exists( __DIR__ . '/pages/${ page.slug }/page-wp-admin.php' ) ) {\n\trequire_once __DIR__ . '/pages/${ page.slug }/page-wp-admin.php';\n}`, - ].join( '\n' ); - } ) - .join( '\n' ); + const pageFiles = pageData.flatMap( ( page ) => [ + `\t__DIR__ . '/pages/${ page.slug }/page.php'`, + `\t__DIR__ . '/pages/${ page.slug }/page-wp-admin.php'`, + ] ); + const pageIncludes = [ + 'foreach ( [', + pageFiles.join( ',\n' ) + ',', + '] as $file ) {', + '\tif ( file_exists( $file ) ) {', + '\t\trequire_once $file;', + '\t}', + '}', + ].join( '\n' ); await generatePhpFromTemplate( 'pages.php.template',