fix(mdx-loader): skip asset transformation for directory links with dots#12037
fix(mdx-loader): skip asset transformation for directory links with dots#12037Dharya-dev wants to merge 2 commits into
Conversation
When a Markdown link targets a local directory that has a dot in its name (e.g., `[link](../directory-with.dot/)`), path.extname() returns a truthy value (`.dot`), causing the transformLinks plugin to incorrectly treat it as a file asset. This results in a failed require() call and a broken build. This fix adds a directory check via fs.stat() after resolving the local path. If the path is a directory, the asset transformation is skipped and the link is left as-is. Closes facebook#11940
|
Hi @Dharya-dev! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Closing in favor of @thanasis2028's PR #11944. Since they did the work first and I am closing the duplicate PR and offer support on the original one. Good luck getting it merged! |
Summary
Fixes a build error when a Markdown link points to a local directory that has a dot in its name (e.g.,
[link](../directory-with.dot/)).Resolves #11940
Problem
path.extname("directory-with.dot/")returns".dot", which is truthy. ThetransformLinksremark plugin interprets this as a file with an asset-like extension and callstoAssetRequireNode(). Since the target is actually a directory (not a file), Webpack'srequire()fails with:Fix
After
getLocalFileAbsolutePathresolves the target path, I added a check usingfs.stat()to see if the path is a directory. If it is, the asset transformation is skipped entirely and the link is left unchanged — which is the correct behavior for directory links.Changes
packages/docusaurus-mdx-loader/src/remark/transformLinks/index.ts— Addedfs.stat()directory check beforetoAssetRequireNode()packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/index.test.ts— Added two test cases covering directory links with dots (with and without trailing slash)__fixtures__/directory-with.dot/index.md— Test fixture directoryTest Results
Let me know if any changes are needed!