Files
supabase/apps/docs/features/directives/ConfigFormats.test.ts
Colum Ferry 95cf9a78a7 docs(cli): show config examples in TOML and JSONC (#53449)
## 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)
2026-11-20 14:34:59 +00:00

192 lines
4.7 KiB
TypeScript

import { readFileSync } from 'fs'
import { join } from 'path'
import fg from 'fast-glob'
import { mdxToMarkdown } from 'mdast-util-mdx'
import { toMarkdown } from 'mdast-util-to-markdown'
import { describe, expect, it } from 'vitest'
import { codeTabsRemark } from './CodeTabs'
import { configFormatsRemark, convertConfigTomlToJsonc } from './ConfigFormats'
import { fromDocsMarkdown } from './utils.server'
async function render(mdx: string, { withCodeTabs = false } = {}) {
let mdast = fromDocsMarkdown(mdx.trim())
mdast = configFormatsRemark()(mdast)
if (withCodeTabs) mdast = codeTabsRemark()(mdast)
return toMarkdown(mdast, { extensions: [mdxToMarkdown()] })
}
describe('ConfigFormats', () => {
it.each([
['positional', 'supabase/config.toml'],
['name=', 'name=supabase/config.toml'],
])('should render a standalone config.toml fence (%s) as synced CodeTabs', async (_, meta) => {
const output = await render(`
\`\`\`toml ${meta}
[auth]
enabled = true
\`\`\`
`)
expect(output).toEqual(
`
<CodeTabs queryGroup="config-format">
<TabPanel id="toml" label="supabase/config.toml">
\`\`\`toml
[auth]
enabled = true
\`\`\`
</TabPanel>
<TabPanel id="jsonc" label="supabase/config.jsonc">
\`\`\`jsonc
{
"auth": {
"enabled": true
}
}
\`\`\`
</TabPanel>
</CodeTabs>
`.trimStart()
)
})
it.each([
['positional', 'supabase/config.toml'],
['name=', 'name=supabase/config.toml'],
])('should add a jsonc tab to a config.toml fence (%s) inside CodeTabs', async (_, meta) => {
const output = await render(
`
<$CodeTabs>
\`\`\`toml ${meta}
[auth]
enabled = true
\`\`\`
\`\`\`ts name=index.ts
console.log('hi')
\`\`\`
</$CodeTabs>
`,
{ withCodeTabs: true }
)
expect(output).toEqual(
`
<CodeTabs>
<TabPanel id="supabase/config.toml" label="supabase/config.toml">
\`\`\`toml name=supabase/config.toml
[auth]
enabled = true
\`\`\`
</TabPanel>
<TabPanel id="supabase/config.jsonc" label="supabase/config.jsonc">
\`\`\`jsonc name=supabase/config.jsonc
{
"auth": {
"enabled": true
}
}
\`\`\`
</TabPanel>
<TabPanel id="index.ts" label="index.ts">
\`\`\`ts name=index.ts
console.log('hi')
\`\`\`
</TabPanel>
</CodeTabs>
`.trimStart()
)
})
it('should wrap config.toml fences nested in lists', async () => {
const output = await render(`
1. Edit the config:
\`\`\`toml supabase/config.toml
[auth]
enabled = true
\`\`\`
`)
expect(output).toContain('<CodeTabs queryGroup="config-format">')
expect(output).toContain('```jsonc')
})
it('should leave unnamed and differently named TOML untouched', async () => {
const mdx = `
\`\`\`toml
[auth]
enabled = true
\`\`\`
\`\`\`toml name=pyproject.toml
[tool.poetry]
name = "x"
\`\`\`
\`\`\`toml supabase/functions/config.toml
[x]
y = 1
\`\`\`
`.trim()
expect(await render(mdx)).toEqual(
toMarkdown(fromDocsMarkdown(mdx), { extensions: [mdxToMarkdown()] })
)
})
it('should drop the generated $schema for snippets', async () => {
const jsonc = convertConfigTomlToJsonc('[auth]\nenabled = true\n')
expect(jsonc).not.toContain('$schema')
})
it('should keep $schema when the source declares one', async () => {
const jsonc = convertConfigTomlToJsonc(
'#:schema https://supabase.com/schemas/config/v1.json\n\n[auth]\nenabled = true\n'
)
expect(jsonc).toContain('"$schema"')
})
it('should carry comments, including commented-out keys', async () => {
const jsonc = convertConfigTomlToJsonc(
'# Auth settings\n[auth]\nenabled = true\n# site_url = "http://localhost:3000"\n'
)
expect(jsonc).toContain('// Auth settings')
expect(jsonc).toContain('// "site_url": "http://localhost:3000",')
})
it('should throw a useful error for an unconvertible snippet', async () => {
expect(() => convertConfigTomlToJsonc('\n[auth\nenabled = true\n')).toThrowError(
/parse_error.*\[auth/s
)
})
it('should convert every config.toml fence in the docs content', async () => {
const contentDir = join(__dirname, '../../content')
const files = await fg('**/*.mdx', { cwd: contentDir, absolute: true })
const failures: Array<string> = []
let converted = 0
for (const file of files) {
const source = readFileSync(file, 'utf-8')
const fences = source.match(/^\s*```toml (name=)?supabase\/config\.toml\b/gm) ?? []
if (fences.length === 0) continue
try {
configFormatsRemark()(fromDocsMarkdown(source))
converted += fences.length
} catch (err) {
failures.push(`${file}: ${(err as Error).message}`)
}
}
expect(failures).toEqual([])
expect(converted).toBeGreaterThan(0)
})
})