@astrojs/mdx 0.18.1 → 0.18.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 6863c2b0a0d736f6
2
- @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.18.1 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 83b53c3b3706ec68
2
+ @astrojs/mdx:build: 
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.18.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,14 @@
1
1
  # @astrojs/mdx
2
2
 
3
+ ## 0.18.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6552](https://github.com/withastro/astro/pull/6552) [`392ba3e4d`](https://github.com/withastro/astro/commit/392ba3e4d55f73ce9194bd94a2243f1aa62af079) Thanks [@bluwy](https://github.com/bluwy)! - Fix integration return type
8
+
9
+ - Updated dependencies [[`90e5f87d0`](https://github.com/withastro/astro/commit/90e5f87d03215a833bb6ac91f9548670a25ce659), [`f5fddafc2`](https://github.com/withastro/astro/commit/f5fddafc248bb1ef57b7349bfecc25539ae2b5ea)]:
10
+ - @astrojs/markdown-remark@2.1.1
11
+
3
12
  ## 0.18.1
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,22 +1,12 @@
1
1
  import { markdownConfigDefaults } from '@astrojs/markdown-remark';
2
2
  import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
3
- import type { AstroIntegration, ContentEntryType, HookParameters } from 'astro';
3
+ import type { AstroIntegration } from 'astro';
4
4
  import type { Options as RemarkRehypeOptions } from 'remark-rehype';
5
- export declare type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
5
+ export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | 'rehypePlugins'> & {
6
6
  extendMarkdownConfig: boolean;
7
7
  recmaPlugins: PluggableList;
8
8
  remarkPlugins: PluggableList;
9
9
  rehypePlugins: PluggableList;
10
10
  remarkRehype: RemarkRehypeOptions;
11
11
  };
12
- declare type IntegrationWithPrivateHooks = {
13
- name: string;
14
- hooks: Omit<AstroIntegration['hooks'], 'astro:config:setup'> & {
15
- 'astro:config:setup': (params: HookParameters<'astro:config:setup'> & {
16
- addPageExtension: (extension: string) => void;
17
- addContentEntryType: (contentEntryType: ContentEntryType) => void;
18
- }) => void | Promise<void>;
19
- };
20
- };
21
- export default function mdx(partialMdxOptions?: Partial<MdxOptions>): IntegrationWithPrivateHooks;
22
- export {};
12
+ export default function mdx(partialMdxOptions?: Partial<MdxOptions>): AstroIntegration;
package/dist/index.js CHANGED
@@ -12,13 +12,8 @@ function mdx(partialMdxOptions = {}) {
12
12
  return {
13
13
  name: "@astrojs/mdx",
14
14
  hooks: {
15
- "astro:config:setup": async ({
16
- updateConfig,
17
- config,
18
- addPageExtension,
19
- addContentEntryType,
20
- command
21
- }) => {
15
+ "astro:config:setup": async (params) => {
16
+ const { updateConfig, config, addPageExtension, addContentEntryType, command } = params;
22
17
  addPageExtension(".mdx");
23
18
  addContentEntryType({
24
19
  extensions: [".mdx"],
@@ -50,6 +45,7 @@ function mdx(partialMdxOptions = {}) {
50
45
  remarkRehypeOptions: mdxOptions.remarkRehype,
51
46
  jsx: true,
52
47
  jsxImportSource: "astro",
48
+ // Note: disable `.md` (and other alternative extensions for markdown files like `.markdown`) support
53
49
  format: "mdx",
54
50
  mdExtensions: []
55
51
  };
@@ -65,6 +61,8 @@ function mdx(partialMdxOptions = {}) {
65
61
  configResolved(resolved) {
66
62
  importMetaEnv = { ...importMetaEnv, ...resolved.env };
67
63
  },
64
+ // Override transform to alter code before MDX compilation
65
+ // ex. inject layouts
68
66
  async transform(_, id) {
69
67
  if (!id.endsWith("mdx"))
70
68
  return;
@@ -75,6 +73,7 @@ function mdx(partialMdxOptions = {}) {
75
73
  ...mdxPluginOpts,
76
74
  elementAttributeNameCase: "html",
77
75
  remarkPlugins: [
76
+ // Ensure `data.astro` is available to all remark plugins
78
77
  toRemarkInitializeAstroData({ userFrontmatter: frontmatter }),
79
78
  ...mdxPluginOpts.remarkPlugins ?? []
80
79
  ],
@@ -91,6 +90,7 @@ function mdx(partialMdxOptions = {}) {
91
90
  },
92
91
  {
93
92
  name: "@astrojs/mdx-postprocess",
93
+ // These transforms must happen *after* JSX runtime transformations
94
94
  transform(code, id) {
95
95
  if (!id.endsWith(".mdx"))
96
96
  return;
package/dist/plugins.js CHANGED
@@ -41,6 +41,8 @@ function rehypeApplyFrontmatterExport() {
41
41
  const astroData = safelyGetAstroData(vfile.data);
42
42
  if (astroData instanceof InvalidAstroDataError)
43
43
  throw new Error(
44
+ // Copied from Astro core `errors-data`
45
+ // TODO: find way to import error data from core
44
46
  '[MDX] A remark or rehype plugin attempted to inject invalid frontmatter. Ensure "astro.frontmatter" is set to a valid JSON object that is not `null` or `undefined`.'
45
47
  );
46
48
  const { frontmatter } = astroData;
@@ -50,6 +52,7 @@ function rehypeApplyFrontmatterExport() {
50
52
  if (frontmatter.layout) {
51
53
  exportNodes.unshift(
52
54
  jsToTreeNode(
55
+ /** @see 'vite-plugin-markdown' for layout props reference */
53
56
  `import { jsx as layoutJsx } from 'astro/jsx-runtime';
54
57
 
55
58
  export default async function ({ children }) {
@@ -96,13 +99,18 @@ async function getRemarkPlugins(mdxOptions, config) {
96
99
  }
97
100
  function getRehypePlugins(mdxOptions) {
98
101
  let rehypePlugins = [
102
+ // ensure `data.meta` is preserved in `properties.metastring` for rehype syntax highlighters
99
103
  rehypeMetaString,
104
+ // rehypeRaw allows custom syntax highlighters to work without added config
100
105
  [rehypeRaw, { passThrough: nodeTypes }]
101
106
  ];
102
107
  rehypePlugins = [
103
108
  ...rehypePlugins,
104
109
  ...mdxOptions.rehypePlugins,
110
+ // getHeadings() is guaranteed by TS, so this must be included.
111
+ // We run `rehypeHeadingIds` _last_ to respect any custom IDs set by user plugins.
105
112
  ...isPerformanceBenchmark ? [] : [rehypeHeadingIds, rehypeInjectHeadingsExport],
113
+ // computed from `astro.data.frontmatter` in VFile data
106
114
  rehypeApplyFrontmatterExport
107
115
  ];
108
116
  return rehypePlugins;
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.1",
4
+ "version": "0.18.2",
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.0",
26
+ "@astrojs/markdown-remark": "^2.1.1",
27
27
  "@astrojs/prism": "^2.1.1",
28
28
  "@mdx-js/mdx": "^2.3.0",
29
29
  "@mdx-js/rollup": "^2.3.0",
@@ -48,7 +48,7 @@
48
48
  "@types/mdast": "^3.0.10",
49
49
  "@types/mocha": "^9.1.1",
50
50
  "@types/yargs-parser": "^21.0.0",
51
- "astro": "2.1.3",
51
+ "astro": "2.1.4",
52
52
  "astro-scripts": "0.0.14",
53
53
  "chai": "^4.3.6",
54
54
  "cheerio": "^1.0.0-rc.11",
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import { markdownConfigDefaults } from '@astrojs/markdown-remark';
2
2
  import { toRemarkInitializeAstroData } from '@astrojs/markdown-remark/dist/internal.js';
3
3
  import { compile as mdxCompile } from '@mdx-js/mdx';
4
4
  import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
5
- import mdxPlugin, { Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
5
+ import mdxPlugin, { type Options as MdxRollupPluginOptions } from '@mdx-js/rollup';
6
6
  import type { AstroIntegration, ContentEntryType, HookParameters } from 'astro';
7
7
  import { parse as parseESM } from 'es-module-lexer';
8
8
  import fs from 'node:fs/promises';
@@ -23,33 +23,21 @@ export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | '
23
23
  remarkRehype: RemarkRehypeOptions;
24
24
  };
25
25
 
26
- type IntegrationWithPrivateHooks = {
27
- name: string;
28
- hooks: Omit<AstroIntegration['hooks'], 'astro:config:setup'> & {
29
- 'astro:config:setup': (
30
- params: HookParameters<'astro:config:setup'> & {
31
- // `addPageExtension` and `contentEntryType` are not a public APIs
32
- // Add type defs here
33
- addPageExtension: (extension: string) => void;
34
- addContentEntryType: (contentEntryType: ContentEntryType) => void;
35
- }
36
- ) => void | Promise<void>;
37
- };
26
+ type SetupHookParams = HookParameters<'astro:config:setup'> & {
27
+ // `addPageExtension` and `contentEntryType` are not a public APIs
28
+ // Add type defs here
29
+ addPageExtension: (extension: string) => void;
30
+ addContentEntryType: (contentEntryType: ContentEntryType) => void;
38
31
  };
39
32
 
40
- export default function mdx(
41
- partialMdxOptions: Partial<MdxOptions> = {}
42
- ): IntegrationWithPrivateHooks {
33
+ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroIntegration {
43
34
  return {
44
35
  name: '@astrojs/mdx',
45
36
  hooks: {
46
- 'astro:config:setup': async ({
47
- updateConfig,
48
- config,
49
- addPageExtension,
50
- addContentEntryType,
51
- command,
52
- }) => {
37
+ 'astro:config:setup': async (params) => {
38
+ const { updateConfig, config, addPageExtension, addContentEntryType, command } =
39
+ params as SetupHookParams;
40
+
53
41
  addPageExtension('.mdx');
54
42
  addContentEntryType({
55
43
  extensions: ['.mdx'],