Skip to content
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

fix: replace last 'export default MDXContent;' #2045

Merged
merged 2 commits into from Jul 8, 2023

Conversation

soata
Copy link
Contributor

@soata soata commented Jul 7, 2023

Fix to replace the last 'export default MDXContent;' instead of the first one.

If .mdx file contains a string that exactly matches 'export default MDXContent;', the certain export is not removed and it will result in an error.

@changeset-bot
Copy link

changeset-bot bot commented Jul 7, 2023

🦋 Changeset detected

Latest commit: 8994d24

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
nextra Patch
nextra-theme-blog Patch
nextra-theme-docs Patch

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

@vercel
Copy link

vercel bot commented Jul 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextra-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 8, 2023 2:30pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
nextra ⬜️ Ignored (Inspect) Visit Preview Jul 8, 2023 2:30pm

@vercel
Copy link

vercel bot commented Jul 7, 2023

@soata is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

${finalResult.replace('export default MDXContent;', '')}
${finalResult.replace(/(export default MDXContent;).*$/, '$1')}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, just one suggestion that we need only replace a last appearance and all code that comes after
image
maybe some solution with String#lastIndexOf and String#slice

could You add also a helpful comment in code why we did it and could you add changeset with patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review.

I apologize for pushing the wrong regex code.
What I intended was
${finalResult.replace(/export default MDXContent;(.*)$/, '$1')}

I used regex to minimize the changes, but I'll think about using String#lastIndexOf.

could You add also a helpful comment in code why we did it and could you add changeset with patch?

I'll try it later!

@dimaMachina dimaMachina merged commit 23a25b1 into shuding:main Jul 8, 2023
6 of 8 checks passed
tatukoivisto pushed a commit to tatukoivisto/nextra that referenced this pull request Aug 20, 2023
Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants