@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 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.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
- "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
41
  "unist-util-visit": "^5.0.0",
42
42
  "vfile": "^6.0.3",
43
- "@astrojs/markdown-remark": "7.0.0-alpha.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.12.0",
62
+ "shiki": "^3.20.0",
63
63
  "unified": "^11.0.5",
64
64
  "vite": "^7.1.7",
65
- "astro": "6.0.0-alpha.0",
65
+ "astro": "6.0.0-beta.1",
66
66
  "astro-scripts": "0.0.14"
67
67
  },
68
68
  "engines": {