From 1bfcffb077a6c7d6efc22ef58d25995e8281b4ea Mon Sep 17 00:00:00 2001 From: Fuma Nama Date: Thu, 19 Dec 2024 20:15:19 +0800 Subject: [PATCH] fix build --- apps/docs/next.config.mjs | 2 +- apps/docs/package.json | 1 + apps/docs/source.config.ts | 8 +++++++- packages/doc-gen/src/remark-ts2js.ts | 8 ++++---- pnpm-lock.yaml | 3 +++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apps/docs/next.config.mjs b/apps/docs/next.config.mjs index 59a3cffce..7b49fa05f 100644 --- a/apps/docs/next.config.mjs +++ b/apps/docs/next.config.mjs @@ -13,7 +13,7 @@ const config = { // Replaced by root workspace command ignoreDuringBuilds: true, }, - serverExternalPackages: ['ts-morph', 'typescript'], + serverExternalPackages: ['ts-morph', 'typescript', 'oxc-transform'], experimental: { reactCompiler: true, }, diff --git a/apps/docs/package.json b/apps/docs/package.json index dd5597463..689b69406 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -34,6 +34,7 @@ "katex": "^0.16.17", "lucide-react": "^0.468.0", "next": "15.1.1", + "oxc-transform": "^0.42.0", "phenomenon": "^1.6.0", "react": "^19.0.0", "react-dom": "^19.0.0", diff --git a/apps/docs/source.config.ts b/apps/docs/source.config.ts index d4117b467..7d99ea3eb 100644 --- a/apps/docs/source.config.ts +++ b/apps/docs/source.config.ts @@ -8,7 +8,12 @@ import { import { rehypeCodeDefaultOptions } from 'fumadocs-core/mdx-plugins'; import { transformerTwoslash } from 'fumadocs-twoslash'; import remarkMath from 'remark-math'; -import { fileGenerator, remarkDocGen, remarkInstall } from 'fumadocs-docgen'; +import { + fileGenerator, + remarkDocGen, + remarkInstall, + remarkTypeScriptToJavaScript, +} from 'fumadocs-docgen'; import rehypeKatex from 'rehype-katex'; import { z } from 'zod'; import { remarkMermaid } from '@theguild/remark-mermaid'; @@ -78,6 +83,7 @@ export default defineConfig({ remarkMath, [remarkInstall, { persist: { id: 'package-manager' } }], [remarkDocGen, { generators: [fileGenerator()] }], + remarkTypeScriptToJavaScript, ], rehypePlugins: (v) => [rehypeKatex, ...v], }, diff --git a/packages/doc-gen/src/remark-ts2js.ts b/packages/doc-gen/src/remark-ts2js.ts index 0f3769407..6b6456dd2 100644 --- a/packages/doc-gen/src/remark-ts2js.ts +++ b/packages/doc-gen/src/remark-ts2js.ts @@ -1,8 +1,7 @@ -import { Transformer } from 'unified'; +import { type Transformer } from 'unified'; import { type Code, Root } from 'mdast'; import { visit } from 'unist-util-visit'; import { createElement, expressionToAttribute } from '@/utils'; -import oxc from 'oxc-transform'; export interface TypeScriptToJavaScriptOptions { /** @@ -40,10 +39,11 @@ export function remarkTypeScriptToJavaScript({ persist = false, disableTrigger = false, }: TypeScriptToJavaScriptOptions = {}): Transformer { - return (tree, file) => { + return async (tree, file) => { + const oxc = await import('oxc-transform'); + visit(tree, 'code', (node) => { if (node.lang !== 'ts' && node.lang !== 'tsx') return; - if (!disableTrigger && !node.meta?.includes('ts2js')) return; const result = oxc.transform( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dfa63a294..e60891798 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,6 +122,9 @@ importers: next: specifier: 15.1.1 version: 15.1.1(@opentelemetry/api@1.9.0)(babel-plugin-react-compiler@19.0.0-beta-df7b47d-20241124)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + oxc-transform: + specifier: ^0.42.0 + version: 0.42.0 phenomenon: specifier: ^1.6.0 version: 1.6.0