diff --git a/.changeset/brown-numbers-prove.md b/.changeset/brown-numbers-prove.md new file mode 100644 index 000000000..96db75af0 --- /dev/null +++ b/.changeset/brown-numbers-prove.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Displays a new config error if `outDir` is placed within `publicDir`. diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 87ff7ba9f..174bfab3b 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -410,6 +410,8 @@ A future version of Astro will stop using the site pathname when producing !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; diff --git a/packages/astro/test/units/config/config-validate.test.js b/packages/astro/test/units/config/config-validate.test.js index 49fd6b418..b9b5edd77 100644 --- a/packages/astro/test/units/config/config-validate.test.js +++ b/packages/astro/test/units/config/config-validate.test.js @@ -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') + }); });