@@ -6,11 +6,13 @@ import { bootWordPressAndRequestHandler, type WordPressInstallMode } from "@wp-p
66import { dependenciesTotalSize , init } from "../../../node_modules/@php-wasm/web-8-5/asyncify/php_8_5.js"
77import phpWasmModule from "../../../node_modules/@php-wasm/web-8-5/asyncify/8_5_8/php_8_5.wasm"
88import { CLOUDFLARE_RUNTIME_HEALTH_MARKER , CLOUDFLARE_RUNTIME_HEALTH_SCHEMA , cloudflareRuntimeHealthResponse } from "./health-envelope.js"
9+ import wordpressInstallSeed from "../assets/wordpress-install-seed.sqlite"
910
1011const PHP_VERSION = "8.5.8"
1112const WORDPRESS_ARCHIVE_URL = "https://wordpress.org/latest.zip"
1213const SQLITE_INTEGRATION_ARCHIVE_URL = "https://github.com/WordPress/sqlite-database-integration/releases/download/v2.2.23/plugin-sqlite-database-integration.zip"
1314const SITE_URL = "https://wp-codebox-runtime.invalid"
15+ const DATABASE_PATH = "/wordpress/wp-content/database/.ht.sqlite"
1416let bootPromise : Promise < { php : PHP ; wordpressVersion : string } > | undefined
1517
1618export default {
@@ -80,6 +82,27 @@ async function runBootProbe(phase: string): Promise<Response> {
8082 }
8183 }
8284
85+ if ( phase === "seeded-wordpress" ) {
86+ const runtime = await bootWordPressRuntime (
87+ "install-from-existing-files-if-needed" ,
88+ true ,
89+ true ,
90+ new Uint8Array ( wordpressInstallSeed ) ,
91+ )
92+ try {
93+ const wordpress = ( await runtime . php . run ( {
94+ code : "<?php require '/wordpress/wp-load.php'; echo json_encode(['siteUrl' => get_option('siteurl'), 'wordpressVersion' => get_bloginfo('version')]);" ,
95+ } ) ) . text . trim ( )
96+ try {
97+ return probeResponse ( phase , JSON . parse ( wordpress ) as Record < string , string > )
98+ } catch {
99+ throw new Error ( `WordPress boot returned invalid JSON: ${ wordpress } ` )
100+ }
101+ } finally {
102+ runtime . php . exit ( )
103+ }
104+ }
105+
83106 if ( phase === "wordpress-files" || phase === "sqlite" || phase === "full" || phase === "streamed-sqlite" || phase === "streamed-wordpress" ) {
84107 const runtime = await bootWordPressRuntime (
85108 phase === "full" || phase === "streamed-wordpress" ? "install-from-existing-files" : "do-not-attempt-installing" ,
@@ -101,10 +124,18 @@ async function bootWordPressRuntime(
101124 wordpressInstallMode : WordPressInstallMode = "install-from-existing-files" ,
102125 includeSqlite = true ,
103126 streamWordPressFiles = false ,
127+ databaseSeed ?: Uint8Array ,
104128) : Promise < { php : PHP ; wordpressVersion : string } > {
105129 const requestHandler = await bootWordPressAndRequestHandler ( {
106130 createPhpRuntime,
107- hooks : streamWordPressFiles ? { beforeWordPressFiles : materializeWordPressServerFiles } : undefined ,
131+ dataSqlPath : DATABASE_PATH ,
132+ hooks : streamWordPressFiles || databaseSeed ? {
133+ beforeWordPressFiles : streamWordPressFiles ? materializeWordPressServerFiles : undefined ,
134+ beforeDatabaseSetup : databaseSeed ? ( php : PHP ) => {
135+ php . mkdir ( "/wordpress/wp-content/database" )
136+ php . writeFile ( DATABASE_PATH , databaseSeed )
137+ } : undefined ,
138+ } : undefined ,
108139 maxPhpInstances : 1 ,
109140 phpVersion : "8.5" ,
110141 siteUrl : SITE_URL ,
@@ -141,7 +172,9 @@ async function materializeWordPressServerFiles(php: PHP): Promise<{ materialized
141172}
142173
143174function isWordPressServerFile ( path : string ) : boolean {
144- return / \. (?: p h p | j s o n | c r t | h t m l ) $ / . test ( path ) || path . endsWith ( "/style.css" )
175+ return / \. (?: p h p | j s o n | c r t | h t m l ) $ / . test ( path )
176+ || path . endsWith ( "/style.css" )
177+ || path . endsWith ( "/wp-admin/css/view-transitions.min.css" )
145178}
146179
147180function createPhpRuntime ( ) {
0 commit comments