Skip to content

Commit 4f6fda4

Browse files
committed
Don't create directories manually before mounting to NODEFS
1 parent 1c180c5 commit 4f6fda4

File tree

5 files changed

+14
-34
lines changed

5 files changed

+14
-34
lines changed

packages/php-wasm/node/src/test/php.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -868,27 +868,27 @@ describe.each(phpVersions)('PHP %s', (phpVersion) => {
868868
1 => array("pipe","w")
869869
);
870870
$proc = proc_open( "fetch", $descriptorspec, $pipes );
871-
871+
872872
// Make the stream non-blocking
873873
stream_set_blocking($pipes[1], false);
874-
874+
875875
// First read should get initial data immediately
876876
$data1 = fread($pipes[1], 1024);
877877
echo "First read: " . json_encode($data1) . "\\n";
878-
878+
879879
// Second read should return empty string immediately (non-blocking)
880880
$data2 = fread($pipes[1], 1024);
881881
echo "Second read (immediate): " . json_encode($data2) . "\\n";
882-
882+
883883
// Wait a bit and try again - should get the delayed data
884884
sleep(1);
885885
$data3 = fread($pipes[1], 1024);
886886
echo "Third read (after delay): " . json_encode($data3) . "\\n";
887-
887+
888888
// Fourth read should be empty again
889889
$data4 = fread($pipes[1], 1024);
890890
echo "Fourth read: " . json_encode($data4) . "\\n";
891-
891+
892892
proc_close( $proc );
893893
`,
894894
});
@@ -927,14 +927,14 @@ describe.each(phpVersions)('PHP %s', (phpVersion) => {
927927
1 => array("pipe","w")
928928
);
929929
$proc = proc_open( "fetch", $descriptorspec, $pipes );
930-
930+
931931
// Make the stream non-blocking
932932
stream_set_blocking($pipes[1], false);
933-
933+
934934
$chunks = array();
935935
$attempts = 0;
936936
$maxAttempts = 20;
937-
937+
938938
// Poll until we get all data or reach max attempts
939939
while ($attempts < $maxAttempts && !feof($pipes[1])) {
940940
$data = fread($pipes[1], 1024);
@@ -947,10 +947,10 @@ describe.each(phpVersions)('PHP %s', (phpVersion) => {
947947
$attempts++;
948948
usleep(100000); // 100ms between attempts
949949
}
950-
950+
951951
echo "Total chunks received: " . count($chunks) . "\\n";
952952
echo "Combined data: " . json_encode(implode("", $chunks)) . "\\n";
953-
953+
954954
proc_close( $proc );
955955
`,
956956
});
@@ -1395,7 +1395,6 @@ describe.each(phpVersions)('PHP %s', (phpVersion) => {
13951395
__dirname + '/test-data/mount-contents/a/b/test.txt',
13961396
'contents'
13971397
);
1398-
php.mkdir('/nodefs');
13991398
php.mount(
14001399
'/nodefs',
14011400
createNodeFsMountHandler(
@@ -1430,7 +1429,6 @@ describe.each(phpVersions)('PHP %s', (phpVersion) => {
14301429
});
14311430

14321431
it('mv() from MEMFS to NODEFS should work', () => {
1433-
php.mkdir('/nodefs');
14341432
php.mount(
14351433
'/nodefs',
14361434
createNodeFsMountHandler(

packages/php-wasm/node/src/test/rotate-php-runtime.spec.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ describe('rotatePHPRuntime()', () => {
6868
fs.writeFileSync(tempFile, 'playground');
6969

7070
// Mount the temporary directory
71-
php.mkdir('/test-root');
7271
await php.mount('/test-root', createNodeFsMountHandler(tempDir));
7372

7473
// Confirm the file is still there
@@ -112,14 +111,6 @@ describe('rotatePHPRuntime()', () => {
112111
fs.writeFileSync(path.join(dir, 'test.php'), `plugin-${i}`);
113112
});
114113

115-
// Create WordPress directory structure
116-
php.mkdir('/wordpress/wp-content/plugins/data-liberation');
117-
php.mkdir('/wordpress/wp-content/plugins/z-data-liberation-markdown');
118-
php.mkdir(
119-
'/wordpress/wp-content/plugins/z-data-liberation-static-files-editor'
120-
);
121-
php.mkdir('/wordpress/wp-content/uploads/static-pages');
122-
123114
// Mount the directories using WordPress paths
124115
await php.mount(
125116
'/wordpress/wp-content/plugins/data-liberation',
@@ -416,7 +407,6 @@ describe('rotatePHPRuntime()', () => {
416407

417408
php.mkdir('/test-root');
418409
php.writeFile('/test-root/index.php', 'test');
419-
php.mkdir('/test-root/nodefs');
420410

421411
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-'));
422412
const tempFile = path.join(tempDir, 'file');

packages/php-wasm/node/src/test/symlinks.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ testSymlinks.forEach(({ name, sourcePath, symlinkPath }) => {
6060
);
6161
}
6262

63-
await php.mkdir('/folder-with-symlinks');
6463
await php.mount(
6564
'/folder-with-symlinks',
6665
createNodeFsMountHandler(

packages/playground/cli/src/mounts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export function parseMountDirArguments(mounts: string[]): Mount[] {
8080

8181
export async function mountResources(php: PHP, mounts: Mount[]) {
8282
for (const mount of mounts) {
83-
php.mkdir(mount.vfsPath);
8483
await php.mount(
8584
mount.vfsPath,
8685
createNodeFsMountHandler(mount.hostPath)

packages/playground/cli/src/worker-thread.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FileLockManager } from '@php-wasm/node';
2-
import { createNodeFsMountHandler, loadNodeRuntime } from '@php-wasm/node';
2+
import { loadNodeRuntime } from '@php-wasm/node';
33
import { EmscriptenDownloadMonitor } from '@php-wasm/progress';
4-
import type { PHP, RemoteAPI, SupportedPHPVersion } from '@php-wasm/universal';
4+
import type { RemoteAPI, SupportedPHPVersion } from '@php-wasm/universal';
55
import {
66
PHPWorker,
77
consumeAPI,
@@ -14,6 +14,7 @@ import { bootWordPress } from '@wp-playground/wordpress';
1414
import { rootCertificates } from 'tls';
1515
import { jspi } from 'wasm-feature-detect';
1616
import { MessageChannel, type MessagePort, parentPort } from 'worker_threads';
17+
import { mountResources } from './mounts';
1718

1819
export interface Mount {
1920
hostPath: string;
@@ -43,13 +44,6 @@ export type PrimaryWorkerBootOptions = {
4344
internalCookieStore?: boolean;
4445
};
4546

46-
function mountResources(php: PHP, mounts: Mount[]) {
47-
for (const mount of mounts) {
48-
php.mkdir(mount.vfsPath);
49-
php.mount(mount.vfsPath, createNodeFsMountHandler(mount.hostPath));
50-
}
51-
}
52-
5347
/**
5448
* Print trace messages from PHP-WASM.
5549
*

0 commit comments

Comments
 (0)