add: config error if outDir is inside publicDir (#8152)

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
André Alves 2023-08-22 07:17:47 -03:00 committed by GitHub
parent 179796405e
commit 5821323285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Displays a new config error if `outDir` is placed within `publicDir`.

View file

@ -410,6 +410,8 @@ A future version of Astro will stop using the site pathname when producing <link
}
return config;
}).refine((obj) => !obj.outDir.toString().startsWith(obj.publicDir.toString()), {
message: '`outDir` must not be placed inside `publicDir` to prevent an infinite loop. Please adjust the directory configuration and try again'
});
return AstroConfigRelativeSchema;

View file

@ -68,4 +68,10 @@ describe('Config Validation', () => {
).catch((err) => err);
expect(configError).to.be.not.instanceOf(Error);
});
it('Error when outDir is placed within publicDir', async () => {
const configError = await validateConfig({ outDir: './public/dist' }, process.cwd()).catch((err) => err);
expect(configError instanceof z.ZodError).to.equal(true);
expect(configError.errors[0].message).to.equal('`outDir` must not be placed inside `publicDir` to prevent an infinite loop. \
Please adjust the directory configuration and try again')
});
});