mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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>
132 lines
4.6 KiB
TypeScript
132 lines
4.6 KiB
TypeScript
import '@xyflow/react/dist/style.css'
|
|
|
|
import {
|
|
Background,
|
|
ColorMode,
|
|
Edge,
|
|
EdgeTypes,
|
|
Node,
|
|
NodeTypes,
|
|
ReactFlow,
|
|
useNodesInitialized,
|
|
useReactFlow,
|
|
} from '@xyflow/react'
|
|
import { useTheme } from 'next-themes'
|
|
import { useEffect, useEffectEvent, useState } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
import { getDagreGraphLayout } from './InstanceConfiguration.utils'
|
|
import { timeout } from '@/lib/helpers'
|
|
|
|
interface DiagramFlowProps {
|
|
nodes: Node[]
|
|
edges: Edge[]
|
|
nodeTypes: NodeTypes
|
|
edgeTypes: EdgeTypes
|
|
/** Prepends background group nodes (regions, shards) after the dagre layout runs */
|
|
addGroupNodes: (nodes: Node[], edges: Edge[]) => { nodes: Node[]; edges: Edge[] }
|
|
ranksep?: number
|
|
}
|
|
|
|
/**
|
|
* Shared React Flow canvas for the infrastructure diagrams, laid out with a
|
|
* two-pass measured dagre layout: the first pass uses fallback heights while
|
|
* the diagram is held invisible, then `useNodesInitialized` triggers a second
|
|
* pass that re-runs dagre with the real measured node heights before fading
|
|
* the diagram in. Must be rendered inside a `ReactFlowProvider`.
|
|
*/
|
|
export const DiagramFlow = ({
|
|
nodes,
|
|
edges,
|
|
nodeTypes,
|
|
edgeTypes,
|
|
addGroupNodes,
|
|
ranksep,
|
|
}: DiagramFlowProps) => {
|
|
const reactFlow = useReactFlow()
|
|
const { resolvedTheme } = useTheme()
|
|
const nodesInitialized = useNodesInitialized()
|
|
const [hasMeasuredLayout, setHasMeasuredLayout] = useState(false)
|
|
|
|
const backgroundPatternColor =
|
|
resolvedTheme === 'dark' ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.4)'
|
|
|
|
const setReactFlow = useEffectEvent(async ({ isMeasuredPass }: { isMeasuredPass: boolean }) => {
|
|
// Merge in React Flow's measured dimensions (if any) so dagre can use real
|
|
// heights instead of the first-paint fallbacks.
|
|
const measuredNodes = nodes.map((node) => {
|
|
const existing = reactFlow.getNode(node.id)
|
|
return existing?.measured ? { ...node, measured: existing.measured } : node
|
|
})
|
|
const graph = getDagreGraphLayout(measuredNodes, edges, { ranksep })
|
|
const { nodes: groupedNodes } = addGroupNodes(graph.nodes, graph.edges)
|
|
// Re-attach known measurements to the freshly created group nodes too —
|
|
// handing setNodes an unmeasured node resets the store's nodesInitialized
|
|
// flag, which would re-trigger the measured pass below on every re-measure
|
|
// and loop forever (each iteration re-running fitView, so the diagram
|
|
// snaps back to center and can't be panned).
|
|
const updatedNodes = groupedNodes.map((node) => {
|
|
if (node.measured !== undefined) return node
|
|
const existing = reactFlow.getNode(node.id)
|
|
return existing?.measured ? { ...node, measured: existing.measured } : node
|
|
})
|
|
reactFlow.setNodes(updatedNodes)
|
|
reactFlow.setEdges(graph.edges)
|
|
|
|
// [Joshen] Odd fix to ensure that react flow snaps back to center when adding nodes
|
|
await timeout(1)
|
|
reactFlow.fitView({ maxZoom: 0.9, minZoom: 0.9 })
|
|
if (isMeasuredPass) setHasMeasuredLayout(true)
|
|
})
|
|
|
|
// First pass: lay out using fallback heights for any not-yet-measured nodes.
|
|
// The diagram is kept invisible until the measured pass below has run, so the
|
|
// user never sees the fallback positions.
|
|
useEffect(() => {
|
|
if (nodes.length > 0) {
|
|
setReactFlow({ isMeasuredPass: false })
|
|
}
|
|
}, [nodes, edges])
|
|
|
|
// Second pass: once React Flow has measured the nodes, re-run the layout so
|
|
// dagre uses real heights. Only `nodesInitialized` going true should trigger
|
|
// this — the first-pass effect above handles node changes.
|
|
const runMeasuredLayout = useEffectEvent(() => {
|
|
if (nodesInitialized && nodes.length > 0) {
|
|
setReactFlow({ isMeasuredPass: true })
|
|
}
|
|
})
|
|
useEffect(() => {
|
|
runMeasuredLayout()
|
|
}, [nodesInitialized])
|
|
|
|
return (
|
|
<ReactFlow
|
|
// FIXME: https://github.com/xyflow/xyflow/issues/4876
|
|
colorMode={'' as unknown as ColorMode}
|
|
fitView
|
|
fitViewOptions={{ minZoom: 0.9, maxZoom: 0.9 }}
|
|
// Keep the diagram invisible (but laid out, so nodes can be measured)
|
|
// until the measured-height layout pass has run.
|
|
className={cn(
|
|
'instance-configuration transition-opacity duration-150',
|
|
hasMeasuredLayout ? 'opacity-100' : 'opacity-0'
|
|
)}
|
|
zoomOnPinch={false}
|
|
zoomOnScroll={false}
|
|
nodesDraggable={false}
|
|
nodesConnectable={false}
|
|
zoomOnDoubleClick={false}
|
|
edgesFocusable={false}
|
|
edgesReconnectable={false}
|
|
defaultNodes={[]}
|
|
defaultEdges={[]}
|
|
nodeTypes={nodeTypes}
|
|
edgeTypes={edgeTypes}
|
|
proOptions={{ hideAttribution: true }}
|
|
>
|
|
<Background color={backgroundPatternColor} />
|
|
</ReactFlow>
|
|
)
|
|
}
|