@astrojs/mdx 5.0.0-beta.6 → 5.0.0-beta.8
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.
|
@@ -122,11 +122,17 @@ function isMdxComponentNode(node) {
|
|
|
122
122
|
return node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement";
|
|
123
123
|
}
|
|
124
124
|
function getExportConstComponentObjectKeys(node) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
let variableInit;
|
|
126
|
+
for (const part of node.data?.estree?.body || []) {
|
|
127
|
+
if (part.type !== "ExportNamedDeclaration" || part.declaration?.type !== "VariableDeclaration") {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const declarator = part.declaration.declarations.find(({ id }) => id.name === "components");
|
|
131
|
+
if (declarator) {
|
|
132
|
+
variableInit = declarator.init;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
130
136
|
if (variableInit?.type !== "ObjectExpression") return;
|
|
131
137
|
const keys = [];
|
|
132
138
|
for (const propertyNode of variableInit.properties) {
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
USES_ASTRO_IMAGE_FLAG
|
|
6
6
|
} from "./rehype-images-to-component.js";
|
|
7
7
|
import { getFileInfo } from "./utils.js";
|
|
8
|
+
import { mdxMetadataMap } from "./vite-plugin-mdx.js";
|
|
8
9
|
const underscoreFragmentImportRegex = /[\s,{]_Fragment[\s,}]/;
|
|
9
10
|
const astroTagComponentImportRegex = /[\s,{]__astro_tag_component__[\s,}]/;
|
|
10
11
|
function vitePluginMdxPostprocess(astroConfig) {
|
|
@@ -17,6 +18,13 @@ function vitePluginMdxPostprocess(astroConfig) {
|
|
|
17
18
|
handler(code, id) {
|
|
18
19
|
const fileInfo = getFileInfo(id, astroConfig);
|
|
19
20
|
const [imports, exports] = parse(code);
|
|
21
|
+
const usesShiki = astroConfig.markdown.syntaxHighlight === "shiki" || astroConfig.markdown.syntaxHighlight === void 0;
|
|
22
|
+
const metadata = mdxMetadataMap.get(id);
|
|
23
|
+
const hasCodeBlocks = metadata?.hasCodeBlocks ?? false;
|
|
24
|
+
if (usesShiki && hasCodeBlocks) {
|
|
25
|
+
code = `import 'virtual:astro:shiki-styles.css';
|
|
26
|
+
${code}`;
|
|
27
|
+
}
|
|
20
28
|
code = injectUnderscoreFragmentImport(code, imports);
|
|
21
29
|
code = injectMetadataExports(code, exports, fileInfo);
|
|
22
30
|
code = transformContentExport(code, exports);
|
package/dist/vite-plugin-mdx.js
CHANGED
|
@@ -2,6 +2,7 @@ import { getAstroMetadata } from "astro/jsx/rehype.js";
|
|
|
2
2
|
import { VFile } from "vfile";
|
|
3
3
|
import { createMdxProcessor } from "./plugins.js";
|
|
4
4
|
import { safeParseFrontmatter } from "./utils.js";
|
|
5
|
+
const mdxMetadataMap = /* @__PURE__ */ new Map();
|
|
5
6
|
function vitePluginMdx(opts) {
|
|
6
7
|
let processor;
|
|
7
8
|
let sourcemapEnabled;
|
|
@@ -58,6 +59,8 @@ function vitePluginMdx(opts) {
|
|
|
58
59
|
}
|
|
59
60
|
try {
|
|
60
61
|
const compiled = await processor.process(vfile);
|
|
62
|
+
const hasCodeBlocks = vfile.data.astro?.hasCodeBlocks ?? false;
|
|
63
|
+
mdxMetadataMap.set(id, { hasCodeBlocks });
|
|
61
64
|
return {
|
|
62
65
|
code: String(compiled.value),
|
|
63
66
|
map: compiled.map,
|
|
@@ -87,9 +90,12 @@ function getMdxMeta(vfile) {
|
|
|
87
90
|
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
|
88
91
|
// extensions to .ts files.
|
|
89
92
|
lang: "ts"
|
|
90
|
-
}
|
|
93
|
+
},
|
|
94
|
+
// Pass hasCodeBlocks flag to postprocess plugin
|
|
95
|
+
hasCodeBlocks: vfile.data.astro?.hasCodeBlocks ?? false
|
|
91
96
|
};
|
|
92
97
|
}
|
|
93
98
|
export {
|
|
99
|
+
mdxMetadataMap,
|
|
94
100
|
vitePluginMdx
|
|
95
101
|
};
|
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": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"source-map": "^0.7.6",
|
|
41
41
|
"unist-util-visit": "^5.1.0",
|
|
42
42
|
"vfile": "^6.0.3",
|
|
43
|
-
"@astrojs/markdown-remark": "7.0.0-beta.
|
|
43
|
+
"@astrojs/markdown-remark": "7.0.0-beta.7"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"astro": "^6.0.0-alpha.0"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"shiki": "^3.22.0",
|
|
63
63
|
"unified": "^11.0.5",
|
|
64
64
|
"vite": "^7.3.1",
|
|
65
|
-
"astro": "6.0.0-beta.
|
|
65
|
+
"astro": "6.0.0-beta.13",
|
|
66
66
|
"astro-scripts": "0.0.14"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|