fix(standalone): correct symlink type in node_modules on Windows - #98606
Open
jat001 wants to merge 1 commit into
Open
fix(standalone): correct symlink type in node_modules on Windows#98606jat001 wants to merge 1 commit into
jat001 wants to merge 1 commit into
Conversation
On Windows, symlinks have two distinct types (file or dir) that must be specified at creation time. In `copyTracedFiles`, when recreating symlinks in the standalone output directory, the symlink targets are relative paths resolved relative to the output location. These targets may not yet exist at creation time because files are copied in NFT trace order, not dependency order. When `fs.symlink()` is called on Windows with a non-existent target, Node.js defaults to creating a file-type symlink. This causes directory symlinks to be incorrectly created as file symlinks, breaking standalone builds that rely on directory-level symlinks (e.g., workspace packages). Fix by detecting the original file type via `tracedFilePath` (which points to the real file in the source tree) and passing the correct type explicitly to `fs.symlink()`. Add unit test in `test/production/standalone-mode/symlink-on-windows/` that directly exercises `copyTracedFiles` with both directory and file symlinks and verifies the output types are correct on Windows. Signed-off-by: Jat <chat@jat.email>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix incorrectly typed symlinks in
.next/standalone/node_moduleson Windows.Why?
On Windows,
fs.symlink()requires the type (fileordir) at creation time and defaults to file type when the target doesn't exist yet. IncopyTracedFiles, symlinks are recreated in NFT trace order (arbitrary), so directory symlink targets may not exist when the symlink is created. This causes directory symlinks to be incorrectly created as file symlinks in the standalone output.While this doesn't break runtime behavior (Windows resolves the target correctly), it produces incorrect output that can confuse tools and users inspecting the standalone directory.
How?
Detect the original file type via
tracedFilePath(which points to the real file in the source tree) and pass the correct type explicitly tofs.symlink()on Windows.Testing
Added unit test in
test/production/standalone-mode/symlink-on-windows/that directly exercisescopyTracedFileswith both directory and file symlinks and verifies the output types are correct on Windows.