File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
packages/php-wasm/node/src/lib Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,31 @@ import type { MountHandler } from '@php-wasm/universal';
2
2
3
3
export function createNodeFsMountHandler ( localPath : string ) : MountHandler {
4
4
return async function ( php , FS , vfsMountPoint ) {
5
+ /**
6
+ * DON'T MERGE THIS.
7
+ * This is a temporary workaround to demonstrate how mounting requires the mount point to be a directory.
8
+ *
9
+ * Emscripten requires the mount point to be a directory.
10
+ * By creating a directory we can even mount a file over it as long as the paths match.
11
+ * PHP-WASM source: https://github.com/WordPress/wordpress-playground/blob/trunk/packages/php-wasm/node/asyncify/php_8_0.js#L2679
12
+ *
13
+ * When Emscripten attempt to mount a local path into VFS, it looks up the path
14
+ * and adds the local path as a mount to the VFS Node.
15
+ * PHP-WASM source: https://github.com/WordPress/wordpress-playground/blob/trunk/packages/php-wasm/node/asyncify/php_8_0.js#L2700
16
+ *
17
+ * For mounting to work, the Node must exist in VFS and be a directory.
18
+ * If the Node doesn't exist, the mount fails with error 44 (MEMFS.doesNotExistError).
19
+ * PHP-WASM source: https://github.com/WordPress/wordpress-playground/blob/trunk/packages/php-wasm/node/asyncify/php_8_0.js#L1201
20
+ */
21
+ try {
22
+ FS . lookupPath ( vfsMountPoint ) ;
23
+ } catch ( e ) {
24
+ // FS.lookupPath will throw an error if the path doesn't exist.
25
+ FS . mkdirTree ( vfsMountPoint ) ;
26
+ }
5
27
FS . mount ( FS . filesystems [ 'NODEFS' ] , { root : localPath } , vfsMountPoint ) ;
6
28
return ( ) => {
29
+ // TODO: Delete the mount point if was created during the mount.
7
30
FS ! . unmount ( vfsMountPoint ) ;
8
31
} ;
9
32
} ;
You can’t perform that action at this time.
0 commit comments