Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ff257df

Browse filesBrowse files
florian-lefebvreematipicodelucissarah11918
authored
feat: move astro config validation after astro:config:setup (#13482)
* feat: move astro config validation after astro:config:setup * feat: superRefine * fix: test * feat: update test * feat: update test * fix: test * feat: feedback * feat: improve logging * feat: refactor * fix: no spread * feat: split schemas * chore: changeset * Update packages/astro/src/core/config/schemas/README.md Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> * Update packages/astro/src/integrations/hooks.ts * Update packages/astro/src/core/config/schemas/README.md * Update .changeset/easy-vans-laugh.md * Update .changeset/easy-vans-laugh.md * grammar nit in changeset --------- Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com> Co-authored-by: delucis <357379+delucis@users.noreply.github.com> Co-authored-by: sarah11918 <5098874+sarah11918@users.noreply.github.com>
1 parent 4db2c68 commit ff257df
Copy full SHA for ff257df

File tree

Expand file treeCollapse file tree

16 files changed

+864
-848
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

16 files changed

+864
-848
lines changed
Open diff view settings
Collapse file

‎.changeset/easy-vans-laugh.md‎

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'astro': minor
3+
---
4+
5+
Updates Astro config validation to also run for the Integration API. An error log will specify which integration is failing the validation.
6+
7+
Now, Astro will first validate the user configuration, then validate the updated configuration after each integration `astro:config:setup` hook has run. This means `updateConfig()` calls will no longer accept invalid configuration.
8+
9+
This fixes a situation where integrations could potentially update a project with a malformed configuration. These issues should now be caught and logged so that you can update your integration to only set valid configurations.
Collapse file

‎.changeset/three-masks-see.md‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'astro': minor
3+
---
4+
5+
Improves integrations error handling
6+
7+
If an error is thrown from an integration hook, an error log will now provide information about the concerned integration and hook
Collapse file

‎packages/astro/src/container/index.ts‎

Copy file name to clipboardExpand all lines: packages/astro/src/container/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './polyfill.js';
22
import { posix } from 'node:path';
33
import { getDefaultClientDirectives } from '../core/client-directive/index.js';
4-
import { ASTRO_CONFIG_DEFAULTS } from '../core/config/schema.js';
4+
import { ASTRO_CONFIG_DEFAULTS } from '../core/config/schemas/index.js';
55
import { validateConfig } from '../core/config/validate.js';
66
import { createKey } from '../core/encryption.js';
77
import { Logger } from '../core/logger/core.js';
Collapse file

‎packages/astro/src/core/build/index.ts‎

Copy file name to clipboardExpand all lines: packages/astro/src/core/build/index.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class AstroBuilder {
173173

174174
/** Run the build logic. build() is marked private because usage should go through ".run()" */
175175
private async build({ viteConfig }: { viteConfig: vite.InlineConfig }) {
176-
await runHookBuildStart({ config: this.settings.config, logging: this.logger });
176+
await runHookBuildStart({ config: this.settings.config, logger: this.logger });
177177
this.validateConfig();
178178

179179
this.logger.info('build', `output: ${blue('"' + this.settings.config.output + '"')}`);
@@ -248,7 +248,7 @@ class AstroBuilder {
248248
.flat()
249249
.map((pageData) => pageData.route)
250250
.concat(hasServerIslands ? getServerIslandRouteData(this.settings.config) : []),
251-
logging: this.logger,
251+
logger: this.logger,
252252
});
253253

254254
if (this.logger.level && levels[this.logger.level()] <= levels['info']) {
Collapse file

‎packages/astro/src/core/config/index.ts‎

Copy file name to clipboardExpand all lines: packages/astro/src/core/config/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export {
66
} from './config.js';
77
export { createNodeLogger } from './logging.js';
88
export { mergeConfig } from './merge.js';
9-
export type { AstroConfigType } from './schema.js';
9+
export type { AstroConfigType } from './schemas/index.js';
1010
export { createSettings } from './settings.js';
1111
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
Collapse file
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Config schemas
2+
3+
There are 3 zod schemas needed to validate the Astro config properly:
4+
5+
- `AstroConfigSchema` (base): a schema that matches the `AstroConfig` type
6+
- `createRelativeSchema` (relative): a function that uses the base schema, and adds transformations relative to the project root. Transformations occur at runtime, and the paths are resolved against the `cwd` of the CLI.
7+
- `AstroConfigRefinedSchema` (refined): a schema that handles extra validations. Due to constraints imposed by the Astro architecture, refinements can't be done on the `AstroConfig` schema because integrations deal with the output of the `AstroConfig` schema. As a result, this schema runs after parsing the user config and after every integration `astro:config:setup` hook (to make sure `updateConfig() has been called with valid config)`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.