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

feat(vite-plugin-markdown): support importing markdown files from outside root project #4780

Merged
merged 13 commits into from
Sep 22, 2022
Merged

Conversation

MoustaphaDev
Copy link
Member

@MoustaphaDev MoustaphaDev commented Sep 16, 2022

Changes

This change adds support for importing markdown files from outside the root directory of a project, which is very common in monorepo setups

Testing

TODO - I'll need some assistance for this one

Docs

TODO - Not sure if it needs documentation but will do if guided
/cc @withastro/maintainers-docs for feedback!

MoustaphaDev and others added 2 commits September 15, 2022 19:57
This change adds support for importing markdown located outside the root of directory of a project
@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2022

⚠️ No Changeset found

Latest commit: 33dd86c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 16, 2022
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

I'm not positive about this change, but if this is all it takes to unblock this, that would be very exciting.

Suggestion: you can use new URL('../jsx-runtime/index.js', import.meta.url) instead of manually manipulating the import.meta.url string, then convert it to a Node path using fileURLToPath, then convert it back to a proper import path with Vite's normalizePath utility. It's roundabout, but a more robust approach than what you're doing here.

@MoustaphaDev
Copy link
Member Author

I'm not positive about this change, but if this is all it takes to unblock this, that would be very exciting.

Suggestion: you can use new URL('../jsx-runtime/index.js', import.meta.url) instead of manually manipulating the import.meta.url string, then convert it to a Node path using fileURLToPath, then convert it back to a proper import path with Vite's normalizePath utility. It's roundabout, but a more robust approach than what you're doing here.

Thanks for the suggestion I refactored it. I hope this PR is not a works my machine thing

@matthewp
Copy link
Contributor

This does seem difficult to test and I'm wary of taking on support for something that's fairly uncommon. It's pretty normal to need to have your files in the same folder as your project root on any framework.

@MoustaphaDev
Copy link
Member Author

MoustaphaDev commented Sep 16, 2022

Fair enough this is quite uncommon (supporting imports for markdown imports in monorepo setups was the motivation behind this PR) and I don't know yet how I'd go about testing this.

@natemoo-re
Copy link
Member

From my perspective this is actually a really common pattern! Imagine a top-level docs folder for a project where the site logic itself is in some nested directory—docs contributors can just edit pure Markdown files without worry about the site structure.

If this is all it takes to unblock that, I'd be super happy.

Pattern I've seen repeated a lot in the repo
@MoustaphaDev
Copy link
Member Author

MoustaphaDev commented Sep 16, 2022

Interesting, I didn't think of that real world use case (just wanted to add that feature because why not 😅). Anyway, looking forward to getting suggestions before I'm able to submit the PR

@matthewp
Copy link
Contributor

I'll remove my objection given @natemoo-re's reasoning. So once @natemoo-re is satisfied with the code I think it's ready to go.

@MoustaphaDev can you mark this PR as being ready for review.

@MoustaphaDev MoustaphaDev marked this pull request as ready for review September 21, 2022 14:27
@MoustaphaDev
Copy link
Member Author

Done !

@matthewp matthewp merged commit 08dae16 into withastro:main Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants