Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: Use `amaro` for stripping types in code samples (#41229)

Ivan Vasilov70388e50bb90
diff --git a/apps/docs/features/directives/CodeSample.test.ts b/apps/docs/features/directives/CodeSample.test.ts
index 3c8e83df2fb..459927fbd5e 100644
--- a/apps/docs/features/directives/CodeSample.test.ts
+++ b/apps/docs/features/directives/CodeSample.test.ts
@@ -1,4 +1,4 @@
-import { afterAll, beforeAll, describe, it, expect, vi } from 'vitest'
+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
import { stripIndent } from 'common-tags'
import { fromMarkdown } from 'mdast-util-from-markdown'
@@ -593,35 +593,35 @@ Some more text.
const users = [
{ id: 1, name: 'John', email: '[email protected]' },
{ id: 2, name: 'Jane' },
- ];
+ ]
function getUserById(id) {
- return users.find((user) => user.id === id);
+ return users.find((user) => user.id === id)
}
function createUser(name, email) {
- const newId = Math.max(...users.map((u) => u.id)) + 1;
- const newUser = { id: newId, name };
+ const newId = Math.max(...users.map((u) => u.id)) + 1
+ const newUser = { id: newId, name }
if (email) {
- newUser.email = email;
+ newUser.email = email
}
- users.push(newUser);
- return newUser;
+ users.push(newUser)
+ return newUser
}
class UserManager {
- users = [];
+ users = []
constructor(initialUsers = []) {
- this.users = initialUsers;
+ this.users = initialUsers
}
addUser(user) {
- this.users.push(user);
+ this.users.push(user)
}
getUsers() {
- return [...this.users];
+ return [...this.users]
}
}
\`\`\`
@@ -698,33 +698,33 @@ Some more text.
const users = [
{ id: 1, name: 'John', email: '[email protected]' },
{ id: 2, name: 'Jane' },
- ];
+ ]
// ...
function createUser(name, email) {
- const newId = Math.max(...users.map((u) => u.id)) + 1;
- const newUser = { id: newId, name };
+ const newId = Math.max(...users.map((u) => u.id)) + 1
+ const newUser = { id: newId, name }
if (email) {
- newUser.email = email;
+ newUser.email = email
}
- users.push(newUser);
- return newUser;
+ users.push(newUser)
+ return newUser
}
class UserManager {
- users = [];
+ users = []
constructor(initialUsers = []) {
- this.users = initialUsers;
+ this.users = initialUsers
}
addUser(user) {
- this.users.push(user);
+ this.users.push(user)
}
getUsers() {
- return [...this.users];
+ return [...this.users]
}
}
\`\`\`
diff --git a/apps/docs/features/directives/CodeSample.ts b/apps/docs/features/directives/CodeSample.ts
index dc505c0bda1..04242278d6d 100644
--- a/apps/docs/features/directives/CodeSample.ts
+++ b/apps/docs/features/directives/CodeSample.ts
@@ -33,12 +33,13 @@
import * as acorn from 'acorn'
import tsPlugin from 'acorn-typescript'
-import { type DefinitionContent, type BlockContent, type Code, type Root } from 'mdast'
+import amaro from 'amaro'
+import { type BlockContent, type Code, type DefinitionContent, type Root } from 'mdast'
import type { MdxJsxAttributeValueExpression, MdxJsxFlowElement } from 'mdast-util-mdx-jsx'
import assert from 'node:assert'
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
-import { removeTypes } from 'remove-types'
+import prettier from 'prettier'
import { type Parent } from 'unist'
import { visitParents } from 'unist-util-visit-parents'
import { z, type SafeParseError } from 'zod'
@@ -260,7 +261,11 @@ async function rewriteNodes(contentMap: Map<MdxJsxFlowElement, [CodeSampleMeta,
let processedContent = content
if (meta.convertToJs) {
- processedContent = await removeTypes(content)
+ const { code } = amaro.transformSync(content, { mode: 'strip-only' })
+
+ const prettierConfig = await prettier.resolveConfig('./.prettierrc.js')
+ processedContent = await prettier.format(code, { ...prettierConfig, parser: 'typescript' })
+
// Convert TypeScript/TSX language to JavaScript/JSX when converting types
assert(
lang === 'typescript' || lang === 'tsx',
diff --git a/apps/docs/package.json b/apps/docs/package.json
index 48990c579d3..5c603ed5233 100644
--- a/apps/docs/package.json
+++ b/apps/docs/package.json
@@ -109,7 +109,6 @@
"remark-emoji": "^3.1.2",
"remark-gfm": "^3.0.1",
"remark-math": "^6.0.0",
- "remove-types": "1.0.0",
"server-only": "^0.0.1",
"shared-data": "workspace:*",
"ui": "workspace:*",
@@ -142,6 +141,7 @@
"@types/react-dom": "catalog:",
"@types/unist": "^2.0.6",
"@types/uuid": "^10.0.0",
+ "amaro": "^1.1.5",
"api-types": "workspace:*",
"cheerio": "^1.0.0-rc.12",
"chokidar": "^4.0.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 53150321718..03726a492bd 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -583,9 +583,6 @@ importers:
remark-math:
specifier: ^6.0.0
version: 6.0.0([email protected])
- remove-types:
- specifier: 1.0.0
- version: 1.0.0([email protected])
server-only:
specifier: ^0.0.1
version: 0.0.1
@@ -677,6 +674,9 @@ importers:
'@types/uuid':
specifier: ^10.0.0
version: 10.0.0
+ amaro:
+ specifier: ^1.1.5
+ version: 1.1.5
api-types:
specifier: workspace:*
version: link:../../packages/api-types
@@ -3082,10 +3082,6 @@ packages:
resolution: {integrity: sha512-URMGH08NzYFhubNSGJrpUEphGKQwMQYBySzat5cAByY1/YgIRkULnIy3tAMeszlL/so2HbeilYloUmSpd7GdVw==}
engines: {node: '>=6.9.0'}
- '@babel/[email protected]':
- resolution: {integrity: sha512-RS+jZcRdZdRFzMyr+wcsaqOmld1/EqTghfaBGQQd/WnRdzdlvSZ//kF7U8VQTxf1ynZ4cjUcYgjVGx13ewNPMg==}
- engines: {node: '>=6.9.0'}
-
resolution: {integrity: sha512-1gn1Up5YXka3YYAHGKpbideQ5Yjf1tDa9qYcgysz+cNCXukyLl6DjPXhD3VRwSb8c0J9tA4b2+rHEZtc6R0tlw==}
engines: {node: '>=6.9.0'}
@@ -3126,12 +3122,6 @@ packages:
engines: {node: '>=6.0.0'}
hasBin: true
- '@babel/[email protected]':
- resolution: {integrity: sha512-ryzI0McXUPJnRCvMo4lumIKZUzhYUO/ScI+Mz4YVaTLt04DHNSjEUjKVvbzQjZFLuod/cYEc07mJWhzl6v4DPg==}
- engines: {node: '>=6.9.0'}
- peerDependencies:
- '@babel/core': ^7.0.0-0
-
resolution: {integrity: sha512-QCWT5Hh830hK5EQa7XzuqIkQU9tT/whqbDz7kuaZMHFl1inRRg7JnuAEOQ0Ur0QUl0NufCk1msK2BeY79Aj/eg==}
engines: {node: '>=6.9.0'}
@@ -3168,12 +3158,6 @@ packages:
peerDependencies:
'@babel/core': ^7.0.0-0
- '@babel/[email protected]':
- resolution: {integrity: sha512-fRGGjO2UEGPjvEcyAZXRXAS8AfdaQoq7HnxAbJoAoW10B9xOKesmmndJv+Sym2a+9FHWZ9KbyyLCe9s0Sn5jtg==}
- engines: {node: '>=6.9.0'}
- peerDependencies:
- '@babel/core': ^7.0.0-0
-
resolution: {integrity: sha512-4AEiDEBPIZvLQaWlc9liCavE0xRM0dNca41WtBeM3jgFptfUOSG9z0uteLhq6+3rq+WB6jIvUwKDTpXEHPJ2Vg==}
engines: {node: '>=6.9.0'}
@@ -9858,6 +9842,10 @@ packages:
resolution: {integrity: sha512-wE7y3jmYeb0+h6mr5BOovuqhFv22O/MV9j5p0ndJsa7z1zJNPGQ4ph5pQk/kTTCWRC3xsA4SmtwmkzQO+7NCNg==}
+ resolution: {integrity: sha512-oo72OEYOSfSPe+96V+jh41gaFWfl9HddXFAHMFM+emjdZkzbtcg0bFWoYaWf8IMlqmZ0VM8F13frI8Ktt3+ADA==}
+ engines: {node: '>=22'}
+
resolution: {integrity: sha512-G2mzTlGYHKYh9oZDO0Gk94xVQ4iY9GYWBaYScbDYvz05ps6dqi0IvdNx1Lxi7oA3tjS5X+mUN7/svFJJdOB9YA==}
@@ -16955,9 +16943,6 @@ packages:
resolution: {integrity: sha512-xzG7w5IRijvIkHIjDk65URsJJ7k4J95wmcArY5PRcmjldIOl7oTvG8+X2Ag690R7SfwiOcHrWZKVc1Pp5WIOzA==}
- resolution: {integrity: sha512-G7Hk1Q+UJ5DvlNAoJZObxANkBZGiGdp589rVcTW/tYqJWJ5rwfraSnKSQaETN8Epaytw8J40nS/zC7bcHGv36w==}
-
resolution: {integrity: sha512-U7XpAktpbSgHTRSNRrjKSrjYkZKuhUukfoBlXWXUExCAqhzh1TU3BDRAfJmarcl5voKS+pbKU9MvyLWKZ4UEEg==}
engines: {node: '>= 0.8.0'}
@@ -20541,8 +20526,6 @@ snapshots:
dependencies:
'@babel/types': 7.28.4
- '@babel/[email protected]': {}
-
'@babel/[email protected]': {}
@@ -20580,11 +20563,6 @@ snapshots:
dependencies:
'@babel/types': 7.28.4
- dependencies:
- '@babel/core': 7.28.4([email protected])
- '@babel/helper-plugin-utils': 7.27.1
-
dependencies:
'@babel/core': 7.28.4([email protected])
@@ -20618,17 +20596,6 @@ snapshots:
'@babel/core': 7.28.4([email protected])
'@babel/helper-plugin-utils': 7.27.1
- dependencies:
- '@babel/core': 7.28.4([email protected])
- '@babel/helper-annotate-as-pure': 7.27.3
- '@babel/helper-create-class-features-plugin': 7.28.3(@babel/[email protected]([email protected]))([email protected])
- '@babel/helper-plugin-utils': 7.27.1
- '@babel/helper-skip-transparent-expression-wrappers': 7.27.1([email protected])
- '@babel/plugin-syntax-typescript': 7.27.1(@babel/[email protected]([email protected]))
- transitivePeerDependencies:
- - supports-color
-
dependencies:
'@babel/core': 7.28.4([email protected])
@@ -21603,7 +21570,7 @@ snapshots:
dependencies:
- '@babel/helper-plugin-utils': 7.26.5
+ '@babel/helper-plugin-utils': 7.27.1
'@babel/template': 7.27.2
'@graphql-codegen/add': 5.0.3([email protected])
'@graphql-codegen/gql-tag-operations': 4.0.17([email protected])([email protected])
@@ -29272,6 +29239,8 @@ snapshots:
+
dependencies:
'@aws-crypto/sha256-js': 1.2.2
@@ -38036,15 +38005,6 @@ snapshots:
- dependencies:
- '@babel/core': 7.28.4([email protected])
- '@babel/plugin-syntax-decorators': 7.25.9(@babel/[email protected]([email protected]))
- '@babel/plugin-transform-typescript': 7.27.0(@babel/[email protected]([email protected]))([email protected])
- prettier: 2.8.8
- transitivePeerDependencies:
- - supports-color
-