* Fix the error for babel/preset-typescript in docs.
* Unfix the version.
* Try using amaro for type stripping.
* Run prettier after stripping types.
* Fix tests.
---------
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
* feat(docs): code samples with ts type stripping
Introduce a new option to `$CodeSample`, `convertToJs`, which takes a
code sample written in TypeScript and strips the types to produce a
JavaScript version.
Adds tests for type stripping.
* Clarify instructions
---------
Co-authored-by: Chris Chinchilla <chris@chrischinchilla.com>
* General updates and switch to Svelte 5
* Update code example to Svelte 5
* Update some examples to use codesamples component
* Add Svelte to codesample component
* Final code updates
* Add more CodeSample components
strictNullChecks was off for docs, which lets errors slip through and
leads to incorrect required/optional typing on Zod-inferred types. This
PR enables strictNullChecks and fixes all the existing violations.
Correct the code examples for the Clerk third-party auth docs:
- Fix TypeScript error
- Change RLS policy check to accept both [Clerk v1 and v2
JWTs](https://clerk.com/docs/backend-requests/resources/session-tokens)
Pulled code samples from an example app that I've checked in to make
maintenance and testing easier in the future.
Partials are currently defined via MDX includes. This PR switches to pre-compile-time partials, which have a new syntax:
```
<$Partial path="path/to/file.mdx" />
```
## Rationale
This produces two improvements:
1. Partial substitution can occur in pipelines that don't use MDX compilation. For example, we can now do partial substitution before building the search index, so partial content will also be indexed.
2. After the App Router migration, the MDXProviders should've been deprecated, but were kept around for the sole reason of making partials work, and leading to us shipping unnecessary client-side code. We get a minor decrease in overall client bundle size (5.74 MB to 5.6 MB) by getting rid of the Providers.
## Breaking changes
Besides the change to partial syntax, the arguments are also less powerful than before because we are doing string substitution and don't have the full power of JS. Defining string variables is still possible (documented in the Contributing guide), and since that's all we actually do in practice, this shouldn't be too cumbersome. There is always the escape hatch of making a custom component for more complex content reuse cases.
Pages incorporating an external code sample on local dev will fail for contributors without the GitHub API key. This PR fixes the local DX by replacing such code samples with a local-only message describing the error, and asking contributors to check the preview site.
We allow fetching external data in CodeSamples into a MDX environment, so we have to be careful about preventing code execution.
Current checks:
- External data is inserted as a code block (via the AST, not direct string manipulation), so it is escaped.
Added two new layers of checks:
- Allow-list of organizations, currently set to Supabase-only
- Only allow immutable commit references
Add the ability to embed code samples from GitHub into tutorials, so we can have a single source of truth for the source code.
Introduces the <$CodeSample /> syntax, which is a special syntax and not a real React component (see the directives/README.md for why on earth I did it this way -- in this specific case, CodeHike adjusts the MDX syntax tree before it gets compiled, and we need to adjust it ourselves before CodeHike sees it, so we need to get down to the level of manipulating the AST in order to make this work with CodeHike).
Adjusted one of the example tutorials to use this new feature as a test.