Skip to content

[Node] Handle symlinked directories in Node FS mounts - #3551

Merged
adamziel merged 1 commit into
trunkfrom
codex/node-fs-mount-symlink-directories
Apr 28, 2026
Merged

[Node] Handle symlinked directories in Node FS mounts#3551
adamziel merged 1 commit into
trunkfrom
codex/node-fs-mount-symlink-directories

Conversation

@adamziel

@adamziel adamziel commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

What it does

Makes NodeFSMountHandler preserve symlinked directories as directories when mounting host paths into PHP.wasm.

Rationale

lstatSync() reports the symlink itself, so a symlink pointing at a directory was treated like a file. statSync() fixes the placeholder decision, but NODEFS also reads the mount root path. Passing the original symlink path still leaves the mounted root shaped like the symlink.

Implementation

Resolves localPath with realpathSync() before creating the VFS placeholder and before calling FS.mount(). The placeholder is then created from statSync(mountRoot), and NODEFS receives the resolved root path.

Added a regression test that checks the actual mounted VFS node mode for both normal directories and symlinked directories. Before this PR, the symlinked-directory case produced a non-directory mount node.

Testing instructions

Focused checks run locally:

npx vitest run --config packages/php-wasm/node/vite.config.ts packages/php-wasm/node/src/test/mount.spec.ts
npx vitest run --config packages/php-wasm/node/vite.jspi.config.ts packages/php-wasm/node/src/test/mount.spec.ts

CI group checks run locally:

npx nx run php-wasm-node:test-group-3-asyncify
npx nx run php-wasm-node:test-group-3-jspi
@adamziel
adamziel force-pushed the codex/node-fs-mount-symlink-directories branch 2 times, most recently from ecf7425 to f62276b Compare April 28, 2026 18:29
@adamziel adamziel added the [Type] Bug An existing feature does not function as intended label Apr 28, 2026
@adamziel
adamziel marked this pull request as ready for review April 28, 2026 18:36
@adamziel
adamziel requested review from a team, Copilot and zaerl April 28, 2026 18:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates NodeFSMountHandler to treat symlinked directories as directories in the VFS by following symlinks when creating mount-point placeholders, and adds a regression test for unmount cleanup when the mounted directory is the CWD.

Changes:

  • Switch placeholder type detection from lstatSync() to statSync() to follow symlinks.
  • Add a regression test ensuring directory-cleanup guard triggers when CWD is inside the mounted directory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/php-wasm/node/src/lib/node-fs-mount.ts Uses statSync() so symlinked dirs get directory placeholders; adds an explanatory inline comment.
packages/php-wasm/node/src/test/mount.spec.ts Adds a regression test covering unmount cleanup behavior when the mount is the current working directory.
Comments suppressed due to low confidence (1)

packages/php-wasm/node/src/lib/node-fs-mount.ts:39

  • This error message is misleading given the new implementation: the check is now based on statSync() (which resolves symlinks), so the failure can occur for non-symlink paths and the message doesn’t reflect the actual supported mount targets. Consider rewording to something like “supports mounting only files and directories (including symlinks to files/directories)” to match the behavior.
				throw new Error(
					'Unsupported file type. PHP-wasm supports only symlinks that link to files, directories, or symlinks.'
				);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/php-wasm/node/src/test/mount.spec.ts Outdated
Comment thread packages/php-wasm/node/src/lib/node-fs-mount.ts Outdated
@adamziel
adamziel force-pushed the codex/node-fs-mount-symlink-directories branch 2 times, most recently from 1e66db5 to 21e9fd1 Compare April 28, 2026 19:37
@adamziel
adamziel force-pushed the codex/node-fs-mount-symlink-directories branch from 21e9fd1 to 5f34205 Compare April 28, 2026 19:45
@adamziel adamziel changed the title Handle symlinked directories in Node FS mounts Apr 28, 2026
@adamziel
adamziel merged commit 05692e1 into trunk Apr 28, 2026
47 of 48 checks passed
@adamziel
adamziel deleted the codex/node-fs-mount-symlink-directories branch April 28, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Aspect] Node.js [Package][@php-wasm] Node [Type] Bug An existing feature does not function as intended

2 participants