@astrojs/mdx 0.18.4 → 0.19.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.
Files changed (30) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +20 -0
  3. package/dist/plugins.js +5 -2
  4. package/dist/remark-images-to-component.d.ts +2 -0
  5. package/dist/remark-images-to-component.js +84 -0
  6. package/dist/remark-shiki.js +17 -0
  7. package/package.json +6 -6
  8. package/src/plugins.ts +5 -2
  9. package/src/remark-images-to-component.ts +98 -0
  10. package/src/remark-shiki.ts +20 -0
  11. package/test/fixtures/css-head-mdx/node_modules/.bin/astro +2 -2
  12. package/test/fixtures/mdx-frontmatter-injection/node_modules/.bin/astro +2 -2
  13. package/test/fixtures/mdx-images/astro.config.ts +8 -0
  14. package/test/fixtures/mdx-images/node_modules/.bin/astro +17 -0
  15. package/test/fixtures/mdx-images/package.json +10 -0
  16. package/test/fixtures/mdx-images/src/assets/houston in space.webp +0 -0
  17. package/test/fixtures/mdx-images/src/assets/houston.webp +0 -0
  18. package/test/fixtures/mdx-images/src/pages/index.mdx +11 -0
  19. package/test/fixtures/mdx-infinite-loop/node_modules/.bin/astro +2 -2
  20. package/test/fixtures/mdx-infinite-loop/package.json +1 -0
  21. package/test/fixtures/mdx-namespace/node_modules/.bin/astro +2 -2
  22. package/test/fixtures/mdx-namespace/package.json +1 -0
  23. package/test/fixtures/mdx-page/node_modules/.bin/astro +2 -2
  24. package/test/fixtures/mdx-page/package.json +1 -0
  25. package/test/fixtures/mdx-plus-react/node_modules/.bin/astro +2 -2
  26. package/test/fixtures/mdx-plus-react/package.json +1 -0
  27. package/test/fixtures/mdx-vite-env-vars/node_modules/.bin/astro +2 -2
  28. package/test/fixtures/mdx-vite-env-vars/package.json +1 -0
  29. package/test/mdx-images.test.js +40 -0
  30. package/test/mdx-syntax-highlighting.test.js +1 -1
