画面上でのテストは完了. 移行にす早さが求められるので,準備ができたらマージする. Reviewed-on: #430 Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #430 でマージされました。
このコミットが含まれているのは:
@@ -0,0 +1,37 @@
|
||||
import * as jsxRuntime from 'react/jsx-runtime'
|
||||
import { ModuleKind, ScriptTarget, transpileModule } from 'typescript'
|
||||
|
||||
import { useMDXComponents } from '@/mdx-components'
|
||||
import viteConfig from '../../vite.config'
|
||||
|
||||
import type { ComponentType } from 'react'
|
||||
|
||||
type Transform = (source: string, id: string) => Promise<{ code: string } | null>
|
||||
|
||||
|
||||
export const transformMdx = async (source: string, suffix = '.mdx') => {
|
||||
const plugins = viteConfig.plugins?.flat () as { name: string; transform: Transform }[]
|
||||
const plugin = plugins.find (entry => entry.name === '@mdx-js/rollup')
|
||||
if (plugin == null)
|
||||
throw new Error ('The application MDX compiler is not registered')
|
||||
return plugin.transform.call (plugin, source, `/test/help-table${suffix}`)
|
||||
}
|
||||
|
||||
|
||||
export const compileMdx = async (source: string): Promise<ComponentType> => {
|
||||
const result = await transformMdx (source)
|
||||
if (result == null)
|
||||
throw new Error ('MDX was not compiled')
|
||||
const code = transpileModule (result.code, {
|
||||
compilerOptions: { module: ModuleKind.CommonJS, target: ScriptTarget.ES2022 } }).outputText
|
||||
const exports = { } as { default: ComponentType }
|
||||
const requireFixture = (name: string) => {
|
||||
if (name === 'react/jsx-runtime')
|
||||
return jsxRuntime
|
||||
if (name === '@/mdx-components')
|
||||
return { useMDXComponents }
|
||||
throw new Error (`Unexpected MDX dependency: ${name}`)
|
||||
}
|
||||
new Function ('require', 'exports', code) (requireFixture, exports)
|
||||
return exports.default
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする