mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Migrate code formatting across the monorepo from Prettier to `oxfmt`
(`0.79.0`, pinned) for much faster formatting checks locally and in CI
while keeping code churn minimal (78 files total, 0.7% of the repo).
Studio's `@ianvs/prettier-plugin-sort-imports` ordering
(`<BUILTIN_MODULES>`, `<THIRD_PARTY_MODULES>`, blank line, then `@/` and
relative imports) is preserved via `oxfmt`'s native `sortImports`
override for `apps/studio/**/*.{js,jsx,ts,tsx}`.
### Performance (before vs after, uncached)
| Benchmark | Prettier (`3.8.x`) | oxfmt (`0.79.0`) | Speedup |
| --- | ---: | ---: | ---: |
| CI formatting step (`blacksmith-4vcpu-ubuntu-2404`, full repo) | `73s`
| **`7s`** | **~10×** |
| Local `apps/studio` JS/TS (`5,157` files) | `17.74s` | **`0.36s`** |
**~49×** |
| Local full monorepo (`11,131` files) | — | **`2.39s`** | — |
**Added:**
- `.oxfmtrc.jsonc` at repo root with Prettier-matching options,
`sortPackageJson: false`, the Studio `sortImports` override, and ignore
patterns migrated from `.prettierignore`
- `oxfmt` (`0.79.0` exact pin) in `pnpm-workspace.yaml` catalog and
workspace `devDependencies` / `dependencies`
- Shared `.agents/scripts/format_and_lint.sh` hook script and
`.agents/hooks.json` (used by both Claude Code and Antigravity)
**Changed:**
- Replaced `test:prettier` with `format:check` and switched `format` in
root `package.json` to `oxfmt`
- Updated `packages/api-types` (`codegen`,
`verify-production-types.mjs`), `apps/design-system` (`build:registry`),
`apps/docs` (`CodeSample.ts`, `generate-sitemap.ts`, `next.config.mjs`,
`spec/Makefile`), `apps/www` (`generate-sitemap.mjs`), and
`packages/build-icons` (`generateIconFiles.mjs`) from Prettier to
`oxfmt`
- Updated `.github/workflows/prettier.yml` (keeping the `format` job ID
intact), `.github/workflows/autofix_linters.yml`,
`.claude/settings.json`, `AGENTS.md`, `CONTRIBUTING.md`, and
`.github/copilot-instructions.md`
- Applied one-time `oxfmt` formatting pass in a separate commit (78
files: 30 `i18n/README.*.md` trailing spaces, 19 Studio files, 17 other
TS/TSX/generated types, 8 MD/MDX, 3 `package.json`, 2 example CSS files)
**Removed:**
- `prettier`, `@ianvs/prettier-plugin-sort-imports`, and
`prettier-plugin-sql-cst` from `devDependencies` (note: `.sql` files
were not part of the CI formatting glob; `eslint-config-prettier` is
kept for ESLint)
- `prettier.config.mjs`, `.prettierignore`, and
`.claude/scripts/format_and_lint.sh`
## To test
- Run `pnpm run format:check` and confirm it passes cleanly across all
matched files
- Run `pnpm --filter api-types test`, `pnpm --filter docs exec vitest
run features/directives/CodeSample.test.ts`, and `pnpm --filter www exec
vitest run generate-sitemap.test.ts`
- Edit an `apps/studio` file with out-of-order imports and run `pnpm run
format` to confirm builtin/third-party vs `@/`/relative grouping matches
prior behavior
- Check that the `Check Code Formatting` CI workflow passes on this PR
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
const ComponentStatus = z.enum([
|
|
'operational',
|
|
'degraded_performance',
|
|
'partial_outage',
|
|
'full_outage',
|
|
])
|
|
export const WorstImpactSchema = z.enum(['degraded_performance', 'partial_outage', 'full_outage'])
|
|
|
|
export const AffectedComponentSchema = z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
group_name: z.string().nullish(),
|
|
current_status: ComponentStatus.catch('degraded_performance'),
|
|
})
|
|
|
|
const Base = {
|
|
id: z.string(),
|
|
name: z.string(),
|
|
url: z.string(),
|
|
last_update_at: z.string(),
|
|
last_update_message: z.string().nullish(),
|
|
affected_components: z.array(AffectedComponentSchema).default([]),
|
|
}
|
|
|
|
export const WidgetIncidentSchema = z.object({
|
|
...Base,
|
|
status: z.enum(['investigating', 'identified', 'monitoring']).catch('investigating'),
|
|
current_worst_impact: WorstImpactSchema.catch('full_outage'),
|
|
})
|
|
|
|
export const WidgetInProgressMaintenanceSchema = z.object({
|
|
...Base,
|
|
status: z.literal('maintenance_in_progress').catch('maintenance_in_progress'),
|
|
started_at: z.string(),
|
|
scheduled_end_at: z.string().nullish(),
|
|
})
|
|
|
|
export const WidgetScheduledMaintenanceSchema = z.object({
|
|
...Base,
|
|
status: z.literal('maintenance_scheduled').catch('maintenance_scheduled'),
|
|
starts_at: z.string().nullish(),
|
|
ends_at: z.string().nullish(),
|
|
})
|
|
|
|
function tolerantArray<T extends z.ZodTypeAny>(itemSchema: T, arrayName: string) {
|
|
return z
|
|
.array(z.unknown())
|
|
.default([])
|
|
.transform((items): Array<z.output<T>> =>
|
|
items.flatMap((item) => {
|
|
const result = itemSchema.safeParse(item)
|
|
if (result.success) return [result.data]
|
|
|
|
const rawId =
|
|
typeof item === 'object' && item !== null && 'id' in item
|
|
? (item as { id?: unknown }).id
|
|
: undefined
|
|
console.warn(`incident.io Widget API: dropping malformed item in ${arrayName}`, {
|
|
id: rawId,
|
|
issues: result.error.issues,
|
|
})
|
|
return []
|
|
})
|
|
)
|
|
}
|
|
|
|
export const WidgetResponseSchema = z.object({
|
|
page_title: z.string(),
|
|
page_url: z.string(),
|
|
ongoing_incidents: tolerantArray(WidgetIncidentSchema, 'ongoing_incidents'),
|
|
in_progress_maintenances: tolerantArray(
|
|
WidgetInProgressMaintenanceSchema,
|
|
'in_progress_maintenances'
|
|
),
|
|
scheduled_maintenances: tolerantArray(WidgetScheduledMaintenanceSchema, 'scheduled_maintenances'),
|
|
})
|
|
|
|
const Annotations = { visible: z.boolean(), show_banner: z.boolean() }
|
|
|
|
export const StatusPageResponseSchema = WidgetResponseSchema.extend({
|
|
ongoing_incidents: z.array(WidgetIncidentSchema.extend(Annotations)),
|
|
in_progress_maintenances: z.array(WidgetInProgressMaintenanceSchema.extend(Annotations)),
|
|
scheduled_maintenances: z.array(
|
|
WidgetScheduledMaintenanceSchema.extend({
|
|
...Annotations,
|
|
banner_lead_days: z.number().positive().nullable(),
|
|
})
|
|
),
|
|
})
|
|
|
|
export type WidgetResponse = z.infer<typeof WidgetResponseSchema>
|
|
export type StatusPageResponse = z.infer<typeof StatusPageResponseSchema>
|
|
export type AffectedComponent = z.infer<typeof AffectedComponentSchema>
|
|
export type WorstImpact = z.infer<typeof WorstImpactSchema>
|