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: warn when publicDir and outDir are nested #13742

Merged
merged 6 commits into from Jul 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/vite/src/node/build.ts
Expand Up @@ -753,7 +753,21 @@ function prepareOutDir(
config.publicDir &&
fs.existsSync(config.publicDir)
) {
copyDir(config.publicDir, outDir)
if (areSeparateFolders(outDir, config.publicDir)) {
ArnaudBarre marked this conversation as resolved.
Show resolved Hide resolved
copyDir(config.publicDir, outDir)
} else {
config.logger.warn(
colors.yellow(
`\n${colors.bold(
`(!)`,
)} The public directory feature is diabled. outDir ${colors.white(
patak-dev marked this conversation as resolved.
Show resolved Hide resolved
colors.dim(outDir),
)} and publicDir ${colors.white(
colors.dim(config.publicDir),
)} are not separate folders.\n`,
),
)
}
}
}
}
Expand Down Expand Up @@ -1223,3 +1237,15 @@ export function toOutputFilePathWithoutRuntime(

export const toOutputFilePathInCss = toOutputFilePathWithoutRuntime
export const toOutputFilePathInHtml = toOutputFilePathWithoutRuntime

function isSameOrSubfolder(parent: string, dir: string) {
const relative = path.relative(parent, dir)
return (
relative === '' ||
(!relative.startsWith('..') && !path.isAbsolute(relative))
)
}

function areSeparateFolders(a: string, b: string) {
return !isSameOrSubfolder(a, b) && !isSameOrSubfolder(b, a)
}