@astrojs/mdx 5.0.0-alpha.0 → 5.0.0-beta.10

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
- const exportNamedDeclaration = node.data?.estree?.body[0];
126
- if (exportNamedDeclaration?.type !== "ExportNamedDeclaration") return;
127
- const variableDeclaration = exportNamedDeclaration.declaration;
128
- if (variableDeclaration?.type !== "VariableDeclaration") return;
129
- const variableInit = variableDeclaration.declarations[0]?.init;
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) {
package/dist/server.js CHANGED
@@ -33,7 +33,7 @@ async function renderToStaticMarkup(Component, props = {}, { default: children =
33
33
  }
34
34
  }
35
35
  function throwEnhancedErrorIfMdxComponent(error, Component) {
36
- if (Component[Symbol.for("mdx-component")]) {
36
+ if (Component[/* @__PURE__ */ Symbol.for("mdx-component")]) {
37
37
  if (AstroError.is(error)) return;
38
38
  error.title = error.name;
39
39
  error.hint = `This issue often occurs when your MDX component encounters runtime errors.`;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { parseFrontmatter } from "@astrojs/markdown-remark";
2
2
  import { parse } from "acorn";
3
- import colors from "picocolors";
3
+ import colors from "piccolore";
4
4
  function appendForwardSlash(path) {
5
5
  return path.endsWith("/") ? path : path + "/";
6
6
  }
@@ -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(code, id, opts) {
14
- if (!id.endsWith(".mdx")) return;
15
- const fileInfo = getFileInfo(id, astroConfig);
16
- const [imports, exports] = parse(code);
17
- code = injectUnderscoreFragmentImport(code, imports);
18
- code = injectMetadataExports(code, exports, fileInfo);
19
- code = transformContentExport(code, exports);
20
- code = annotateContentExport(code, id, !!opts?.ssr, imports);
21
- return { code, map: null };
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
  }
@@ -18,48 +18,58 @@ function vitePluginMdx(opts) {
18
18
  resolved.plugins.splice(jsxPluginIndex, 1);
19
19
  }
20
20
  },
21
- async resolveId(source, importer, options) {
22
- if (importer?.endsWith(".mdx") && source[0] !== "/") {
23
- let resolved = await this.resolve(source, importer, options);
24
- if (!resolved) resolved = await this.resolve("./" + source, importer, options);
25
- return resolved;
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
- async transform(code, id) {
31
- if (!id.endsWith(".mdx")) return;
32
- const { frontmatter, content } = safeParseFrontmatter(code, id);
33
- const vfile = new VFile({
34
- value: content,
35
- path: id,
36
- data: {
37
- astro: {
38
- frontmatter
39
- },
40
- applyFrontmatterExport: {
41
- srcDir: opts.srcDir
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
- try {
51
- const compiled = await processor.process(vfile);
52
- return {
53
- code: String(compiled.value),
54
- map: compiled.map,
55
- meta: getMdxMeta(vfile)
56
- };
57
- } catch (e) {
58
- const err = e;
59
- err.name = "MDXError";
60
- err.loc = { file: id, line: e.line, column: e.column };
61
- Error.captureStackTrace(err);
62
- throw err;
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-alpha.0",
4
+ "version": "5.0.0-beta.10",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -29,27 +29,29 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "@mdx-js/mdx": "^3.1.1",
32
- "acorn": "^8.15.0",
33
- "es-module-lexer": "^1.7.0",
32
+ "acorn": "^8.16.0",
33
+ "es-module-lexer": "^2.0.0",
34
34
  "estree-util-visit": "^2.0.0",
35
35
  "hast-util-to-html": "^9.0.5",
36
- "picocolors": "^1.1.1",
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
- "unist-util-visit": "^5.0.0",
41
+ "unist-util-visit": "^5.1.0",
42
42
  "vfile": "^6.0.3",
43
- "@astrojs/markdown-remark": "7.0.0-alpha.0"
43
+ "@astrojs/markdown-remark": "7.0.0-beta.9"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "astro": "^6.0.0-alpha.0"
47
47
  },
48
48
  "devDependencies": {
49
+ "@shikijs/rehype": "^4.0.0",
50
+ "@shikijs/twoslash": "^4.0.0",
49
51
  "@types/estree": "^1.0.8",
50
52
  "@types/hast": "^3.0.4",
51
53
  "@types/mdast": "^4.0.4",
52
- "cheerio": "1.1.2",
54
+ "cheerio": "1.2.0",
53
55
  "linkedom": "^0.18.12",
54
56
  "mdast-util-mdx": "^3.0.0",
55
57
  "mdast-util-mdx-jsx": "^3.2.0",
@@ -57,16 +59,15 @@
57
59
  "rehype-pretty-code": "^0.14.1",
58
60
  "remark-math": "^6.0.0",
59
61
  "remark-rehype": "^11.1.2",
60
- "remark-shiki-twoslash": "^3.1.3",
61
62
  "remark-toc": "^9.0.0",
62
- "shiki": "^3.12.0",
63
+ "shiki": "^4.0.0",
63
64
  "unified": "^11.0.5",
64
- "vite": "^7.1.7",
65
- "astro": "6.0.0-alpha.0",
66
- "astro-scripts": "0.0.14"
65
+ "vite": "^7.3.1",
66
+ "astro-scripts": "0.0.14",
67
+ "astro": "6.0.0-beta.18"
67
68
  },
68
69
  "engines": {
69
- "node": "^20.19.5 || >=22.12.0"
70
+ "node": "^20.19.1 || >=22.12.0"
70
71
  },
71
72
  "publishConfig": {
72
73
  "provenance": true