Skip to content

Commit

Permalink
add: config error if outDir is inside publicDir (#8152)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
  • Loading branch information
andremralves and natemoo-re committed Aug 22, 2023
1 parent 1797964 commit 5821323
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-numbers-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Displays a new config error if `outDir` is placed within `publicDir`.
2 changes: 2 additions & 0 deletions packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/units/config/config-validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
});

0 comments on commit 5821323

Please sign in to comment.