diff --git a/packages/wp-now/src/wp-now.ts b/packages/wp-now/src/wp-now.ts index 9dad5af1fb..1bce67d2f6 100644 --- a/packages/wp-now/src/wp-now.ts +++ b/packages/wp-now/src/wp-now.ts @@ -197,8 +197,9 @@ async function runWpContentMode( php.mount(projectPath, `${documentRoot}/wp-content`); + mountSqlitePlugin(php, documentRoot); + mountSqliteDatabaseDirectory(php, documentRoot, wpContentPath); mountMuPlugins(php, documentRoot); - mountSqlite(php, documentRoot); } async function runWordPressDevelopMode( @@ -214,14 +215,15 @@ async function runWordPressDevelopMode( async function runWordPressMode( php: NodePHP, - { documentRoot, projectPath, absoluteUrl }: WPNowOptions + { documentRoot, wpContentPath, projectPath, absoluteUrl }: WPNowOptions ) { php.mount(projectPath, documentRoot); if (!php.fileExists(`${documentRoot}/wp-config.php`)) { await initWordPress(php, 'user-provided', documentRoot, absoluteUrl); } + mountSqlitePlugin(php, documentRoot); + mountSqliteDatabaseDirectory(php, documentRoot, wpContentPath); mountMuPlugins(php, documentRoot); - copySqlite(projectPath); } async function runPluginOrThemeMode( @@ -252,8 +254,8 @@ async function runPluginOrThemeMode( projectPath, `${documentRoot}/wp-content/${directoryName}/${pluginName}` ); + mountSqlitePlugin(php, documentRoot); mountMuPlugins(php, documentRoot); - mountSqlite(php, documentRoot); } async function initWordPress( @@ -283,7 +285,7 @@ function mountMuPlugins(php: NodePHP, vfsDocumentRoot: string) { ); } -function mountSqlite(php: NodePHP, vfsDocumentRoot: string) { +function mountSqlitePlugin(php: NodePHP, vfsDocumentRoot: string) { const sqlitePluginPath = `${vfsDocumentRoot}/wp-content/plugins/${SQLITE_FILENAME}`; if (php.listFiles(sqlitePluginPath).length === 0) { php.mount(SQLITE_PATH, sqlitePluginPath); @@ -294,14 +296,22 @@ function mountSqlite(php: NodePHP, vfsDocumentRoot: string) { } } -function copySqlite(localWordPressPath: string) { - const targetPath = `${localWordPressPath}/wp-content/plugins/${SQLITE_FILENAME}`; - if (!fs.existsSync(targetPath)) { - fs.copySync(SQLITE_PATH, targetPath); - } - fs.copySync( - `${SQLITE_PATH}/db.copy`, - `${localWordPressPath}/wp-content/db.php` +/** + * Create SQLite database directory in hidden utility directory and mount it to the document root + * + * @param php + * @param vfsDocumentRoot + * @param wpContentPath + */ +function mountSqliteDatabaseDirectory( + php: NodePHP, + vfsDocumentRoot: string, + wpContentPath: string +) { + fs.ensureDirSync(path.join(wpContentPath, 'database')); + php.mount( + path.join(wpContentPath, 'database'), + path.join(vfsDocumentRoot, 'wp-content', 'database') ); }