Skip to content

Commit f8e9458

Browse files
feat: move MDX into the processors themselves (#17262)
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
1 parent 7c04f2e commit f8e9458

49 files changed

Lines changed: 954 additions & 582 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes `@astrojs/markdown-remark` being pinned to an exact version.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/internal-helpers': minor
3+
---
4+
5+
Adds an `@astrojs/internal-helpers/mdx` entrypoint with the shared helpers the Markdown processor packages use to render `.mdx` files.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astrojs/markdown-remark': minor
3+
'@astrojs/markdown-satteri': minor
4+
---
5+
6+
Adds MDX rendering to the `unified()` and `satteri()` processors.
7+
8+
Both processors now compile `.mdx` files themselves. You still need to install `@astrojs/mdx` to add MDX support to your project.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/mdx': patch
3+
---
4+
5+
Fixes `.mdx` files still using `markdown.processor` when `extendMarkdownConfig` is `false`. They now use a clean default processor instead; pass `mdx({ processor })` to choose one explicitly.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/mdx': patch
3+
---
4+
5+
Adds a warning when the deprecated `remarkPlugins`, `rehypePlugins`, `recmaPlugins` and `remarkRehype` options are ignored because your Markdown processor does not run them. They still apply when your processor is `unified()`, and were previously dropped silently otherwise.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@astrojs/mdx': major
3+
---
4+
5+
Moves MDX file processing to the Markdown processors.
6+
7+
'@astrojs/mdx' is still required to add MDX support to your project. However, it now delegates the MDX files processing to Markdown processors.
8+
9+
#### What should I do?
10+
11+
If you haven't explicitly installed a Markdown processor, you don't need to do anything.
12+
13+
Otherwise, ensure that your configured Markdown processor uses the following version:
14+
- `@astrojs/markdown-satteri` 0.4.0 or later if you use `satteri()`
15+
- `@astrojs/markdown-remark` 7.3.0 or later if you use `unified()`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/markdown-remark': minor
3+
---
4+
5+
Adds a `recmaPlugins` option to `unified()` for adding recma (estree/JSX) plugins to the MDX compiler.

knip.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ export default {
126126
'packages/integrations/mdx': {
127127
entry: [srcEntry, dtsEntry, testEntry],
128128
project,
129-
// Optional peer dep: type-only imports for narrowing the `satteri()` processor.
130-
// Knip flags it because the peer is referenced from source; the runtime stays gated by name-check.
131-
ignoreDependencies: ['@astrojs/markdown-satteri'],
129+
// Optional peer dep: dynamically imported for the deprecated remark/rehype options.
130+
ignoreDependencies: ['@astrojs/markdown-remark'],
132131
},
133132
'packages/markdown/remark': {
134133
entry: [srcEntry, dtsEntry, testEntry],
@@ -137,6 +136,8 @@ export default {
137136
'packages/markdown/satteri': {
138137
entry: [srcEntry, dtsEntry, testEntry],
139138
project,
139+
// Only referenced by a `declare module 'hast'` augmentation, which knip doesn't count.
140+
ignoreDependencies: ['@types/hast'],
140141
},
141142
'packages/upgrade': {
142143
entry: ['src/index.ts!', testEntry],

packages/astro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
"sharp": "^0.35.4"
183183
},
184184
"peerDependencies": {
185-
"@astrojs/markdown-remark": "workspace:*"
185+
"@astrojs/markdown-remark": "^7.3.0"
186186
},
187187
"peerDependenciesMeta": {
188188
"@astrojs/markdown-remark": {

packages/astro/src/core/util.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from 'node:fs';
21
import { fileURLToPath } from 'node:url';
32
import type { AstroSettings } from '../types/astro.js';
43
import type { AstroConfig } from '../types/public/config.js';
@@ -132,51 +131,6 @@ export function isEndpoint(file: URL, settings: AstroSettings): boolean {
132131
return !endsWithPageExt(file, settings) && !file.toString().includes('?astro');
133132
}
134133

135-
export function resolveJsToTs(filePath: string) {
136-
if (filePath.endsWith('.jsx') && !fs.existsSync(filePath)) {
137-
const tryPath = filePath.slice(0, -4) + '.tsx';
138-
if (fs.existsSync(tryPath)) {
139-
return tryPath;
140-
}
141-
}
142-
return filePath;
143-
}
144-
145-
// Match Vite's default `resolve.extensions` order so that when multiple
146-
// candidate files exist, we pick the same module Vite will load.
147-
// https://vite.dev/config/shared-options.html#resolve-extensions
148-
const VITE_DEFAULT_RESOLVE_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
149-
150-
/**
151-
* Resolve a path that doesn't name a file on disk (e.g. produced by an
152-
* extensionless import like `import { Counter } from './Counter'`) to the file
153-
* Vite would load, by probing Vite's default extension order and directory
154-
* `index` files. Returns the path unchanged when it already exists as a file
155-
* or when no candidate is found.
156-
*/
157-
export function resolveExtensionlessPath(filePath: string): string {
158-
const stat = fs.statSync(filePath, { throwIfNoEntry: false });
159-
if (stat?.isFile()) {
160-
return filePath;
161-
}
162-
for (const ext of VITE_DEFAULT_RESOLVE_EXTENSIONS) {
163-
const tryPath = filePath + ext;
164-
if (fs.existsSync(tryPath)) {
165-
return tryPath;
166-
}
167-
}
168-
// Directory import: resolve to its `index` module, like Vite does.
169-
if (stat?.isDirectory()) {
170-
for (const ext of VITE_DEFAULT_RESOLVE_EXTENSIONS) {
171-
const tryPath = `${filePath}/index${ext}`;
172-
if (fs.existsSync(tryPath)) {
173-
return tryPath;
174-
}
175-
}
176-
}
177-
return filePath;
178-
}
179-
180134
/**
181135
* Set a default NODE_ENV so Vite doesn't set an incorrect default when loading the Astro config
182136
*/

0 commit comments

Comments
 (0)