mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The CLI reads `supabase/config.jsonc` (and `config.json`) since v3.1.0, but every docs page still shows `config.toml` only. There's also no page explaining the formats, how to switch, the `$schema` / `#:schema` declaration, or editor setup, and no reference pages for the new `supabase config convert` and `supabase config validate` commands. Linear: CLI-2871 ## Solution - **Dual-format examples from one source.** A new directive (`features/directives/ConfigFormats.ts`) picks up any ```` ```toml ```` fence with `name=supabase/config.toml` and renders it as `supabase/config.toml` / `supabase/config.jsonc` tabs. The JSONC is generated at build time with `convertCliConfigTomlToJsonc` from `@supabase/config`, the same converter `supabase config convert` uses, so authors only write TOML and the JSONC matches what the CLI would produce (comments included). Inside `<$CodeTabs>` the JSONC is added as an extra tab. - **The format choice sticks.** `ConfigCodeTabs` keeps the selected format in `localStorage`, so choosing JSONC switches every config example on the page and on later pages. - **Config reference.** The `usage` examples on `/guides/local-development/cli/config` use the same tabs (they were highlighted as Python before), and the intro mentions `config.jsonc`. The `remotes.<branch_name>` example now uses `[remotes.staging]`, since `<branch_name>` isn't a valid TOML key. - **New guide, "Config file formats"** (`/guides/local-development/cli/config-formats`): which file wins, minimum CLI version, `convert` and `validate`, schema declaration and versioning, and editor setup (VS Code trusted domains, Even Better TOML, Tombi, SchemaStore). - **CLI reference.** Adds `supabase-config-convert` and `supabase-config-validate` to the CLI reference nav. `cli_v1_commands.yaml` is the generated v3.2.0 reference, identical to the release bot's update in #53463, so the two PRs don't conflict. - **Content.** About 60 existing config examples across the guides, including the Branching configuration page, are tagged `name=supabase/config.toml`. Branching reads `config.json` and `config.jsonc` as well, and the Branching configuration page now says so. Non-Supabase TOML (`pyproject.toml`, `bunfig.toml`) and the v2-era `[inbucket]` before/after snippet stay TOML-only. - **Format-neutral prose.** Sentences that described the config as `config.toml` now say "your config file", naming `supabase/config.toml` and `supabase/config.jsonc` once per page. TOML section syntax in prose (`max_frequency` under `[auth.email]`) is written as key paths (`auth.email.max_frequency`), which read the same in both formats. Headings that named `config.toml` keep their old anchors. Sentences about what `supabase init` creates still say `config.toml`. - **Markdown export for agents.** `internals/generate-guides-markdown.ts` runs the same transform, so the `.md` pages served to AI agents include the JSONC example after each TOML one. - A test converts every tagged example under `content/`, so a broken TOML example fails tests instead of the build. New dependencies for `apps/docs`: `@supabase/config` (^1.8.0) and `effect` (the same `effect` version Studio pins). `config convert` and `config validate` ship in CLI v3.2.0, which is now stable. ## Review instructions 1. Open `/docs/guides/local-development/seeding-your-database` on the preview. Switch an example to `supabase/config.jsonc` and check the other examples on the page switch too. 2. Open `/docs/guides/local-development/cli/config` and check the usage examples open on JSONC. 3. Read `/docs/guides/local-development/cli/config-formats`. 4. Open `/docs/reference/cli/supabase-config-convert` and `/docs/reference/cli/supabase-config-validate`. ## Self-review Ran the `review-the-docs` local self-review (content, pipeline, and component checks) over the 54 changed pages. - No blockers. Fixed the nits it found: leftover TOML section syntax in prose (diff engines, declarative schemas, Branching, the common settings table on Local and hosted projects), a few long or ungrammatical sentences, and the conversion follow-up steps on Config file formats, now a list. - Links, custom anchors, nav wiring, and frontmatter check out. - The `.md` export on the preview shows each TOML example followed by its JSONC version. - `test-the-docs` deferred: the changed fences are config snippets, and `ConfigFormats.test.ts` already converts every tagged example. No procedural steps changed apart from the `config convert` and `config validate` commands on the new page. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
121 lines
4.0 KiB
TypeScript
121 lines
4.0 KiB
TypeScript
/**
|
|
* The ConfigFormats transform renders `supabase/config.toml` examples in both
|
|
* TOML and JSONC. A TOML fence opts in by naming the file, either as
|
|
* ```` ```toml supabase/config.toml ```` or ```` ```toml name=supabase/config.toml ````:
|
|
*
|
|
* - inside `<$CodeTabs>`, a `supabase/config.jsonc` fence is added as a tab
|
|
* - anywhere else, the fence becomes a `CodeTabs` with both formats, synced
|
|
* across the page through the `config-format` query group
|
|
*/
|
|
|
|
import { CliConfigConvertError, convertCliConfigTomlToJsonc } from '@supabase/config/convert'
|
|
import { type Code, type Parent, type Root } from 'mdast'
|
|
import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx'
|
|
import { visitParents } from 'unist-util-visit-parents'
|
|
|
|
export const CONFIG_TOML_NAME = 'supabase/config.toml'
|
|
export const CONFIG_JSONC_NAME = 'supabase/config.jsonc'
|
|
export const CONFIG_FORMAT_QUERY_GROUP = 'config-format'
|
|
|
|
const SCHEMA_MEMBER = /^\{\n {2}"\$schema": "[^"]*",\n\n?/
|
|
|
|
export function convertConfigTomlToJsonc(source: string): string {
|
|
try {
|
|
const { text, schemaSource } = convertCliConfigTomlToJsonc(source)
|
|
return (schemaSource === 'default' ? text.replace(SCHEMA_MEMBER, '{\n') : text).trimEnd()
|
|
} catch (error) {
|
|
if (!(error instanceof CliConfigConvertError)) throw error
|
|
const { reason, detail, sourceLine } = error
|
|
const firstLine = source.split('\n').find((line) => line.trim() !== '') ?? ''
|
|
throw new Error(
|
|
`Could not convert config.toml snippet to JSONC (${reason}: ${detail}` +
|
|
`${sourceLine === undefined ? '' : `, line ${sourceLine}`}). ` +
|
|
`Snippet starts with: ${firstLine}`
|
|
)
|
|
}
|
|
}
|
|
|
|
export function configFormatsRemark() {
|
|
return function transform(tree: Root) {
|
|
const targets: Array<{ node: Code; parent: Parent }> = []
|
|
visitParents(tree, 'code', (node: Code, ancestors: Array<Parent>) => {
|
|
if (isConfigToml(node)) {
|
|
targets.push({ node, parent: ancestors[ancestors.length - 1] })
|
|
}
|
|
})
|
|
|
|
for (const { node, parent } of targets) {
|
|
const jsonc = convertConfigTomlToJsonc(node.value)
|
|
const index = parent.children.indexOf(node)
|
|
|
|
if (isCodeTabs(parent)) {
|
|
node.meta = [`name=${CONFIG_TOML_NAME}`, stripName(node.meta)].filter(Boolean).join(' ')
|
|
parent.children.splice(index + 1, 0, {
|
|
type: 'code',
|
|
lang: 'jsonc',
|
|
meta: `name=${CONFIG_JSONC_NAME}`,
|
|
value: jsonc,
|
|
})
|
|
} else {
|
|
const meta = stripName(node.meta)
|
|
parent.children.splice(
|
|
index,
|
|
1,
|
|
configCodeTabs([
|
|
tabPanel('toml', CONFIG_TOML_NAME, { ...node, meta }),
|
|
tabPanel('jsonc', CONFIG_JSONC_NAME, {
|
|
type: 'code',
|
|
lang: 'jsonc',
|
|
meta,
|
|
value: jsonc,
|
|
}),
|
|
])
|
|
)
|
|
}
|
|
}
|
|
|
|
return tree
|
|
}
|
|
}
|
|
|
|
function isConfigToml(node: Code) {
|
|
return node.lang === 'toml' && node.meta?.split(/\s+/).some(isConfigTomlName) === true
|
|
}
|
|
|
|
function isConfigTomlName(token: string) {
|
|
return token === CONFIG_TOML_NAME || token === `name=${CONFIG_TOML_NAME}`
|
|
}
|
|
|
|
function isCodeTabs(node: Parent) {
|
|
return node.type === 'mdxJsxFlowElement' && (node as MdxJsxFlowElement).name === '$CodeTabs'
|
|
}
|
|
|
|
function stripName(meta: string | null | undefined) {
|
|
const rest = meta
|
|
?.split(/\s+/)
|
|
.filter((token) => token && !token.startsWith('name=') && !isConfigTomlName(token))
|
|
.join(' ')
|
|
return rest || null
|
|
}
|
|
|
|
function tabPanel(id: string, label: string, code: Code): MdxJsxFlowElement {
|
|
return {
|
|
type: 'mdxJsxFlowElement',
|
|
name: 'TabPanel',
|
|
attributes: [
|
|
{ type: 'mdxJsxAttribute', name: 'id', value: id },
|
|
{ type: 'mdxJsxAttribute', name: 'label', value: label },
|
|
],
|
|
children: [code],
|
|
}
|
|
}
|
|
|
|
function configCodeTabs(children: Array<MdxJsxFlowElement>): MdxJsxFlowElement {
|
|
return {
|
|
type: 'mdxJsxFlowElement',
|
|
name: 'CodeTabs',
|
|
attributes: [{ type: 'mdxJsxAttribute', name: 'queryGroup', value: CONFIG_FORMAT_QUERY_GROUP }],
|
|
children,
|
|
}
|
|
}
|