Add errors for unknown experimental keys (#7011)

This commit is contained in:
Reuben Tier 2023-05-18 10:39:39 +01:00 committed by GitHub
parent 6b4fcde376
commit cada10a466
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 12 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Throw an error when unknown experimental keys are present

View file

@ -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({}),

View file

@ -8,9 +8,6 @@ describe('Custom Elements', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/custom-elements/',
experimental: {
integrations: true,
},
});
await fixture.build();
});

View file

@ -3,7 +3,4 @@ import ceIntegration from '@test/custom-element-renderer';
export default defineConfig({
integrations: [ceIntegration()],
experimental: {
integrations: true
}
})

View file

@ -11,9 +11,6 @@ describe('SSR: prerender 404', () => {
root: './fixtures/ssr-prerender-404/',
output: 'server',
adapter: testAdapter(),
experimental: {
prerender: true,
},
});
await fixture.build();
});

View file

@ -12,9 +12,6 @@ describe('SSR: prerender', () => {
root: './fixtures/ssr-prerender/',
output: 'server',
adapter: testAdapter(),
experimental: {
prerender: true,
},
});
await fixture.build();
});