Skip to content

Commit

Permalink
Add errors for unknown experimental keys (#7011)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOtterlord authored May 18, 2023
1 parent 6b4fcde commit cada10a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-eggs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Throw an error when unknown experimental keys are present
11 changes: 11 additions & 0 deletions packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ export const AstroConfigSchema = z.object({
middleware: z.oboolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.middleware),
hybridOutput: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.hybridOutput),
})
.passthrough()
.refine(d => {
const validKeys = Object.keys(ASTRO_CONFIG_DEFAULTS.experimental)
const invalidKeys = Object.keys(d).filter(key => !validKeys.includes(key))
if (invalidKeys.length > 0) return false
return true
}, d => {
const validKeys = Object.keys(ASTRO_CONFIG_DEFAULTS.experimental)
const invalidKeys = Object.keys(d).filter(key => !validKeys.includes(key))
return { message: `Invalid experimental key: \`${invalidKeys.join(', ')}\`. \nMake sure the spelling is correct, and that your Astro version supports this experiment.\nSee https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for more information.` };
})
.optional()
.default({}),
legacy: z.object({}).optional().default({}),
Expand Down
3 changes: 0 additions & 3 deletions packages/astro/test/custom-elements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ describe('Custom Elements', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/custom-elements/',
experimental: {
integrations: true,
},
});
await fixture.build();
});
Expand Down
3 changes: 0 additions & 3 deletions packages/astro/test/fixtures/custom-elements/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ import ceIntegration from '@test/custom-element-renderer';

export default defineConfig({
integrations: [ceIntegration()],
experimental: {
integrations: true
}
})
3 changes: 0 additions & 3 deletions packages/astro/test/ssr-prerender-404.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ describe('SSR: prerender 404', () => {
root: './fixtures/ssr-prerender-404/',
output: 'server',
adapter: testAdapter(),
experimental: {
prerender: true,
},
});
await fixture.build();
});
Expand Down
3 changes: 0 additions & 3 deletions packages/astro/test/ssr-prerender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ describe('SSR: prerender', () => {
root: './fixtures/ssr-prerender/',
output: 'server',
adapter: testAdapter(),
experimental: {
prerender: true,
},
});
await fixture.build();
});
Expand Down

0 comments on commit cada10a

Please sign in to comment.