@astrojs/mdx 0.10.0 → 0.10.2

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 9de770958d53d2f8
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.10.0 build /home/runner/work/astro/astro/packages/integrations/mdx
4
- @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/mdx:build: 
1
+ @astrojs/mdx:build: cache hit, replaying output 97b75f35cc1d424b
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.10.2 build /home/runner/work/astro/astro/packages/integrations/mdx
4
+ @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.10.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4423](https://github.com/withastro/astro/pull/4423) [`d4cd7a59f`](https://github.com/withastro/astro/commit/d4cd7a59fd38d411c442a818cfaab40f74106628) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Update Markdown type signature to match new markdown plugin,and update top-level layout props for better alignment
8
+
9
+ ## 0.10.2-next.0
10
+
11
+ ### Patch Changes
12
+
13
+ - [#4423](https://github.com/withastro/astro/pull/4423) [`d4cd7a59f`](https://github.com/withastro/astro/commit/d4cd7a59fd38d411c442a818cfaab40f74106628) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Update Markdown type signature to match new markdown plugin,and update top-level layout props for better alignment
14
+
15
+ ## 0.10.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#4443](https://github.com/withastro/astro/pull/4443) [`adb207979`](https://github.com/withastro/astro/commit/adb20797962c280d4d38f335f577fd52a1b48d4b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix MDX style imports when layout is not applied
20
+
21
+ * [#4428](https://github.com/withastro/astro/pull/4428) [`a2414bf59`](https://github.com/withastro/astro/commit/a2414bf59e2e2cd633aece68e724401c4ad281b9) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix dev server reload performance when globbing from an MDX layout
22
+
3
23
  ## 0.10.0
4
24
 
5
25
  ### Minor Changes
@@ -18,9 +18,9 @@ function rehypeApplyFrontmatterExport(pageFrontmatter) {
18
18
  exportNodes.unshift(
19
19
  jsToTreeNode(
20
20
  `import { jsx as layoutJsx } from 'astro/jsx-runtime';
21
- import Layout from ${JSON.stringify(frontmatter.layout)};
22
21
 
23
- export default function ({ children }) {
22
+ export default async function ({ children }) {
23
+ const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
24
24
  const { layout, ...content } = frontmatter;
25
25
  content.file = file;
26
26
  content.url = url;
@@ -41,6 +41,8 @@ function rehypeApplyFrontmatterExport(pageFrontmatter) {
41
41
  }
42
42
  });
43
43
  return layoutJsx(Layout, {
44
+ file,
45
+ url,
44
46
  content,
45
47
  frontmatter: content,
46
48
  headings: getHeadings(),
package/dist/index.js CHANGED
@@ -85,6 +85,8 @@ function mdx(mdxOptions = {}) {
85
85
  transform(code, id) {
86
86
  if (!id.endsWith(".mdx"))
87
87
  return;
88
+ code += `
89
+ MDXContent[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);`;
88
90
  const [, moduleExports] = parseESM(code);
89
91
  const { fileUrl, fileId } = getFileInfo(id, config);
90
92
  if (!moduleExports.includes("url")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/mdx",
3
3
  "description": "Use MDX within Astro",
4
- "version": "0.10.0",
4
+ "version": "0.10.2",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -42,7 +42,7 @@
42
42
  "@types/chai": "^4.3.1",
43
43
  "@types/mocha": "^9.1.1",
44
44
  "@types/yargs-parser": "^21.0.0",
45
- "astro": "1.0.6",
45
+ "astro": "1.1.0",
46
46
  "astro-scripts": "0.0.7",
47
47
  "chai": "^4.3.6",
48
48
  "linkedom": "^0.14.12",
@@ -20,13 +20,17 @@ export function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any
20
20
  jsToTreeNode(`export const ${EXPORT_NAME} = ${JSON.stringify(frontmatter)};`),
21
21
  ];
22
22
  if (frontmatter.layout) {
23
+ // NOTE(bholmesdev) 08-22-2022
24
+ // Using an async layout import (i.e. `const Layout = (await import...)`)
25
+ // Preserves the dev server import cache when globbing a large set of MDX files
26
+ // Full explanation: 'https://github.com/withastro/astro/pull/4428'
23
27
  exportNodes.unshift(
24
28
  jsToTreeNode(
25
29
  /** @see 'vite-plugin-markdown' for layout props reference */
26
30
  `import { jsx as layoutJsx } from 'astro/jsx-runtime';
27
- import Layout from ${JSON.stringify(frontmatter.layout)};
28
31
 
29
- export default function ({ children }) {
32
+ export default async function ({ children }) {
33
+ const Layout = (await import(${JSON.stringify(frontmatter.layout)})).default;
30
34
  const { layout, ...content } = frontmatter;
31
35
  content.file = file;
32
36
  content.url = url;
@@ -47,6 +51,8 @@ export function rehypeApplyFrontmatterExport(pageFrontmatter: Record<string, any
47
51
  }
48
52
  });
49
53
  return layoutJsx(Layout, {
54
+ file,
55
+ url,
50
56
  content,
51
57
  frontmatter: content,
52
58
  headings: getHeadings(),
package/src/index.ts CHANGED
@@ -119,6 +119,11 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
119
119
  // These transforms must happen *after* JSX runtime transformations
120
120
  transform(code, id) {
121
121
  if (!id.endsWith('.mdx')) return;
122
+
123
+ // Ensures styles and scripts are injected into a `<head>`
124
+ // When a layout is not applied
125
+ code += `\nMDXContent[Symbol.for('astro.needsHeadRendering')] = !Boolean(frontmatter.layout);`;
126
+
122
127
  const [, moduleExports] = parseESM(code);
123
128
 
124
129
  const { fileUrl, fileId } = getFileInfo(id, config);
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  const {
3
3
  content = { title: "content didn't work" },
4
+ file = "file didn't work",
5
+ url = "url didn't work",
4
6
  frontmatter = {
5
7
  title: "frontmatter didn't work",
6
8
  file: "file didn't work",
@@ -24,6 +26,8 @@ const {
24
26
  <p data-frontmatter-title>{frontmatter.title}</p>
25
27
  <p data-frontmatter-file>{frontmatter.file}</p>
26
28
  <p data-frontmatter-url>{frontmatter.url}</p>
29
+ <p data-file>{frontmatter.file}</p>
30
+ <p data-url>{frontmatter.url}</p>
27
31
  <p data-layout-rendered>Layout rendered!</p>
28
32
  <ul data-headings>
29
33
  {headings.map(heading => <li>{heading.slug}</li>)}
@@ -1 +1,3 @@
1
+ import '../styles.css'
2
+
1
3
  # Hello page!
@@ -0,0 +1,3 @@
1
+ p {
2
+ color: red;
3
+ }
@@ -57,17 +57,21 @@ describe('MDX frontmatter', () => {
57
57
  expect(headingSlugs).to.contain('section-2');
58
58
  });
59
59
 
60
- it('passes "file" and "url" to layout via frontmatter', async () => {
60
+ it('passes "file" and "url" to layout', async () => {
61
61
  const html = await fixture.readFile('/with-headings/index.html');
62
62
  const { document } = parseHTML(html);
63
63
 
64
64
  const frontmatterFile = document.querySelector('[data-frontmatter-file]')?.textContent;
65
65
  const frontmatterUrl = document.querySelector('[data-frontmatter-url]')?.textContent;
66
+ const file = document.querySelector('[data-file]')?.textContent;
67
+ const url = document.querySelector('[data-url]')?.textContent;
66
68
 
67
69
  expect(frontmatterFile?.endsWith('with-headings.mdx')).to.equal(
68
70
  true,
69
71
  '"file" prop does not end with correct path or is undefined'
70
72
  );
71
73
  expect(frontmatterUrl).to.equal('/with-headings');
74
+ expect(file).to.equal(frontmatterFile);
75
+ expect(url).to.equal(frontmatterUrl);
72
76
  });
73
77
  });
@@ -26,6 +26,15 @@ describe('MDX Page', () => {
26
26
 
27
27
  expect(h1.textContent).to.equal('Hello page!');
28
28
  });
29
+
30
+ it('injects style imports when layout is not applied', async () => {
31
+ const html = await fixture.readFile('/index.html');
32
+ const { document } = parseHTML(html);
33
+
34
+ const stylesheet = document.querySelector('link[rel="stylesheet"]');
35
+
36
+ expect(stylesheet).to.not.be.null;
37
+ });
29
38
  });
30
39
 
31
40
  describe('dev', () => {