@@ -1,5 +1,4 @@
1
- @astrojs/mdx:build: cache hit, replaying output dc77e5588cbd224c
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.18.4 build /home/runner/work/astro/astro/packages/integrations/mdx
4
- @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/mdx:build: 
1
+
2
+ > @astrojs/mdx@0.19.1 build /home/runner/work/astro/astro/packages/integrations/mdx
3
+ > astro-scripts build "src/**/*.ts" && tsc
4
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6932](https://github.com/withastro/astro/pull/6932) [`49514e4ce`](https://github.com/withastro/astro/commit/49514e4ce40fedb39bf7decd2c296258efbdafc7) Thanks [@bluwy](https://github.com/bluwy)! - Upgrade shiki to v0.14.1. This updates the shiki theme colors and adds the theme name to the `pre` tag, e.g. `<pre class="astro-code github-dark">`.
8
+
9
+ - Updated dependencies [[`49514e4ce`](https://github.com/withastro/astro/commit/49514e4ce40fedb39bf7decd2c296258efbdafc7)]:
10
+ - @astrojs/markdown-remark@2.2.0
11
+
12
+ ## 0.19.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#6824](https://github.com/withastro/astro/pull/6824) [`2511d58d5`](https://github.com/withastro/astro/commit/2511d58d586af080a78e5ef8a63020b3e17770db) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Add support for using optimized and relative images in MDX files with `experimental.assets`
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`2511d58d5`](https://github.com/withastro/astro/commit/2511d58d586af080a78e5ef8a63020b3e17770db)]:
21
+ - @astrojs/markdown-remark@2.1.4
22
+
3
23
  ## 0.18.4
4
24
 
5
25
  ### Patch Changes
package/dist/plugins.js CHANGED
@@ -1,4 +1,4 @@
1
- import { rehypeHeadingIds } from "@astrojs/markdown-remark";
1
+ import { rehypeHeadingIds, remarkCollectImages } from "@astrojs/markdown-remark";
2
2
  import {
3
3
  InvalidAstroDataError,
4
4
  safelyGetAstroData
@@ -10,6 +10,7 @@ import remarkGfm from "remark-gfm";
10
10
  import remarkSmartypants from "remark-smartypants";
11
11
  import { rehypeInjectHeadingsExport } from "./rehype-collect-headings.js";
12
12
  import rehypeMetaString from "./rehype-meta-string.js";
13
+ import { remarkImageToComponent } from "./remark-images-to-component.js";
13
14
  import remarkPrism from "./remark-prism.js";
14
15
  import remarkShiki from "./remark-shiki.js";
15
16
  import { jsToTreeNode } from "./utils.js";
@@ -77,7 +78,9 @@ function rehypeApplyFrontmatterExport() {
77
78
  };
78
79
  }
79
80
  async function getRemarkPlugins(mdxOptions, config) {
80
- let remarkPlugins = [];
81
+ let remarkPlugins = [
82
+ ...config.experimental.assets ? [remarkCollectImages, remarkImageToComponent] : []
83
+ ];
81
84
  if (!isPerformanceBenchmark) {
82
85
  if (mdxOptions.gfm) {
83
86
  remarkPlugins.push(remarkGfm);
@@ -0,0 +1,2 @@
1
+ import type { MarkdownVFile } from '@astrojs/markdown-remark';
2
+ export declare function remarkImageToComponent(): (tree: any, file: MarkdownVFile) => void;
@@ -0,0 +1,84 @@
1
+ import { visit } from "unist-util-visit";
2
+ import { jsToTreeNode } from "./utils.js";
3
+ function remarkImageToComponent() {
4
+ return function(tree, file) {
5
+ if (!file.data.imagePaths)
6
+ return;
7
+ const importsStatements = [];
8
+ const importedImages = /* @__PURE__ */ new Map();
9
+ visit(tree, "image", (node, index, parent) => {
10
+ var _a;
11
+ if ((_a = file.data.imagePaths) == null ? void 0 : _a.has(node.url)) {
12
+ let importName = importedImages.get(node.url);
13
+ if (!importName) {
14
+ importName = `__${importedImages.size}_${node.url.replace(/\W/g, "_")}__`;
15
+ importsStatements.push({
16
+ type: "mdxjsEsm",
17
+ value: "",
18
+ data: {
19
+ estree: {
20
+ type: "Program",
21
+ sourceType: "module",
22
+ body: [
23
+ {
24
+ type: "ImportDeclaration",
25
+ source: { type: "Literal", value: node.url, raw: JSON.stringify(node.url) },
26
+ specifiers: [
27
+ {
28
+ type: "ImportDefaultSpecifier",
29
+ local: { type: "Identifier", name: importName }
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ });
37
+ importedImages.set(node.url, importName);
38
+ }
39
+ const componentElement = {
40
+ name: "__AstroImage__",
41
+ type: "mdxJsxFlowElement",
42
+ attributes: [
43
+ {
44
+ name: "src",
45
+ type: "mdxJsxAttribute",
46
+ value: {
47
+ type: "mdxJsxAttributeValueExpression",
48
+ value: importName,
49
+ data: {
50
+ estree: {
51
+ type: "Program",
52
+ sourceType: "module",
53
+ comments: [],
54
+ body: [
55
+ {
56
+ type: "ExpressionStatement",
57
+ expression: { type: "Identifier", name: importName }
58
+ }
59
+ ]
60
+ }
61
+ }
62
+ }
63
+ },
64
+ { name: "alt", type: "mdxJsxAttribute", value: node.alt || "" }
65
+ ],
66
+ children: []
67
+ };
68
+ if (node.title) {
69
+ componentElement.attributes.push({
70
+ type: "mdxJsxAttribute",
71
+ name: "title",
72
+ value: node.title
73
+ });
74
+ }
75
+ parent.children.splice(index, 1, componentElement);
76
+ }
77
+ });
78
+ tree.children.unshift(...importsStatements);
79
+ tree.children.unshift(jsToTreeNode(`import { Image as __AstroImage__ } from "astro:assets";`));
80
+ };
81
+ }
82
+ export {
83
+ remarkImageToComponent
84
+ };
@@ -1,7 +1,24 @@
1
1
  import { getHighlighter } from "shiki";
2
2
  import { visit } from "unist-util-visit";
3
3
  const highlighterCacheAsync = /* @__PURE__ */ new Map();
4
+ const compatThemes = {
5
+ "material-darker": "material-theme-darker",
6
+ "material-default": "material-theme",
7
+ "material-lighter": "material-theme-lighter",
8
+ "material-ocean": "material-theme-ocean",
9
+ "material-palenight": "material-theme-palenight"
10
+ };
11
+ const normalizeTheme = (theme) => {
12
+ if (typeof theme === "string") {
13
+ return compatThemes[theme] || theme;
14
+ } else if (compatThemes[theme.name]) {
15
+ return { ...theme, name: compatThemes[theme.name] };
16
+ } else {
17
+ return theme;
18
+ }
19
+ };
4
20
  const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }) => {
21
+ theme = normalizeTheme(theme);
5
22
  const cacheID = typeof theme === "string" ? theme : theme.name;
6
23
  let highlighterAsync = highlighterCacheAsync.get(cacheID);
7
24
  if (!highlighterAsync) {
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": "0.18.4",
4
+ "version": "0.19.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -23,7 +23,7 @@
23
23
  "./package.json": "./package.json"
24
24
  },
25
25
  "dependencies": {
26
- "@astrojs/markdown-remark": "^2.1.3",
26
+ "@astrojs/markdown-remark": "^2.2.0",
27
27
  "@astrojs/prism": "^2.1.1",
28
28
  "@mdx-js/mdx": "^2.3.0",
29
29
  "@mdx-js/rollup": "^2.3.0",
@@ -37,7 +37,7 @@
37
37
  "remark-frontmatter": "^4.0.1",
38
38
  "remark-gfm": "^3.0.1",
39
39
  "remark-smartypants": "^2.0.0",
40
- "shiki": "^0.11.1",
40
+ "shiki": "^0.14.1",
41
41
  "source-map": "^0.7.4",
42
42
  "unist-util-visit": "^4.1.0",
43
43
  "vfile": "^5.3.2"
@@ -49,8 +49,6 @@
49
49
  "@types/mdast": "^3.0.10",
50
50
  "@types/mocha": "^9.1.1",
51
51
  "@types/yargs-parser": "^21.0.0",
52
- "astro": "2.2.3",
53
- "astro-scripts": "0.0.14",
54
52
  "chai": "^4.3.6",
55
53
  "cheerio": "^1.0.0-rc.11",
56
54
  "linkedom": "^0.14.12",
@@ -64,7 +62,9 @@
64
62
  "remark-rehype": "^10.1.0",
65
63
  "remark-shiki-twoslash": "^3.1.0",
66
64
  "remark-toc": "^8.0.1",
67
- "vite": "^4.2.1"
65
+ "vite": "^4.3.1",
66
+ "astro": "2.4.0",
67
+ "astro-scripts": "0.0.14"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=16.12.0"
package/src/plugins.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { rehypeHeadingIds } from '@astrojs/markdown-remark';
1
+ import { rehypeHeadingIds, remarkCollectImages } from '@astrojs/markdown-remark';
2
2
  import {
3
3
  InvalidAstroDataError,
4
4
  safelyGetAstroData,
@@ -16,6 +16,7 @@ import type { VFile } from 'vfile';
16
16
  import type { MdxOptions } from './index.js';
17
17
  import { rehypeInjectHeadingsExport } from './rehype-collect-headings.js';
18
18
  import rehypeMetaString from './rehype-meta-string.js';
19
+ import { remarkImageToComponent } from './remark-images-to-component.js';
19
20
  import remarkPrism from './remark-prism.js';
20
21
  import remarkShiki from './remark-shiki.js';
21
22
  import { jsToTreeNode } from './utils.js';
@@ -99,7 +100,9 @@ export async function getRemarkPlugins(
99
100
  mdxOptions: MdxOptions,
100
101
  config: AstroConfig
101
102
  ): Promise<MdxRollupPluginOptions['remarkPlugins']> {
102
- let remarkPlugins: PluggableList = [];
103
+ let remarkPlugins: PluggableList = [
104
+ ...(config.experimental.assets ? [remarkCollectImages, remarkImageToComponent] : []),
105
+ ];
103
106
 
104
107
  if (!isPerformanceBenchmark) {
105
108
  if (mdxOptions.gfm) {
@@ -0,0 +1,98 @@
1
+ import type { MarkdownVFile } from '@astrojs/markdown-remark';
2
+ import { type Image, type Parent } from 'mdast';
3
+ import type { MdxjsEsm, MdxJsxFlowElement } from 'mdast-util-mdx';
4
+ import { visit } from 'unist-util-visit';
5
+ import { jsToTreeNode } from './utils.js';
6
+
7
+ export function remarkImageToComponent() {
8
+ return function (tree: any, file: MarkdownVFile) {
9
+ if (!file.data.imagePaths) return;
10
+
11
+ const importsStatements: MdxjsEsm[] = [];
12
+ const importedImages = new Map<string, string>();
13
+
14
+ visit(tree, 'image', (node: Image, index: number | null, parent: Parent | null) => {
15
+ // Use the imagePaths set from the remark-collect-images so we don't have to duplicate the logic for
16
+ // checking if an image should be imported or not
17
+ if (file.data.imagePaths?.has(node.url)) {
18
+ let importName = importedImages.get(node.url);
19
+
20
+ // If we haven't already imported this image, add an import statement
21
+ if (!importName) {
22
+ importName = `__${importedImages.size}_${node.url.replace(/\W/g, '_')}__`;
23
+
24
+ importsStatements.push({
25
+ type: 'mdxjsEsm',
26
+ value: '',
27
+ data: {
28
+ estree: {
29
+ type: 'Program',
30
+ sourceType: 'module',
31
+ body: [
32
+ {
33
+ type: 'ImportDeclaration',
34
+ source: { type: 'Literal', value: node.url, raw: JSON.stringify(node.url) },
35
+ specifiers: [
36
+ {
37
+ type: 'ImportDefaultSpecifier',
38
+ local: { type: 'Identifier', name: importName },
39
+ },
40
+ ],
41
+ },
42
+ ],
43
+ },
44
+ },
45
+ });
46
+ importedImages.set(node.url, importName);
47
+ }
48
+
49
+ // Build a component that's equivalent to <Image src={importName} alt={node.alt} title={node.title} />
50
+ const componentElement: MdxJsxFlowElement = {
51
+ name: '__AstroImage__',
52
+ type: 'mdxJsxFlowElement',
53
+ attributes: [
54
+ {
55
+ name: 'src',
56
+ type: 'mdxJsxAttribute',
57
+ value: {
58
+ type: 'mdxJsxAttributeValueExpression',
59
+ value: importName,
60
+ data: {
61
+ estree: {
62
+ type: 'Program',
63
+ sourceType: 'module',
64
+ comments: [],
65
+ body: [
66
+ {
67
+ type: 'ExpressionStatement',
68
+ expression: { type: 'Identifier', name: importName },
69
+ },
70
+ ],
71
+ },
72
+ },
73
+ },
74
+ },
75
+ { name: 'alt', type: 'mdxJsxAttribute', value: node.alt || '' },
76
+ ],
77
+ children: [],
78
+ };
79
+
80
+ if (node.title) {
81
+ componentElement.attributes.push({
82
+ type: 'mdxJsxAttribute',
83
+ name: 'title',
84
+ value: node.title,
85
+ });
86
+ }
87
+
88
+ parent!.children.splice(index!, 1, componentElement);
89
+ }
90
+ });
91
+
92
+ // Add all the import statements to the top of the file for the images
93
+ tree.children.unshift(...importsStatements);
94
+
95
+ // Add an import statement for the Astro Image component, we rename it to avoid conflicts
96
+ tree.children.unshift(jsToTreeNode(`import { Image as __AstroImage__ } from "astro:assets";`));
97
+ };
98
+ }
@@ -10,7 +10,27 @@ import { visit } from 'unist-util-visit';
10
10
  */
11
11
  const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
12
12
 
13
+ // Map of old theme names to new names to preserve compatibility when we upgrade shiki
14
+ const compatThemes: Record<string, string> = {
15
+ 'material-darker': 'material-theme-darker',
16
+ 'material-default': 'material-theme',
17
+ 'material-lighter': 'material-theme-lighter',
18
+ 'material-ocean': 'material-theme-ocean',
19
+ 'material-palenight': 'material-theme-palenight',
20
+ };
21
+
22
+ const normalizeTheme = (theme: string | shiki.IShikiTheme) => {
23
+ if (typeof theme === 'string') {
24
+ return compatThemes[theme] || theme;
25
+ } else if (compatThemes[theme.name]) {
26
+ return { ...theme, name: compatThemes[theme.name] };
27
+ } else {
28
+ return theme;
29
+ }
30
+ };
31
+
13
32
  const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig) => {
33
+ theme = normalizeTheme(theme);
14
34
  const cacheID: string = typeof theme === 'string' ? theme : theme.name;
15
35
  let highlighterAsync = highlighterCacheAsync.get(cacheID);
16
36
  if (!highlighterAsync) {
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -0,0 +1,8 @@
1
+ import mdx from '@astrojs/mdx';
2
+
3
+ export default {
4
+ integrations: [mdx()],
5
+ experimental: {
6
+ assets: true
7
+ }
8
+ }
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
15
+ else
16
+ exec node "$basedir/../../../../../../../astro/astro.js" "$@"
17
+ fi
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@test/mdx-images",
3
+ "private": true,
4
+ "dependencies": {
5
+ "@astrojs/mdx": "workspace:*",
6
+ "astro": "workspace:*",
7
+ "react": "^18.2.0",
8
+ "react-dom": "^18.2.0"
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ Image using a relative path:
2
+ ![Houston](../assets/houston.webp)
3
+
4
+ Image using an aliased path:
5
+ ![Houston](~/assets/houston.webp)
6
+
7
+ Image with a title:
8
+ ![Houston](~/assets/houston.webp "Houston title")
9
+
10
+ Image with spaces in the path:
11
+ ![Houston](<~/assets/houston in space.webp>)
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@test/mdx-infinite-loop",
3
3
  "type": "module",
4
+ "private": true,
4
5
  "dependencies": {
5
6
  "@astrojs/mdx": "workspace:*",
6
7
  "@astrojs/preact": "workspace:*",
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@test/mdx-namespace",
3
+ "private": true,
3
4
  "dependencies": {
4
5
  "@astrojs/mdx": "workspace:*",
5
6
  "@astrojs/react": "workspace:*",
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@test/mdx-page",
3
+ "private": true,
3
4
  "dependencies": {
4
5
  "@astrojs/mdx": "workspace:*",
5
6
  "astro": "workspace:*",
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@test/mdx-plus-react",
3
+ "private": true,
3
4
  "dependencies": {
4
5
  "@astrojs/mdx": "workspace:*",
5
6
  "@astrojs/react": "workspace:*",
@@ -6,9 +6,9 @@ case `uname` in
6
6
  esac
7
7
 
8
8
  if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
9
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
10
  else
11
- export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
11
+ export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
12
  fi
13
13
  if [ -x "$basedir/node" ]; then
14
14
  exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@test/mdx-env-variables",
3
+ "private": true,
3
4
  "dependencies": {
4
5
  "astro": "workspace:*",
5
6
  "@astrojs/mdx": "workspace:*"
@@ -0,0 +1,40 @@
1
+ import { expect } from 'chai';
2
+ import { parseHTML } from 'linkedom';
3
+ import { loadFixture } from '../../../astro/test/test-utils.js';
4
+
5
+ describe('MDX Page', () => {
6
+ let devServer;
7
+ let fixture;
8
+
9
+ before(async () => {
10
+ fixture = await loadFixture({
11
+ root: new URL('./fixtures/mdx-images/', import.meta.url),
12
+ });
13
+ devServer = await fixture.startDevServer();
14
+ });
15
+
16
+ after(async () => {
17
+ await devServer.stop();
18
+ });
19
+
20
+ describe('Optimized images in MDX', () => {
21
+ it('works', async () => {
22
+ const res = await fixture.fetch('/');
23
+ expect(res.status).to.equal(200);
24
+
25
+ const html = await res.text();
26
+ const { document } = parseHTML(html);
27
+
28
+ const imgs = document.getElementsByTagName('img');
29
+ expect(imgs.length).to.equal(4);
30
+ // Image using a relative path
31
+ expect(imgs.item(0).src.startsWith('/_image')).to.be.true;
32
+ // Image using an aliased path
33
+ expect(imgs.item(1).src.startsWith('/_image')).to.be.true;
34
+ // Image with title
35
+ expect(imgs.item(2).title).to.equal('Houston title');
36
+ // Image with spaces in the path
37
+ expect(imgs.item(3).src.startsWith('/_image')).to.be.true;
38
+ });
39
+ });
40
+ });
@@ -25,7 +25,7 @@ describe('MDX syntax highlighting', () => {
25
25
 
26
26
  const shikiCodeBlock = document.querySelector('pre.astro-code');
27
27
  expect(shikiCodeBlock).to.not.be.null;
28
- expect(shikiCodeBlock.getAttribute('style')).to.contain('background-color:#0d1117');
28
+ expect(shikiCodeBlock.getAttribute('style')).to.contain('background-color:#24292e');
29
29
  });
30
30
 
31
31
  it('respects markdown.shikiConfig.theme', async () => {