diff --git a/packages/playground/remote/src/lib/worker-thread.ts b/packages/playground/remote/src/lib/worker-thread.ts index a29a099e84..cf56ceca62 100644 --- a/packages/playground/remote/src/lib/worker-thread.ts +++ b/packages/playground/remote/src/lib/worker-thread.ts @@ -6,8 +6,12 @@ import { getWordPressModuleDetails, LatestSupportedWordPressVersion, SupportedWordPressVersions, + sqliteDatabaseIntegration, } from '@wp-playground/wordpress-builds'; -import { wordPressRewriteRules } from '@wp-playground/wordpress'; +import { + preloadSqliteIntegration, + wordPressRewriteRules, +} from '@wp-playground/wordpress'; import { PHPRequestHandler } from '@php-wasm/universal'; import { SyncProgressCallback, @@ -57,6 +61,14 @@ if ( wordPressAvailableInOPFS = await playgroundAvailableInOpfs(virtualOpfsDir!); } +// The SQLite integration must always be downloaded, even when using OPFS or Native FS, +// because it can't be assumed to exist in WordPress document root. Instead, it's installed +// in the /internal directory to avoid polluting the mounted directory structure. +downloadMonitor.expectAssets({ + [sqliteDatabaseIntegration.url]: sqliteDatabaseIntegration.size, +}); +const sqliteIntegrationRequest = monitoredFetch(sqliteDatabaseIntegration.url); + // Start downloading WordPress if needed let wordPressRequest = null; if (!wordPressAvailableInOPFS) { @@ -210,6 +222,12 @@ try { }); } + const sqliteIntegrationZip = await (await sqliteIntegrationRequest).blob(); + await preloadSqliteIntegration( + primaryPhp, + new File([sqliteIntegrationZip], 'sqlite.zip') + ); + // Always setup the current site URL. await defineSiteUrl(primaryPhp, { siteUrl: scopedSiteUrl, diff --git a/packages/playground/wordpress/src/index.ts b/packages/playground/wordpress/src/index.ts index 7160af09c8..c20212c13f 100644 --- a/packages/playground/wordpress/src/index.ts +++ b/packages/playground/wordpress/src/index.ts @@ -202,12 +202,21 @@ export async function preloadSqliteIntegration( "'{SQLITE_PLUGIN}'", phpVar(joinPaths(SQLITE_PLUGIN_FOLDER, 'load.php')) ); + const dbPhpPath = joinPaths(await php.documentRoot, 'wp-content/db.php'); + const stopIfDbPhpExists = ``; const SQLITE_MUPLUGIN_PATH = '/internal/shared/mu-plugins/sqlite-database-integration.php'; - await php.writeFile(SQLITE_MUPLUGIN_PATH, dbPhp); + await php.writeFile(SQLITE_MUPLUGIN_PATH, stopIfDbPhpExists + dbPhp); await php.writeFile( `/internal/shared/preload/0-sqlite.php`, - `