@astrojs/mdx 0.18.2 → 0.18.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.
@@ -1,5 +1,5 @@
1
- @astrojs/mdx:build: cache hit, replaying output 83b53c3b3706ec68
1
+ @astrojs/mdx:build: cache hit, replaying output dc77e5588cbd224c
2
2
  @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.18.2 build /home/runner/work/astro/astro/packages/integrations/mdx
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.18.4 build /home/runner/work/astro/astro/packages/integrations/mdx
4
4
  @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
5
  @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.18.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6817](https://github.com/withastro/astro/pull/6817) [`f882bc163`](https://github.com/withastro/astro/commit/f882bc1636d5ce1c3b8faae47df36b4dc758045a) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix sourcemap warnings when using Content Collections and MDX with the `vite.build.sourcemap` option
8
+
9
+ ## 0.18.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [#6779](https://github.com/withastro/astro/pull/6779) [`a98f6f418`](https://github.com/withastro/astro/commit/a98f6f418c92261a06ef79624a8c86e288c21eab) Thanks [@matthewp](https://github.com/matthewp)! - Prevent body head content injection in MDX when using layout
14
+
3
15
  ## 0.18.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import mdxPlugin from "@mdx-js/rollup";
5
5
  import { parse as parseESM } from "es-module-lexer";
6
6
  import fs from "node:fs/promises";
7
7
  import { fileURLToPath } from "node:url";
8
+ import { SourceMapGenerator } from "source-map";
8
9
  import { VFile } from "vfile";
9
10
  import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from "./plugins.js";
10
11
  import { getFileInfo, ignoreStringPlugins, parseFrontmatter } from "./utils.js";
@@ -64,6 +65,7 @@ function mdx(partialMdxOptions = {}) {
64
65
  // Override transform to alter code before MDX compilation
65
66
  // ex. inject layouts
66
67
  async transform(_, id) {
68
+ var _a;
67
69
  if (!id.endsWith("mdx"))
68
70
  return;
69
71
  const { fileId } = getFileInfo(id, config);
@@ -80,7 +82,8 @@ function mdx(partialMdxOptions = {}) {
80
82
  recmaPlugins: [
81
83
  ...mdxPluginOpts.recmaPlugins ?? [],
82
84
  () => recmaInjectImportMetaEnvPlugin({ importMetaEnv })
83
- ]
85
+ ],
86
+ SourceMapGenerator: ((_a = config.vite.build) == null ? void 0 : _a.sourcemap) ? SourceMapGenerator : void 0
84
87
  });
85
88
  return {
86
89
  code: escapeViteEnvReferences(String(compiled.value)),
@@ -122,13 +125,15 @@ export const Content = (props = {}) => MDXContent({
122
125
  }
123
126
  code += `
124
127
  Content[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);`;
128
+ code += `
129
+ Content.moduleId = ${JSON.stringify(id)};`;
125
130
  if (command === "dev") {
126
131
  code += `
127
132
  if (import.meta.hot) {
128
133
  import.meta.hot.decline();
129
134
  }`;
130
135
  }
131
- return escapeViteEnvReferences(code);
136
+ return { code: escapeViteEnvReferences(code), map: null };
132
137
  }
133
138
  }
134
139
  ]
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.2",
4
+ "version": "0.18.4",
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.1",
26
+ "@astrojs/markdown-remark": "^2.1.3",
27
27
  "@astrojs/prism": "^2.1.1",
28
28
  "@mdx-js/mdx": "^2.3.0",
29
29
  "@mdx-js/rollup": "^2.3.0",
@@ -38,6 +38,7 @@
38
38
  "remark-gfm": "^3.0.1",
39
39
  "remark-smartypants": "^2.0.0",
40
40
  "shiki": "^0.11.1",
41
+ "source-map": "^0.7.4",
41
42
  "unist-util-visit": "^4.1.0",
42
43
  "vfile": "^5.3.2"
43
44
  },
@@ -48,7 +49,7 @@
48
49
  "@types/mdast": "^3.0.10",
49
50
  "@types/mocha": "^9.1.1",
50
51
  "@types/yargs-parser": "^21.0.0",
51
- "astro": "2.1.4",
52
+ "astro": "2.2.3",
52
53
  "astro-scripts": "0.0.14",
53
54
  "chai": "^4.3.6",
54
55
  "cheerio": "^1.0.0-rc.11",
@@ -63,7 +64,7 @@
63
64
  "remark-rehype": "^10.1.0",
