Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vite build now works with broken symlink in public #18592

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crutchcorn
Copy link

Description

This PR solves the problem of breaking vite build when having a broken symlink inside of the public folder.

This occurs because stat treats symlinks as isDirectory() === true and breaks with a "Not found" error when it attempts to copy

A reproduction of this issue can be found here:

https://github.com/crutchcorn/broken-symblink-copy-demo

@crutchcorn crutchcorn changed the title fix: Vite build now works with broken symlink in public fix: vite build now works with broken symlink in public Nov 6, 2024
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

But in the first place, why do you have a broken symlink in public directory? If there's a broken symlink, then shouldn't Vite error and tell the user that Vite wasn't able to copy the content? 🤔

@@ -598,6 +598,10 @@ export function copyDir(srcDir: string, destDir: string): void {
continue
}
const destFile = path.resolve(destDir, file)
// This may occur if the source directory is a symlink that points to a non-existent directory
if (!fs.existsSync(destFile)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be

Suggested change
if (!fs.existsSync(destFile)) {
if (!fs.existsSync(srcFile)) {

Also I think it'd nice to avoid this existsSync call and add an try-catch to fs.statSync instead. fs.statSync throwed ENOENT on my machine (both Windows and WSL), did fs.statSync return a result on your machine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants