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: add support for js/mjs file extensions for Content Collections config file #6229

Merged
merged 14 commits into from
Feb 13, 2023

Conversation

MoustaphaDev
Copy link
Member

@MoustaphaDev MoustaphaDev commented Feb 13, 2023

Changes

Closes #6179

Testing

Check that an error is thrown when the frontmatter doesn't match the schema of the collection defined in the config.mjs file.

I could add a test case for a config.js but it seems redundant as the config file has to be a module anyway.

Docs

Bug fix, we already document this

@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2023

🦋 Changeset detected

Latest commit: 08d0902

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

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 13, 2023
@MoustaphaDev MoustaphaDev changed the title fix: support js/mjs file extension for Content Collections config file fix: add support for js/mjs file extensions for Content Collections config file Feb 13, 2023
@@ -0,0 +1,5 @@
---
'astro': patch
Copy link
Member Author

@MoustaphaDev MoustaphaDev Feb 13, 2023

Choose a reason for hiding this comment

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

Patch because this is already documented

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

This code looks great! However, there's a caveat to using mjs configs: intellisense will not work unless "allowJs: true is present in your tsconfig.json, or if you switch to a jsconfig.json.

I'm curious if we can check for allowJs in your tsconfig, and log a warning if it isn't present. This would guide users in the right direction to avoid future support tickets. A callout in our docs would be great too!

@MoustaphaDev
Copy link
Member Author

MoustaphaDev commented Feb 13, 2023

Ah thanks for the heads-up! I just found this commit on discord withastro/docs@bb99ae0 where allowJs was removed from the tsconfig.json because it would break the astro:content virtual module. Did you find a way to get around the side effects of allowJs?

@bholmesdev
Copy link
Contributor

@MoustaphaDev Ah good catch. I've been unable to replicate that issue outside of docs but it's probably worth more testing. I verified astro:content works as expected using allowJs in the blog starter on my end. Mind trying on your end as a sanity check?

@MoustaphaDev
Copy link
Member Author

MoustaphaDev commented Feb 13, 2023

I don't see anything breaking @bholmesdev! Working on implementing the warnings
I'll open a PR in docs too

@MoustaphaDev MoustaphaDev marked this pull request as draft February 13, 2023 19:03
@MoustaphaDev MoustaphaDev marked this pull request as ready for review February 13, 2023 20:53
Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

Super small nit but looks amazing! Feeling configdent 👏

packages/astro/src/content/server-listeners.ts Outdated Show resolved Hide resolved
Co-authored-by: Ben Holmes <hey@bholmes.dev>
@tschaub
Copy link

tschaub commented Feb 13, 2023

Thanks for the work on this, @MoustaphaDev!

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.

Unsupported config.js file type for content collection schema
3 participants