64
65
  "remark-shiki-twoslash": "^3.1.0",
65
66
  "remark-toc": "^8.0.1",
66
- "vite": "^4.1.2"
67
+ "vite": "^4.2.1"
67
68
  },
68
69
  "engines": {
69
70
  "node": ">=16.12.0"
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import { parse as parseESM } from 'es-module-lexer';
8
8
  import fs from 'node:fs/promises';
9
9
  import { fileURLToPath } from 'node:url';
10
10
  import type { Options as RemarkRehypeOptions } from 'remark-rehype';
11
+ import { SourceMapGenerator } from 'source-map';
11
12
  import { VFile } from 'vfile';
12
13
  import type { Plugin as VitePlugin } from 'vite';
13
14
  import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js';
@@ -113,6 +114,9 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
113
114
  ...(mdxPluginOpts.recmaPlugins ?? []),
114
115
  () => recmaInjectImportMetaEnvPlugin({ importMetaEnv }),
115
116
  ],
117
+ SourceMapGenerator: config.vite.build?.sourcemap
118
+ ? SourceMapGenerator
119
+ : undefined,
116
120
  });
117
121
 
118
122
  return {
@@ -160,6 +164,7 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
160
164
  // Ensures styles and scripts are injected into a `<head>`
161
165
  // When a layout is not applied
162
166
  code += `\nContent[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);`;
167
+ code += `\nContent.moduleId = ${JSON.stringify(id)};`;
163
168
 
164
169
  if (command === 'dev') {
165
170
  // TODO: decline HMR updates until we have a stable approach
@@ -167,7 +172,7 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
167
172
  import.meta.hot.decline();
168
173
  }`;
169
174
  }
170
- return escapeViteEnvReferences(code);
175
+ return { code: escapeViteEnvReferences(code), map: null };
171
176
  },
172
177
  },
173
178
  ] as VitePlugin[],
@@ -81,5 +81,18 @@ describe('Head injection w/ MDX', () => {
81
81
  const bodyLinks = $('body link[rel=stylesheet]');
82
82
  expect(bodyLinks).to.have.a.lengthOf(0);
83
83
  });
84
+
85
+ it('Injection caused by delayed slots', async () => {
86
+ const html = await fixture.readFile('/componentwithtext/index.html');
87
+
88
+ // Using cheerio here because linkedom doesn't support head tag injection
89
+ const $ = cheerio.load(html);
90
+
91
+ const headLinks = $('head link[rel=stylesheet]');
92
+ expect(headLinks).to.have.a.lengthOf(1);
93
+
94
+ const bodyLinks = $('body link[rel=stylesheet]');
95
+ expect(bodyLinks).to.have.a.lengthOf(0);
96
+ });
84
97
  });
85
98
  });
@@ -0,0 +1,14 @@
1
+ ---
2
+ const { inlineStyle, title, display = 'horizontal' } = Astro.props;
3
+ const lineEnding = display === 'horizontal' ? ', ' : '<br>';
4
+ ---
5
+
6
+ {title && <h2 set:html={title} />}
7
+ <address style={inlineStyle}>
8
+ <span class="name">some name</span><Fragment set:html={lineEnding} />
9
+ line 1<Fragment set:html={lineEnding} />
10
+ line 2<Fragment set:html={lineEnding} />
11
+ line 3<Fragment set:html={lineEnding} />
12
+ line 4<Fragment set:html={lineEnding} />
13
+ line 5
14
+ </address>
@@ -0,0 +1,15 @@
1
+ ---
2
+ // Extend the BaseLayout, adding space for a banner at the top of the page
3
+ // after the main heading, then the detail for the actual page
4
+ import ContentLayout from './ContentLayout.astro';
5
+ const { frontmatter } = Astro.props;
6
+ ---
7
+
8
+ <ContentLayout>
9
+ <div class="content-container">
10
+ <article id="main-content" class="pad-z5 flow">
11
+ <h1 set:html={frontmatter.pageHeading ? frontmatter.pageHeading : frontmatter.title} />
12
+ <slot />
13
+ </article>
14
+ </div>
15
+ </ContentLayout>
@@ -0,0 +1,12 @@
1
+ ---
2
+ layout: ../layouts/DocumentLayout.astro
3
+ title: blah blah
4
+ ---
5
+
6
+ import BasicBlock from '../components/BasicBlock.astro';
7
+
8
+ Some text for a paragraph.
9
+
10
+ <BasicBlock title="This causes css in wrong place." />
11
+
12
+ Some other text.