Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix paths
  • Loading branch information
jeroenpf committed Aug 23, 2024
commit 3592e75fdafbc07ef20034eed604af6bb2c198b0
1 change: 0 additions & 1 deletion vendor/wp-now/src/execute-php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export async function executePHP(
const [, php] = phpInstances;

try {
php.useHostFilesystem();
if (!path.isAbsolute(phpArgs[1])) {
const maybePhpFile = path.join(
wpNowOptions.projectPath,
Expand Down
6 changes: 3 additions & 3 deletions vendor/wp-now/src/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express from 'express';
import compression from 'compression';
import compressible from 'compressible';
import { portFinder } from './port-finder';
import { NodePHP } from '@php-wasm/node';
import { PHP } from '@php-wasm/universal';
import startWPNow from './wp-now';
import { output } from './output';
import { addTrailingSlash } from './add-trailing-slash';
Expand All @@ -23,7 +23,7 @@ const requestBodyToBytes = async ( req ): Promise< Uint8Array > =>

export interface WPNowServer {
url: string;
php: NodePHP;
php: PHP;
options: WPNowOptions;
stopServer: () => Promise<void>;
}
Expand All @@ -42,12 +42,12 @@ export async function startServer(
`The given path "${options.projectPath}" does not exist.`
);
}

const app = express();
app.use(compression({ filter: shouldCompress }));
app.use(addTrailingSlash('/wp-admin'));
const port = options.port ?? await portFinder.getOpenPort();
const { php, options: wpNowOptions } = await startWPNow(options);

app.use('/', async (req, res) => {
try {
const requestHeaders = {};
Expand Down
16 changes: 11 additions & 5 deletions vendor/wp-now/src/wp-now.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs-extra';
import { loadNodeRuntime,createNodeFsMountHandler } from '@php-wasm/node';
import { loadNodeRuntime } from '@php-wasm/node';
import { MountHandler, PHP, PHPRequestHandler, setPhpIniEntries } from '@php-wasm/universal';
import path from 'path';
import { SQLITE_FILENAME } from './constants';
Expand Down Expand Up @@ -42,8 +42,6 @@ export default async function startWPNow(
options: Partial<WPNowOptions> = {}
): Promise<{ php: PHP; phpInstances: PHP[]; options: WPNowOptions }> {
const { documentRoot } = options;


const requestHandler = new PHPRequestHandler({
phpFactory: async ({ isPrimary }) => {
const id = await loadNodeRuntime( options.phpVersion );
Expand All @@ -60,7 +58,6 @@ export default async function startWPNow(

const php = await requestHandler.getPrimaryPhp()


php.mkdir(documentRoot);
php.chdir(documentRoot);
php.writeFile(
Expand Down Expand Up @@ -150,6 +147,15 @@ async function runIndexMode(
php.mount(projectPath, createNodeFsMountHandler( documentRoot ) );
}

function createNodeFsMountHandler( localPath: string ): MountHandler {
return async function (php, FS, vfsMountPoint) {
FS.mount(FS.filesystems['NODEFS'], { root: localPath }, vfsMountPoint);
return () => {
FS!.unmount(localPath);
};
};
}

async function runWpContentMode(
php: PHP,
{
Expand Down Expand Up @@ -392,7 +398,7 @@ function mountMuPlugins(php: PHP, vfsDocumentRoot: string) {
function mountSqlitePlugin(php: PHP, vfsDocumentRoot: string) {
const sqlitePluginPath = `${vfsDocumentRoot}/wp-content/plugins/${SQLITE_FILENAME}`;
if (php.listFiles(sqlitePluginPath).length === 0) {
php.mount(getSqlitePath(), sqlitePluginPath);
php.mount(getSqlitePath(), createNodeFsMountHandler(sqlitePluginPath));
php.mount(
path.join(getSqlitePath(), 'db.copy'),
createNodeFsMountHandler( `${vfsDocumentRoot}/wp-content/db.php`)
Expand Down