mirror of
https://github.com/supabase/supabase.git
synced 2026-09-11 04:21:47 +08:00
Upgrades the monorepo to TypeScript 7.0.2, released 2026-07-08. `tsc` is now the native Go compiler ([announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/)) — full turbo typecheck drops from ~56s to ~19s locally. TS 7.0 ships **without a programmatic API** (it lands in 7.1), so this uses Microsoft's recommended side-by-side setup: the `typescript` name resolves to `@typescript/typescript6` (the 6.0 API republished) for API consumers — typescript-eslint and Next.js build typechecking — while `@typescript/native` (the real `typescript@7.0.2`) owns the `tsc` bin that typecheck scripts run. Exactly one version of each is in the lockfile; nothing imports the native package as a library. When 7.1 + tool support lands we can collapse back to a single `typescript` dep in the catalog. **Changed:** - `pnpm-workspace.yaml`: catalog aliases for `typescript` / `@typescript/native` - 17 package.json files: `@typescript/native` added beside each `typescript` dep so every package's `tsc` is the native binary - `apps/studio/tsconfig.json`: exclude `dist/` (gitignored build output) from typechecking **Fixed** (real type errors TS 6 under-reported): - `packages/ui-patterns` CodeBlock: `borderLeft: null` → `undefined` (`CSSProperties` doesn't accept null) - `apps/www` CodeBlock: removed a JSX `@ts-ignore` comment that tsgo doesn't honor and fixed what it masked (untyped `.js` theme objects, possibly-undefined highlighter children) ⚠️ **Merge timing:** the new packages are inside pnpm's 3-day `minimumReleaseAge` window until ~July 11. Installs from the committed lockfile are unaffected (resolution is skipped), but anything that forces a re-resolution before then will fail — hold off merging until the window passes. Note for editors: the compat package has no `lib/tsserver.js`, so VS Code's "Use Workspace Version" won't work — use the bundled TS or the TypeScript Native Preview extension. ## To test - `pnpm install && pnpm typecheck` — all 15 tasks green, and `./node_modules/.bin/tsc --version` prints 7.0.2 - `pnpm lint --filter=studio` — typescript-eslint still parses (resolves the 6.0 API) - `pnpm build --filter=design-system` (or any Next app) — Next's tsconfig validation and build typecheck still work - CodeBlock rendering on www (syntax highlighting, line highlights with/without border) — the two fixes are behavior-neutral but worth an eyeball <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements / New Features** * Enhanced TypeScript tooling support across the workspace for smoother development builds and checks. * **Bug Fixes** * Code blocks render more reliably when content is empty or missing. * Highlighted code line styling applies more consistently. * **Maintenance** * Studio TypeScript builds now avoid including generated output (such as `dist`) during compilation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
183 lines
5.4 KiB
TypeScript
183 lines
5.4 KiB
TypeScript
'use client'
|
|
|
|
import { Check, Copy, File, Terminal } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import { useEffect, useState, type CSSProperties } from 'react'
|
|
import CopyToClipboard from 'react-copy-to-clipboard'
|
|
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'
|
|
import bash from 'react-syntax-highlighter/dist/cjs/languages/hljs/bash'
|
|
import js from 'react-syntax-highlighter/dist/cjs/languages/hljs/javascript'
|
|
import json from 'react-syntax-highlighter/dist/cjs/languages/hljs/json'
|
|
import kotlin from 'react-syntax-highlighter/dist/cjs/languages/hljs/kotlin'
|
|
import py from 'react-syntax-highlighter/dist/cjs/languages/hljs/python'
|
|
import sql from 'react-syntax-highlighter/dist/cjs/languages/hljs/sql'
|
|
import yaml from 'react-syntax-highlighter/dist/cjs/languages/hljs/yaml'
|
|
import { Button, cn } from 'ui'
|
|
|
|
import monokaiCustomTheme, { codeHikeTheme } from './CodeBlock.utils'
|
|
|
|
export type LANG = 'js' | 'sql' | 'py' | 'bash' | 'ts' | 'tsx' | 'kotlin' | 'yaml' | 'json'
|
|
|
|
export interface CodeBlockProps {
|
|
lang: LANG
|
|
startingLineNumber?: number
|
|
hideCopy?: boolean
|
|
showLineNumbers?: boolean
|
|
className?: string
|
|
children?: string
|
|
size?: 'small' | 'medium' | 'large'
|
|
background?: string
|
|
filename?: string
|
|
theme?: 'monokai' | 'code-hike'
|
|
}
|
|
|
|
function CodeBlock(props: CodeBlockProps) {
|
|
const { resolvedTheme } = useTheme()
|
|
const isDarkTheme = resolvedTheme?.includes('dark') ?? false
|
|
const [copied, setCopied] = useState(false)
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
const firstLine = props.children ? props.children.split('\n')[0] : ''
|
|
|
|
let filename = ''
|
|
|
|
if (firstLine.includes('filename =')) {
|
|
filename = firstLine.split('=')[1]
|
|
}
|
|
|
|
const content =
|
|
props.children && filename ? props.children.replace(`${firstLine}\n\n`, '') : props.children
|
|
|
|
const handleCopy = () => {
|
|
setCopied(true)
|
|
setTimeout(() => {
|
|
setCopied(false)
|
|
}, 1000)
|
|
}
|
|
|
|
const isCodeHikeTheme = props.theme === 'code-hike'
|
|
|
|
let lang = props.lang
|
|
? props.lang
|
|
: props.className
|
|
? props.className.replace('language-', '')
|
|
: 'js'
|
|
// force jsx to be js highlighted
|
|
if (lang === 'jsx') lang = 'js'
|
|
|
|
SyntaxHighlighter.registerLanguage('js', js)
|
|
SyntaxHighlighter.registerLanguage('py', py)
|
|
SyntaxHighlighter.registerLanguage('sql', sql)
|
|
SyntaxHighlighter.registerLanguage('bash', bash)
|
|
SyntaxHighlighter.registerLanguage('kotlin', kotlin)
|
|
SyntaxHighlighter.registerLanguage('yaml', yaml)
|
|
SyntaxHighlighter.registerLanguage('json', json)
|
|
|
|
// const large = props.size === 'large' ? true : false
|
|
const large = false
|
|
|
|
useEffect(() => {
|
|
setMounted(true)
|
|
}, [])
|
|
|
|
if (!mounted) return null
|
|
|
|
return (
|
|
<div className="not-prose dark overflow-hidden">
|
|
{filename && (
|
|
<div
|
|
className="
|
|
bg-background
|
|
text-muted
|
|
flex
|
|
h-8 w-full
|
|
items-center
|
|
|
|
gap-1
|
|
rounded-tr
|
|
rounded-tl
|
|
|
|
border-t
|
|
|
|
border-r
|
|
border-l
|
|
px-4
|
|
font-sans
|
|
"
|
|
>
|
|
{lang === 'bash' ? (
|
|
<Terminal size={12} strokeWidth={2} />
|
|
) : (
|
|
<File size={12} strokeWidth={2} />
|
|
)}
|
|
<span className="text-xs">{filename ?? 'index.js'}</span>
|
|
</div>
|
|
)}
|
|
<div className="relative">
|
|
<SyntaxHighlighter
|
|
language={lang}
|
|
style={
|
|
(isCodeHikeTheme
|
|
? isDarkTheme
|
|
? codeHikeTheme.dark
|
|
: codeHikeTheme.light
|
|
: isDarkTheme
|
|
? monokaiCustomTheme.dark
|
|
: monokaiCustomTheme.light) as Record<string, CSSProperties>
|
|
}
|
|
className={cn(
|
|
'synthax-highlighter border border-default/15 rounded-lg',
|
|
!filename && 'rounded-t-lg',
|
|
'rounded-b-lg',
|
|
props.className
|
|
)}
|
|
customStyle={{
|
|
padding: props.showLineNumbers
|
|
? large
|
|
? '1.25rem 1rem'
|
|
: '1rem 0.8rem'
|
|
: large
|
|
? '1.25rem 1.5rem'
|
|
: '1.25rem 1.5rem',
|
|
fontSize: large ? 18 : '0.775rem',
|
|
lineHeight: large ? 1.6 : 1.4,
|
|
}}
|
|
showLineNumbers={props.showLineNumbers}
|
|
lineNumberStyle={{
|
|
padding: '0px',
|
|
marginRight: isCodeHikeTheme ? '16px' : '21px',
|
|
minWidth: '1.5em',
|
|
opacity: isCodeHikeTheme ? '0.7' : '0.3',
|
|
fontSize: large ? 14 : '0.75rem',
|
|
}}
|
|
>
|
|
{content ?? ''}
|
|
</SyntaxHighlighter>
|
|
{!props.hideCopy && props.children ? (
|
|
<div className="absolute right-2 top-2">
|
|
<CopyToClipboard text={props.children}>
|
|
<Button
|
|
variant="text"
|
|
icon={
|
|
copied ? (
|
|
<span className="text-brand">
|
|
<Check strokeWidth={3} />
|
|
</span>
|
|
) : (
|
|
<Copy />
|
|
)
|
|
}
|
|
onClick={() => handleCopy()}
|
|
aria-label="Copy"
|
|
className="px-1.5 py-1.5 border border-transparent hover:border-strong"
|
|
/>
|
|
</CopyToClipboard>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default CodeBlock
|