Skip to content

Commit

Permalink
feat: update deps to use @mdx-js/mdx@2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Feb 7, 2022
1 parent 49ec88b commit 2be0e61
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 47 deletions.
5 changes: 4 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
7 changes: 3 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {
Aleph,
compile,
CompileOptions,
LoadInput,
LoadOutput,
Plugin,
ResolveResult,
util,
} from "./deps.ts";

export type CompileOptions = Parameters<typeof compile>[1];

export type ResolverOptions = {
/** Rewrite the page path
* ```ts
Expand Down Expand Up @@ -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(
Expand All @@ -100,7 +99,7 @@ export async function mdxLoader(

return {
code: [
contents.toString(),
value.toString(),
...props,
].filter(Boolean).join("\n"),
};
Expand Down
93 changes: 51 additions & 42 deletions mod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`,
Expand All @@ -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;
Expand All @@ -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;
`,
Expand Down

0 comments on commit 2be0e61

Please sign in to comment.