@astrojs/mdx 5.0.0-alpha.0 → 5.0.0-beta.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/utils.js +1 -1
- package/dist/vite-plugin-mdx-postprocess.js +18 -9
- package/dist/vite-plugin-mdx.js +46 -36
- package/package.json +5 -5
package/dist/utils.js
CHANGED
|
@@ -10,15 +10,24 @@ const astroTagComponentImportRegex = /[\s,{]__astro_tag_component__[\s,}]/;
|
|
|
10
10
|
function vitePluginMdxPostprocess(astroConfig) {
|
|
11
11
|
return {
|
|
12
12
|
name: "@astrojs/mdx-postprocess",
|
|
13
|
-
transform
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
transform: {
|
|
14
|
+
filter: {
|
|
15
|
+
id: /\.mdx$/
|
|
16
|
+
},
|
|
17
|
+
handler(code, id) {
|
|
18
|
+
const fileInfo = getFileInfo(id, astroConfig);
|
|
19
|
+
const [imports, exports] = parse(code);
|
|
20
|
+
code = injectUnderscoreFragmentImport(code, imports);
|
|
21
|
+
code = injectMetadataExports(code, exports, fileInfo);
|
|
22
|
+
code = transformContentExport(code, exports);
|
|
23
|
+
code = annotateContentExport(
|
|
24
|
+
code,
|
|
25
|
+
id,
|
|
26
|
+
this.environment.name === "ssr" || this.environment.name === "prerender",
|
|
27
|
+
imports
|
|
28
|
+
);
|
|
29
|
+
return { code, map: null };
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
32
|
};
|
|
24
33
|
}
|
package/dist/vite-plugin-mdx.js
CHANGED
|
@@ -18,48 +18,58 @@ function vitePluginMdx(opts) {
|
|
|
18
18
|
resolved.plugins.splice(jsxPluginIndex, 1);
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
resolveId: {
|
|
22
|
+
filter: {
|
|
23
|
+
// Do not match sources that start with /
|
|
24
|
+
id: /^[^/]/
|
|
25
|
+
},
|
|
26
|
+
async handler(source, importer, options) {
|
|
27
|
+
if (importer?.endsWith(".mdx")) {
|
|
28
|
+
let resolved = await this.resolve(source, importer, options);
|
|
29
|
+
if (!resolved) resolved = await this.resolve("./" + source, importer, options);
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
},
|
|
28
34
|
// Override transform to alter code before MDX compilation
|
|
29
35
|
// ex. inject layouts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
transform: {
|
|
37
|
+
filter: {
|
|
38
|
+
id: /\.mdx$/
|
|
39
|
+
},
|
|
40
|
+
async handler(code, id) {
|
|
41
|
+
const { frontmatter, content } = safeParseFrontmatter(code, id);
|
|
42
|
+
const vfile = new VFile({
|
|
43
|
+
value: content,
|
|
44
|
+
path: id,
|
|
45
|
+
data: {
|
|
46
|
+
astro: {
|
|
47
|
+
frontmatter
|
|
48
|
+
},
|
|
49
|
+
applyFrontmatterExport: {
|
|
50
|
+
srcDir: opts.srcDir
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (!processor) {
|
|
46
|
-
processor = createMdxProcessor(opts.mdxOptions, {
|
|
47
|
-
sourcemap: sourcemapEnabled
|
|
48
53
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
if (!processor) {
|
|
55
|
+
processor = createMdxProcessor(opts.mdxOptions, {
|
|
56
|
+
sourcemap: sourcemapEnabled
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const compiled = await processor.process(vfile);
|
|
61
|
+
return {
|
|
62
|
+
code: String(compiled.value),
|
|
63
|
+
map: compiled.map,
|
|
64
|
+
meta: getMdxMeta(vfile)
|
|
65
|
+
};
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const err = e;
|
|
68
|
+
err.name = "MDXError";
|
|
69
|
+
err.loc = { file: id, line: e.line, column: e.column };
|
|
70
|
+
Error.captureStackTrace(err);
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
};
|
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-
|
|
4
|
+
"version": "5.0.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"es-module-lexer": "^1.7.0",
|
|
34
34
|
"estree-util-visit": "^2.0.0",
|
|
35
35
|
"hast-util-to-html": "^9.0.5",
|
|
36
|
-
"
|
|
36
|
+
"piccolore": "^0.1.3",
|
|
37
37
|
"rehype-raw": "^7.0.0",
|
|
38
38
|
"remark-gfm": "^4.0.1",
|
|
39
39
|
"remark-smartypants": "^3.0.2",
|
|
40
40
|
"source-map": "^0.7.6",
|
|
41
41
|
"unist-util-visit": "^5.0.0",
|
|
42
42
|
"vfile": "^6.0.3",
|
|
43
|
-
"@astrojs/markdown-remark": "7.0.0-
|
|
43
|
+
"@astrojs/markdown-remark": "7.0.0-beta.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"astro": "^6.0.0-alpha.0"
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"remark-rehype": "^11.1.2",
|
|
60
60
|
"remark-shiki-twoslash": "^3.1.3",
|
|
61
61
|
"remark-toc": "^9.0.0",
|
|
62
|
-
"shiki": "^3.
|
|
62
|
+
"shiki": "^3.20.0",
|
|
63
63
|
"unified": "^11.0.5",
|
|
64
64
|
"vite": "^7.1.7",
|
|
65
|
-
"astro": "6.0.0-
|
|
65
|
+
"astro": "6.0.0-beta.1",
|
|
66
66
|
"astro-scripts": "0.0.14"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|