@astrojs/mdx 3.1.4 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -3
- package/dist/server.d.ts +11 -0
- package/dist/server.js +53 -0
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { markdownConfigDefaults } from "@astrojs/markdown-remark";
|
|
4
|
-
import astroJSXRenderer from "astro/jsx/renderer.js";
|
|
5
4
|
import { ignoreStringPlugins, parseFrontmatter } from "./utils.js";
|
|
6
5
|
import { vitePluginMdxPostprocess } from "./vite-plugin-mdx-postprocess.js";
|
|
7
6
|
import { vitePluginMdx } from "./vite-plugin-mdx.js";
|
|
8
7
|
function getContainerRenderer() {
|
|
9
8
|
return {
|
|
10
9
|
name: "astro:jsx",
|
|
11
|
-
serverEntrypoint: "
|
|
10
|
+
serverEntrypoint: "@astrojs/mdx/server.js"
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
13
|
function mdx(partialMdxOptions = {}) {
|
|
@@ -18,7 +17,10 @@ function mdx(partialMdxOptions = {}) {
|
|
|
18
17
|
hooks: {
|
|
19
18
|
"astro:config:setup": async (params) => {
|
|
20
19
|
const { updateConfig, config, addPageExtension, addContentEntryType, addRenderer } = params;
|
|
21
|
-
addRenderer(
|
|
20
|
+
addRenderer({
|
|
21
|
+
name: "astro:jsx",
|
|
22
|
+
serverEntrypoint: "@astrojs/mdx/server.js"
|
|
23
|
+
});
|
|
22
24
|
addPageExtension(".mdx");
|
|
23
25
|
addContentEntryType({
|
|
24
26
|
extensions: [".mdx"],
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NamedSSRLoadedRendererValue } from 'astro';
|
|
2
|
+
export declare function check(Component: any, props: any, { default: children, ...slotted }?: {
|
|
3
|
+
default?: null | undefined;
|
|
4
|
+
}): Promise<any>;
|
|
5
|
+
export declare function renderToStaticMarkup(this: any, Component: any, props?: {}, { default: children, ...slotted }?: {
|
|
6
|
+
default?: null | undefined;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
html: any;
|
|
9
|
+
}>;
|
|
10
|
+
declare const renderer: NamedSSRLoadedRendererValue;
|
|
11
|
+
export default renderer;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AstroError } from "astro/errors";
|
|
2
|
+
import { AstroJSX, jsx } from "astro/jsx-runtime";
|
|
3
|
+
import { renderJSX } from "astro/runtime/server/index.js";
|
|
4
|
+
const slotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
|
|
5
|
+
async function check(Component, props, { default: children = null, ...slotted } = {}) {
|
|
6
|
+
if (typeof Component !== "function") return false;
|
|
7
|
+
const slots = {};
|
|
8
|
+
for (const [key, value] of Object.entries(slotted)) {
|
|
9
|
+
const name = slotName(key);
|
|
10
|
+
slots[name] = value;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const result = await Component({ ...props, ...slots, children });
|
|
14
|
+
return result[AstroJSX];
|
|
15
|
+
} catch (e) {
|
|
16
|
+
throwEnhancedErrorIfMdxComponent(e, Component);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
async function renderToStaticMarkup(Component, props = {}, { default: children = null, ...slotted } = {}) {
|
|
21
|
+
const slots = {};
|
|
22
|
+
for (const [key, value] of Object.entries(slotted)) {
|
|
23
|
+
const name = slotName(key);
|
|
24
|
+
slots[name] = value;
|
|
25
|
+
}
|
|
26
|
+
const { result } = this;
|
|
27
|
+
try {
|
|
28
|
+
const html = await renderJSX(result, jsx(Component, { ...props, ...slots, children }));
|
|
29
|
+
return { html };
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throwEnhancedErrorIfMdxComponent(e, Component);
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function throwEnhancedErrorIfMdxComponent(error, Component) {
|
|
36
|
+
if (Component[Symbol.for("mdx-component")]) {
|
|
37
|
+
if (AstroError.is(error)) return;
|
|
38
|
+
error.title = error.name;
|
|
39
|
+
error.hint = `This issue often occurs when your MDX component encounters runtime errors.`;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const renderer = {
|
|
44
|
+
name: "astro:jsx",
|
|
45
|
+
check,
|
|
46
|
+
renderToStaticMarkup
|
|
47
|
+
};
|
|
48
|
+
var server_default = renderer;
|
|
49
|
+
export {
|
|
50
|
+
check,
|
|
51
|
+
server_default as default,
|
|
52
|
+
renderToStaticMarkup
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Add support for MDX pages in your Astro site",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-alpha.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"homepage": "https://docs.astro.build/en/guides/integrations-guide/mdx/",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": "./dist/index.js",
|
|
23
|
+
"./server.js": "./dist/server.js",
|
|
23
24
|
"./package.json": "./package.json"
|
|
24
25
|
},
|
|
25
26
|
"files": [
|
|
@@ -40,10 +41,10 @@
|
|
|
40
41
|
"source-map": "^0.7.4",
|
|
41
42
|
"unist-util-visit": "^5.0.0",
|
|
42
43
|
"vfile": "^6.0.2",
|
|
43
|
-
"@astrojs/markdown-remark": "
|
|
44
|
+
"@astrojs/markdown-remark": "6.0.0-alpha.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"astro": "^
|
|
47
|
+
"astro": "^5.0.0-alpha.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/estree": "^1.0.5",
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"shiki": "^1.14.1",
|
|
64
65
|
"unified": "^11.0.5",
|
|
65
66
|
"vite": "^5.4.1",
|
|
66
|
-
"astro": "
|
|
67
|
+
"astro": "5.0.0-alpha.1",
|
|
67
68
|
"astro-scripts": "0.0.14"
|
|
68
69
|
},
|
|
69
70
|
"engines": {
|