From 2be0e613df39ec446f9e63a3889ca788be912192 Mon Sep 17 00:00:00 2001 From: TomokiMiyauci Date: Tue, 8 Feb 2022 02:30:23 +0900 Subject: [PATCH] feat: update deps to use @mdx-js/mdx@2.0.0 --- deps.ts | 5 ++- mod.ts | 7 ++-- mod_test.ts | 93 +++++++++++++++++++++++++++++------------------------ 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/deps.ts b/deps.ts index d81c231..671dce0 100644 --- a/deps.ts +++ b/deps.ts @@ -5,5 +5,8 @@ export type { Plugin, ResolveResult, } from "https://deno.land/x/aleph@v0.3.0-beta.19/types.d.ts"; -export { compile } from "https://esm.sh/xdm@1.12.2?deps=unist-util-stringify-position@3.0.0,unist-util-visit@3.0.0"; +export { + compile, + type CompileOptions, +} from "https://esm.sh/@mdx-js/mdx@2.0.0?pin=v66"; export { default as util } from "https://deno.land/x/aleph@v0.3.0-beta.19/shared/util.ts"; diff --git a/mod.ts b/mod.ts index c52093d..62c83bf 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,7 @@ import { Aleph, compile, + CompileOptions, LoadInput, LoadOutput, Plugin, @@ -8,8 +9,6 @@ import { util, } from "./deps.ts"; -export type CompileOptions = Parameters[1]; - export type ResolverOptions = { /** Rewrite the page path * ```ts @@ -85,7 +84,7 @@ export async function mdxLoader( const { framework } = aleph.config; const source = new TextDecoder().decode(content); - const { contents } = await compile(source, options); + const { value } = await compile(source, options); if (framework !== "react") { throw new Error( @@ -100,7 +99,7 @@ export async function mdxLoader( return { code: [ - contents.toString(), + value.toString(), ...props, ].filter(Boolean).join("\n"), }; diff --git a/mod_test.ts b/mod_test.ts index 201e4f6..8ecebd1 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -49,21 +49,24 @@ test("mdxLoader", async () => { ).resolves.toEqual({ code: `/*@jsxRuntime automatic @jsxImportSource react*/ import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime"; -function MDXContent(props) { - const _components = Object.assign({ - h1: "h1", - p: "p" - }, props.components), {wrapper: MDXLayout} = _components; - const _content = _jsxs(_Fragment, { - children: [_jsx(_components.h1, { - children: "aleph-plugin-mdx" - }), "\\n", _jsx(_components.p, { - children: "Aleph plugin for mdx v2" - })] - }); +function MDXContent(props = {}) { + const {wrapper: MDXLayout} = props.components || ({}); return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, { - children: _content - })) : _content; + children: _jsx(_createMdxContent, {}) + })) : _createMdxContent(); + function _createMdxContent() { + const _components = Object.assign({ + h1: "h1", + p: "p" + }, props.components); + return _jsxs(_Fragment, { + children: [_jsx(_components.h1, { + children: "aleph-plugin-mdx" + }), "\\n", _jsx(_components.p, { + children: "Aleph plugin for mdx v2" + })] + }); + } } export default MDXContent; `, @@ -78,21 +81,24 @@ export default MDXContent; ).resolves.toEqual({ code: `/*@jsxRuntime automatic @jsxImportSource react*/ import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime"; -function MDXContent(props) { - const _components = Object.assign({ - h1: "h1", - p: "p" - }, props.components), {wrapper: MDXLayout} = _components; - const _content = _jsxs(_Fragment, { - children: [_jsx(_components.h1, { - children: "aleph-plugin-mdx" - }), "\\n", _jsx(_components.p, { - children: "Aleph plugin for mdx v2" - })] - }); +function MDXContent(props = {}) { + const {wrapper: MDXLayout} = props.components || ({}); return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, { - children: _content - })) : _content; + children: _jsx(_createMdxContent, {}) + })) : _createMdxContent(); + function _createMdxContent() { + const _components = Object.assign({ + h1: "h1", + p: "p" + }, props.components); + return _jsxs(_Fragment, { + children: [_jsx(_components.h1, { + children: "aleph-plugin-mdx" + }), "\\n", _jsx(_components.p, { + children: "Aleph plugin for mdx v2" + })] + }); + } } export default MDXContent; @@ -117,21 +123,24 @@ MDXContent.nav = [{"path":"/"}];`, ).resolves.toEqual({ code: `/*@jsxRuntime automatic @jsxImportSource react*/ import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime"; -function MDXContent(props) { - const _components = Object.assign({ - h1: "h1", - p: "p" - }, props.components), {wrapper: MDXLayout} = _components; - const _content = _jsxs(_Fragment, { - children: [_jsx(_components.h1, { - children: "aleph-plugin-mdx" - }), "\\n", _jsx(_components.p, { - children: "Aleph plugin for mdx v2" - })] - }); +function MDXContent(props = {}) { + const {wrapper: MDXLayout} = props.components || ({}); return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, { - children: _content - })) : _content; + children: _jsx(_createMdxContent, {}) + })) : _createMdxContent(); + function _createMdxContent() { + const _components = Object.assign({ + h1: "h1", + p: "p" + }, props.components); + return _jsxs(_Fragment, { + children: [_jsx(_components.h1, { + children: "aleph-plugin-mdx" + }), "\\n", _jsx(_components.p, { + children: "Aleph plugin for mdx v2" + })] + }); + } } export default MDXContent; `,