-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat(mdx): move mdx into sub-package #7752
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Note Your Pull Request seems to be updating Translations of the Node.js Website. Whilst we appreciate your intent; Any Translation update should be done through our Crowdin Project. Thank you! |
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.
Pull Request Overview
This PR refactors the MDX functionality by extracting it into its own package and making several updates to imports, type annotations, and usage of external libraries. Key changes include:
- Migration of MDX-related functionality from the site to a dedicated package (@node-core/mdx).
- Updates to module imports and type annotations across MDX files.
- Removal of legacy files and tests no longer required.
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/mdx/lib/shiki.ts | Updated type annotations and import paths for Shiki highlighter. |
packages/mdx/lib/plugins.ts | Added type annotations to plugin exports. |
packages/mdx/lib/index.tsx | Refactored MDX compilation with strengthened type definitions. |
packages/mdx/lib/highlight.ts | Updated import path for Shiki configuration. |
packages/mdx/lib/evaluate.ts | Introduced a new evaluator using Sval. |
packages/mdx/eslint.config.js | Updated ESLint configuration with new TypeScript rules. |
apps/site/util/gitHubUtils.ts | Removed unused slugger creation, now provided elsewhere. |
apps/site/pages/id/about/security-reporting.mdx | Fixed broken link URL formatting. |
apps/site/package.json | Updated dependencies to reflect usage of the new MDX package. |
apps/site/next.dynamic.mjs | Updated MDX compiler imports to use the new package. |
apps/site/next.config.mjs | Added new package dependency for @radix-ui/react-avatar. |
apps/site/components/withAvatarGroup.ts | Removed unused Image import in favor of streamlined props. |
apps/site/components/MDX/Image/index.tsx | Removed unnecessary image unoptimized property. |
apps/site/components/MDX/CodeBox/index.tsx | Updated import for language display utilities. |
apps/site/components/Downloads/Release/ReleaseCodeBox.tsx | Updated evaluator and highlighter imports to the new MDX package. |
Comments suppressed due to low confidence (1)
packages/mdx/lib/index.tsx:88
- The variable 'slugger' is used without being defined. To resolve this, instantiate it using the imported 'createGitHubSlugger' function (e.g., const slugger = createGitHubSlugger()) before using it.
heading.data = { ...heading.data, id: slugger(heading.value) };
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Follow-ups (for separate PRs):
|
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.
could you try to add some unit test
@AugustinMauroy can you please check if the added tests are to your satisfaction? Thank you |
I don't think we need MDX functionality on api-docs-tooling itself; Only Shiki, but that is unified and can run directly with rehype/remark. But I'm fine in general moving all the custom stuff we've made for our needs into its own package... |
@@ -1,5 +1,7 @@ | |||
'use client'; | |||
|
|||
import createSval from '@node-core/mdx/evaluator'; |
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.
Not sure calling it /mdx makes sense.... I think making it clearer it is web stuff related makes sense? No idea for a name btw
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.
Can you let us know if you changed this code or was it just a 1:1 move? Why did git not understand it as a move?
@@ -0,0 +1,54 @@ | |||
import { |
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.
Separate type import from regular imports...
}); | ||
|
||
const match = html.match(/<code[^>]*>([\s\S]*?)<\/code>/); | ||
return match?.[1] || html; |
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 recall this code being like this before? Or was 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.
Typescript didn’t like that we were returning a string when it could be undefined, so I changed the structure accordingly. I can revert if you insist.
@@ -0,0 +1,26 @@ | |||
'use strict'; |
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.
No need of use strict on TypeScript files...
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'm not sure why you changed some files from .mjs to .ts... Again, we want to simplify these packages to be easily to be imported by other packages without the need of building them or bundling them. Adding TypeScript diminishes that ability for virtually no real reason. These are libraries; Type verification will ultimately be done on the App-side; And if we're really curious if theu're OK, we can add a CI step for tsc
to emit warnings on JSdocs.
Yes, I misunderstood earlier, we only need Shiki to be imported to api-docs-tooling. As for a name, I just took the prefix the files had ( I suppose "markdown-utilities" could also work? |
Also, on that note, I’m going to convert these back to JS, like you said, and so that we don’t need a typescript loader to use Shiki in api-docs-tooling. Drafting until then. Sorry for the confusion with the files (if any). |
|
||
import baseConfig from '../../eslint.config.js'; | ||
|
||
export 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.
export default [ | |
/* | |
* @see https://eslint.org/docs/latest/use/configure/ | |
*/ | |
export default [ |
That's nice ! |
I think I'll make this |
Description
The
apps/site
directory is currently quite complex. Since we're using a monorepo, why not take advantage of that structure whenever we can? The MDX functionality can be extracted into its own package, which might also be useful forapi-docs-tooling
down the line.Validation
Everything should build and run without regressions
Check List
pnpm format
to ensure the code follows the style guide.pnpm test
to check if all tests are passing.pnpm build
to check if the website builds without errors.