summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar André Alves <71379045+andremralves@users.noreply.github.com> 2023-08-22 07:17:47 -0300
committerGravatar GitHub <noreply@github.com> 2023-08-22 11:17:47 +0100
commit5821323285646aee7ff9194a505f708028e4db57 (patch)
treec1b541822d05feaa1d0ae19e848ac0388f288828
parent179796405e053b559d83f84507e5a465861a029a (diff)
downloadastro-5821323285646aee7ff9194a505f708028e4db57.tar.gz
astro-5821323285646aee7ff9194a505f708028e4db57.tar.zst
astro-5821323285646aee7ff9194a505f708028e4db57.zip
add: config error if `outDir` is inside `publicDir` (#8152)
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
-rw-r--r--.changeset/brown-numbers-prove.md5
-rw-r--r--packages/astro/src/core/config/schema.ts2
-rw-r--r--packages/astro/test/units/config/config-validate.test.js6
3 files changed, 13 insertions, 0 deletions
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 <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;
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')
+ });
});