@astrojs/mdx 2.2.3 → 2.2.4
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
CHANGED
|
@@ -54,8 +54,7 @@ function mdx(partialMdxOptions = {}) {
|
|
|
54
54
|
enforce: "pre",
|
|
55
55
|
configResolved(resolved) {
|
|
56
56
|
processor = createMdxProcessor(mdxOptions, {
|
|
57
|
-
sourcemap: !!resolved.build.sourcemap
|
|
58
|
-
importMetaEnv: { SITE: config.site, ...resolved.env }
|
|
57
|
+
sourcemap: !!resolved.build.sourcemap
|
|
59
58
|
});
|
|
60
59
|
const jsxPluginIndex = resolved.plugins.findIndex((p) => p.name === "astro:jsx");
|
|
61
60
|
if (jsxPluginIndex !== -1) {
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { MdxOptions } from './index.js';
|
|
2
2
|
interface MdxProcessorExtraOptions {
|
|
3
3
|
sourcemap: boolean;
|
|
4
|
-
importMetaEnv: Record<string, any>;
|
|
5
4
|
}
|
|
6
5
|
export declare function createMdxProcessor(mdxOptions: MdxOptions, extraOptions: MdxProcessorExtraOptions): import("unified").Processor<import("mdast").Root, import("estree").Program, import("estree").Program, import("estree").Program, string>;
|
|
7
6
|
export {};
|
package/dist/plugins.js
CHANGED
|
@@ -9,7 +9,6 @@ import rehypeRaw from "rehype-raw";
|
|
|
9
9
|
import remarkGfm from "remark-gfm";
|
|
10
10
|
import remarkSmartypants from "remark-smartypants";
|
|
11
11
|
import { SourceMapGenerator } from "source-map";
|
|
12
|
-
import { recmaInjectImportMetaEnv } from "./recma-inject-import-meta-env.js";
|
|
13
12
|
import { rehypeApplyFrontmatterExport } from "./rehype-apply-frontmatter-export.js";
|
|
14
13
|
import { rehypeInjectHeadingsExport } from "./rehype-collect-headings.js";
|
|
15
14
|
import rehypeMetaString from "./rehype-meta-string.js";
|
|
@@ -20,7 +19,7 @@ function createMdxProcessor(mdxOptions, extraOptions) {
|
|
|
20
19
|
return createProcessor({
|
|
21
20
|
remarkPlugins: getRemarkPlugins(mdxOptions),
|
|
22
21
|
rehypePlugins: getRehypePlugins(mdxOptions),
|
|
23
|
-
recmaPlugins:
|
|
22
|
+
recmaPlugins: mdxOptions.recmaPlugins,
|
|
24
23
|
remarkRehypeOptions: mdxOptions.remarkRehype,
|
|
25
24
|
jsx: true,
|
|
26
25
|
jsxImportSource: "astro",
|
|
@@ -69,9 +68,6 @@ function getRehypePlugins(mdxOptions) {
|
|
|
69
68
|
}
|
|
70
69
|
return rehypePlugins;
|
|
71
70
|
}
|
|
72
|
-
function getRecmaPlugins(mdxOptions, importMetaEnv) {
|
|
73
|
-
return [...mdxOptions.recmaPlugins ?? [], [recmaInjectImportMetaEnv, { importMetaEnv }]];
|
|
74
|
-
}
|
|
75
71
|
export {
|
|
76
72
|
createMdxProcessor
|
|
77
73
|
};
|
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": "2.2.
|
|
4
|
+
"version": "2.2.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"remark-toc": "^9.0.0",
|
|
66
66
|
"unified": "^11.0.4",
|
|
67
67
|
"vite": "^5.1.4",
|
|
68
|
-
"astro": "4.5.
|
|
68
|
+
"astro": "4.5.16",
|
|
69
69
|
"astro-scripts": "0.0.14"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { visit as estreeVisit } from "estree-util-visit";
|
|
2
|
-
function recmaInjectImportMetaEnv({
|
|
3
|
-
importMetaEnv
|
|
4
|
-
}) {
|
|
5
|
-
return (tree) => {
|
|
6
|
-
estreeVisit(tree, (node) => {
|
|
7
|
-
if (node.type === "MemberExpression") {
|
|
8
|
-
const envVarName = getImportMetaEnvVariableName(node);
|
|
9
|
-
if (typeof envVarName === "string" && importMetaEnv[envVarName] != null) {
|
|
10
|
-
for (const key in node) {
|
|
11
|
-
delete node[key];
|
|
12
|
-
}
|
|
13
|
-
const envVarLiteral = {
|
|
14
|
-
type: "Literal",
|
|
15
|
-
value: importMetaEnv[envVarName],
|
|
16
|
-
raw: JSON.stringify(importMetaEnv[envVarName])
|
|
17
|
-
};
|
|
18
|
-
Object.assign(node, envVarLiteral);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function getImportMetaEnvVariableName(node) {
|
|
25
|
-
try {
|
|
26
|
-
if (node.object.type !== "MemberExpression" || node.property.type !== "Identifier")
|
|
27
|
-
return new Error();
|
|
28
|
-
const nestedExpression = node.object;
|
|
29
|
-
if (nestedExpression.property.type !== "Identifier" || nestedExpression.property.name !== "env")
|
|
30
|
-
return new Error();
|
|
31
|
-
const envExpression = nestedExpression.object;
|
|
32
|
-
if (envExpression.type !== "MetaProperty" || envExpression.property.type !== "Identifier" || envExpression.property.name !== "meta")
|
|
33
|
-
return new Error();
|
|
34
|
-
if (envExpression.meta.name !== "import")
|
|
35
|
-
return new Error();
|
|
36
|
-
return node.property.name;
|
|
37
|
-
} catch (e) {
|
|
38
|
-
if (e instanceof Error) {
|
|
39
|
-
return e;
|
|
40
|
-
}
|
|
41
|
-
return new Error("Unknown parsing error");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export {
|
|
45
|
-
recmaInjectImportMetaEnv
|
|
46
|
-
};
|