From 70388e50bb9072c8a267084efa47f042a8d8442e Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Wed, 10 Dec 2025 17:23:46 +0200 Subject: [PATCH] fix: Use `amaro` for stripping types in code samples (#41229) * Fix the error for babel/preset-typescript in docs. * Unfix the version. * Try using amaro for type stripping. * Run prettier after stripping types. * Fix tests. --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com> --- .../features/directives/CodeSample.test.ts | 44 +++++++------- apps/docs/features/directives/CodeSample.ts | 11 +++- apps/docs/package.json | 2 +- pnpm-lock.yaml | 60 ++++--------------- 4 files changed, 41 insertions(+), 76 deletions(-) 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: 'john@example.com' }, { 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: 'john@example.com' }, { 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=6.9.0'} - '@babel/helper-plugin-utils@7.26.5': - resolution: {integrity: sha512-RS+jZcRdZdRFzMyr+wcsaqOmld1/EqTghfaBGQQd/WnRdzdlvSZ//kF7U8VQTxf1ynZ4cjUcYgjVGx13ewNPMg==} - engines: {node: '>=6.9.0'} - '@babel/helper-plugin-utils@7.27.1': resolution: {integrity: sha512-1gn1Up5YXka3YYAHGKpbideQ5Yjf1tDa9qYcgysz+cNCXukyLl6DjPXhD3VRwSb8c0J9tA4b2+rHEZtc6R0tlw==} engines: {node: '>=6.9.0'} @@ -3126,12 +3122,6 @@ packages: engines: {node: '>=6.0.0'} hasBin: true - '@babel/plugin-syntax-decorators@7.25.9': - resolution: {integrity: sha512-ryzI0McXUPJnRCvMo4lumIKZUzhYUO/ScI+Mz4YVaTLt04DHNSjEUjKVvbzQjZFLuod/cYEc07mJWhzl6v4DPg==} - engines: {node: '>=6.9.0'} - peerDependencies: - '@babel/core': ^7.0.0-0 - '@babel/plugin-syntax-import-assertions@7.26.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/plugin-transform-typescript@7.27.0': - resolution: {integrity: sha512-fRGGjO2UEGPjvEcyAZXRXAS8AfdaQoq7HnxAbJoAoW10B9xOKesmmndJv+Sym2a+9FHWZ9KbyyLCe9s0Sn5jtg==} - engines: {node: '>=6.9.0'} - peerDependencies: - '@babel/core': ^7.0.0-0 - '@babel/plugin-transform-typescript@7.28.0': resolution: {integrity: sha512-4AEiDEBPIZvLQaWlc9liCavE0xRM0dNca41WtBeM3jgFptfUOSG9z0uteLhq6+3rq+WB6jIvUwKDTpXEHPJ2Vg==} engines: {node: '>=6.9.0'} @@ -9858,6 +9842,10 @@ packages: alien-signals@2.0.7: resolution: {integrity: sha512-wE7y3jmYeb0+h6mr5BOovuqhFv22O/MV9j5p0ndJsa7z1zJNPGQ4ph5pQk/kTTCWRC3xsA4SmtwmkzQO+7NCNg==} + amaro@1.1.5: + resolution: {integrity: sha512-oo72OEYOSfSPe+96V+jh41gaFWfl9HddXFAHMFM+emjdZkzbtcg0bFWoYaWf8IMlqmZ0VM8F13frI8Ktt3+ADA==} + engines: {node: '>=22'} + amazon-cognito-identity-js@6.3.15: resolution: {integrity: sha512-G2mzTlGYHKYh9oZDO0Gk94xVQ4iY9GYWBaYScbDYvz05ps6dqi0IvdNx1Lxi7oA3tjS5X+mUN7/svFJJdOB9YA==} @@ -16955,9 +16943,6 @@ packages: remove-trailing-spaces@1.0.9: resolution: {integrity: sha512-xzG7w5IRijvIkHIjDk65URsJJ7k4J95wmcArY5PRcmjldIOl7oTvG8+X2Ag690R7SfwiOcHrWZKVc1Pp5WIOzA==} - remove-types@1.0.0: - resolution: {integrity: sha512-G7Hk1Q+UJ5DvlNAoJZObxANkBZGiGdp589rVcTW/tYqJWJ5rwfraSnKSQaETN8Epaytw8J40nS/zC7bcHGv36w==} - rename-keys@1.2.0: resolution: {integrity: sha512-U7XpAktpbSgHTRSNRrjKSrjYkZKuhUukfoBlXWXUExCAqhzh1TU3BDRAfJmarcl5voKS+pbKU9MvyLWKZ4UEEg==} engines: {node: '>= 0.8.0'} @@ -20541,8 +20526,6 @@ snapshots: dependencies: '@babel/types': 7.28.4 - '@babel/helper-plugin-utils@7.26.5': {} - '@babel/helper-plugin-utils@7.27.1': {} '@babel/helper-replace-supers@7.27.1(@babel/core@7.28.4(supports-color@8.1.1))(supports-color@8.1.1)': @@ -20580,11 +20563,6 @@ snapshots: dependencies: '@babel/types': 7.28.4 - '@babel/plugin-syntax-decorators@7.25.9(@babel/core@7.28.4(supports-color@8.1.1))': - dependencies: - '@babel/core': 7.28.4(supports-color@8.1.1) - '@babel/helper-plugin-utils': 7.27.1 - '@babel/plugin-syntax-import-assertions@7.26.0(@babel/core@7.28.4(supports-color@8.1.1))': dependencies: '@babel/core': 7.28.4(supports-color@8.1.1) @@ -20618,17 +20596,6 @@ snapshots: '@babel/core': 7.28.4(supports-color@8.1.1) '@babel/helper-plugin-utils': 7.27.1 - '@babel/plugin-transform-typescript@7.27.0(@babel/core@7.28.4(supports-color@8.1.1))(supports-color@8.1.1)': - dependencies: - '@babel/core': 7.28.4(supports-color@8.1.1) - '@babel/helper-annotate-as-pure': 7.27.3 - '@babel/helper-create-class-features-plugin': 7.28.3(@babel/core@7.28.4(supports-color@8.1.1))(supports-color@8.1.1) - '@babel/helper-plugin-utils': 7.27.1 - '@babel/helper-skip-transparent-expression-wrappers': 7.27.1(supports-color@8.1.1) - '@babel/plugin-syntax-typescript': 7.27.1(@babel/core@7.28.4(supports-color@8.1.1)) - transitivePeerDependencies: - - supports-color - '@babel/plugin-transform-typescript@7.28.0(@babel/core@7.28.4(supports-color@8.1.1))(supports-color@8.1.1)': dependencies: '@babel/core': 7.28.4(supports-color@8.1.1) @@ -21603,7 +21570,7 @@ snapshots: '@graphql-codegen/client-preset@4.8.0(encoding@0.1.13)(graphql-sock@1.0.1(graphql@16.11.0))(graphql@16.11.0)': 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(graphql@16.11.0) '@graphql-codegen/gql-tag-operations': 4.0.17(encoding@0.1.13)(graphql@16.11.0) @@ -29272,6 +29239,8 @@ snapshots: alien-signals@2.0.7: {} + amaro@1.1.5: {} + amazon-cognito-identity-js@6.3.15(encoding@0.1.13): dependencies: '@aws-crypto/sha256-js': 1.2.2 @@ -38036,15 +38005,6 @@ snapshots: remove-trailing-spaces@1.0.9: {} - remove-types@1.0.0(supports-color@8.1.1): - dependencies: - '@babel/core': 7.28.4(supports-color@8.1.1) - '@babel/plugin-syntax-decorators': 7.25.9(@babel/core@7.28.4(supports-color@8.1.1)) - '@babel/plugin-transform-typescript': 7.27.0(@babel/core@7.28.4(supports-color@8.1.1))(supports-color@8.1.1) - prettier: 2.8.8 - transitivePeerDependencies: - - supports-color - rename-keys@1.2.0: {} repeat-element@1.1.4: {}