Skip to content

feat: better context types through codegen#15145

Closed
florian-lefebvre wants to merge 10 commits intomainfrom
feat/context-types-codegen
Closed

feat: better context types through codegen#15145
florian-lefebvre wants to merge 10 commits intomainfrom
feat/context-types-codegen

Conversation

@florian-lefebvre
Copy link
Copy Markdown
Member

@florian-lefebvre florian-lefebvre commented Jan 8, 2026

Todo

  • experimental flag
  • fonts family name codegen

Changes

  • Ported from feat: better internal types #15120
  • During sync, generates better types for APIContext and astro:config/server based on the Astro internals. For example, whether sessions are enabled or not
  • This is a backward compatible improvement
  • context.csp can now be undefined and will log a warning if accessed when not enabled, to match sessions
  • i18n has also been updated accordingly

Testing

  • Unit test
  • Types tests (required quite a few changes to avoid dts leaking)
  • Manual testing

Docs

  • Changeset
  • Docs PR

@florian-lefebvre florian-lefebvre self-assigned this Jan 8, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 8, 2026

🦋 Changeset detected

Latest commit: df22467

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Jan 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 8, 2026

⚠️ Package Trust Level Decreased

Caution

Decreased trust levels may indicate a higher risk of supply chain attacks. Please review these changes carefully.

📦 Package 🔒 Before 🔓 After
@cloudflare/kv-asset-handler trusted-with-provenance none
@cloudflare/unenv-preset trusted-with-provenance none
workerd trusted-with-provenance none
undici provenance none
miniflare trusted-with-provenance none
youch provenance none
@cloudflare/workerd-darwin-64 trusted-with-provenance none
@cloudflare/workerd-darwin-arm64 trusted-with-provenance none
@cloudflare/workerd-linux-64 trusted-with-provenance none
@cloudflare/workerd-linux-arm64 trusted-with-provenance none
@cloudflare/workerd-windows-64 trusted-with-provenance none
wrangler trusted-with-provenance none

* @message
* The `security.csp` configuration isn't enabled.
*/
export const CspNotEnabled = {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarah11918 I'd like to remove this error in v6, it was only used while csp was in experimental. Is it fine?

Copy link
Copy Markdown
Member

@sarah11918 sarah11918 Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florian-lefebvre Yes, assuming this message is about CSP being available to the user (and not whether or not csp is configured true) then makes perfect sense to remove since it will be available by default in v6!

(I know we have had discussions about whether to remove or deprecate error messages in the past, and I'm not sure where we landed on error messages used in experimental features that are not needed once the feature is stable. So to be clear, it seems like the message is OK to not have any more because it only relates to experimental, behind a flag, behaviour. Whether the solution is to remove or deprecate is a separate question. 😄 )

* [Astro reference](https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertdirective)
*/
insertDirective: (directive: CspDirective) => void;
csp: ConditionalType<
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarah11918 in this PR, context.csp may be undefined. What kind of changeset do I need? Asking given we're still in alpha so IDK if that deserves another major changeset

@florian-lefebvre
Copy link
Copy Markdown
Member Author

@Princesseuh by any chance, do you know how can I fix this TS issue? Doesn't seem to like references but I need them to properly test .d.ts in isolation

@Princesseuh
Copy link
Copy Markdown
Member

Would it work to just change the includes? It seems like you could just include the specific files you need

@florian-lefebvre
Copy link
Copy Markdown
Member Author

You mean in the root tsconfig?

@Princesseuh
Copy link
Copy Markdown
Member

No in test/types/tsconfig.json

@florian-lefebvre
Copy link
Copy Markdown
Member Author

I tried a few things but not including fixtures just means they are not typechecked at all apparently, despite the references

Base automatically changed from next to main January 30, 2026 17:31
An error occurred while trying to automatically change base from next to main January 30, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants