-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: markdown config typechecking #2970
Conversation
🦋 Changeset detectedLatest commit: b01d281 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/astro/src/core/config.ts
Outdated
@@ -12,6 +13,9 @@ import loadTypeScript from '@proload/plugin-tsm'; | |||
import postcssrc from 'postcss-load-config'; | |||
import { arraify, isObject } from './util.js'; | |||
import { appendForwardSlash, trimSlashes } from './path.js'; | |||
// These two imports make astroMarkdownOptions work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wahhh??? Would love an explanation why here, for future readers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out the new commit, I added a longer (not sure if better) explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove any public references to the mode
option for now, since it doesn't do anything.
Other than that, looks great!
/** | ||
* @docs | ||
* @name markdown.mode | ||
* @type {'md' | 'mdx'} | ||
* @default `mdx` | ||
* @description | ||
* Control wheater to allow components inside markdown files ('mdx') or not ('md'). | ||
*/ | ||
mode?: 'md' | 'mdx'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this actually does anything right now, which is why we didn't include it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does add rehypeJsx
and rehypeExpressions
. I could remove the MDX mode altogether if these plugins do nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no you're right! I also saw that #2971 added escaping for expressions when mode === 'md'
. So I think this is fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After doing some testing, the only difference I've found is that components are being rendered with mdx
but completely ignored with md
. Expressions works in both modes, tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking as red just to make sure we hold off on this until post release day. I have some comments that I'd like to make but just won't have the time until Monday/Tuesday to make them. Appreciate the patience!
packages/astro/src/core/config.ts
Outdated
.passthrough() | ||
.optional() | ||
.default({}), | ||
markdown: astroMarkdownOptions.default({}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for your patience on this review @JuanM04!
My main comment is that we really benefit from having all of our config parsing logic here in one file and in one single parser object instantiation.
Reading this PR, I can see the value you've put into validation reuse, which is great. But, I'm also bouncing around to follow where the different parsers / validation logic lives, defined across multiple files, and even multiple packages, with multiple zod parser instances referencing each other.
If you'd like to improve the existing markdown: z.object(...
validation logic defined here, I'm all for it. I could even see the value in a new Plugin
validator that both remarkPlugins
and rehypePlugins
, which breaks up the single-object-validator that I love but for a valid, valuable reason.
But at the end of the day, Astro owns the "Astro Config" type and therefore its validation, so I'd like to keep it as simple as possible and only inside the Astro package, for our sake as maintainers.
@JuanM04 lmk what you think, and how you'd like to move forward!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're totally right. The idea behind the division was about separation of concerns, since @astrojs/markdown-remark
is its own package, but I see how that can be a problem.
I'll integrate this configuration in a single place
@FredKSchott I've moved the validation inside |
Note: the error thrown by Deno it's not caused by this PR directly. If you have an Astro page with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This is looking great, thanks for making those changes. LGTM!
Can't merge with failing tests! What's the best way to resolve? |
I'm looking into it. Either a fix is found or the test is ignored |
As long as you can confirm that this isn't a regression caused by this PR |
Ok, this way it should work. The markdown plugin now is dynamically imported only when using Sidenote: I've just found out that this error was encountered in another PR: #3036 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* Added schemas to markdown plugin * Added new schemas to main package * Changesets * typeraw * Explaination about the weird type hack * Added markdown.mode to config * Added comment * Formatted * Moved validation to `astro` and added RemarkPlugin ad RehypePlugin * Removed the ability to have a custom markdown renderer internally * Fixed plugin type * Removed unused renderMarkdownWithFrontmatter * Added missing dependency * Dynamically import astro markdown * Cache import
Changes
Following the comment
// TODO: add better type checking
, I've added type checking for the markdown configurationTesting
Docs