diff --git a/.changeset/calm-houses-carry.md b/.changeset/calm-houses-carry.md new file mode 100644 index 000000000..4e614e623 --- /dev/null +++ b/.changeset/calm-houses-carry.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +fix(astro): add support for `src/content/config.mts` files diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts index 202acd6b9..5834c81d8 100644 --- a/packages/astro/src/content/utils.ts +++ b/packages/astro/src/content/utils.ts @@ -448,7 +448,7 @@ export function getContentPaths( }; } function search(fs: typeof fsMod, srcDir: URL) { - const paths = ['config.mjs', 'config.js', 'config.ts'].map( + const paths = ['config.mjs', 'config.js', 'config.mts', 'config.ts'].map( (p) => new URL(`./content/${p}`, srcDir) ); for (const file of paths) { diff --git a/packages/astro/test/content-collections.test.js b/packages/astro/test/content-collections.test.js index 10c65b0dd..e39d7da5e 100644 --- a/packages/astro/test/content-collections.test.js +++ b/packages/astro/test/content-collections.test.js @@ -214,6 +214,20 @@ describe('Content Collections', () => { expect(error).to.include('**title**: Expected type `"string"`, received "number"'); }); }); + describe('With config.mts', () => { + it("Errors when frontmatter doesn't match schema", async () => { + const fixture = await loadFixture({ + root: './fixtures/content-collections-with-config-mts/', + }); + let error; + try { + await fixture.build(); + } catch (e) { + error = e.message; + } + expect(error).to.include('**title**: Expected type `"string"`, received "number"'); + }); + }); describe('With empty markdown file', () => { it('Throws the right error', async () => { diff --git a/packages/astro/test/fixtures/content-collections-with-config-mts/package.json b/packages/astro/test/fixtures/content-collections-with-config-mts/package.json new file mode 100644 index 000000000..cba237161 --- /dev/null +++ b/packages/astro/test/fixtures/content-collections-with-config-mts/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/content-collections-with-config-mts", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/content-collections-with-config-mts/src/content/blog/introduction.md b/packages/astro/test/fixtures/content-collections-with-config-mts/src/content/blog/introduction.md new file mode 100644 index 000000000..c85be69f6 --- /dev/null +++ b/packages/astro/test/fixtures/content-collections-with-config-mts/src/content/blog/introduction.md @@ -0,0 +1,5 @@ +--- +title: 10000 +--- + +# Hi there! \ No newline at end of file diff --git a/packages/astro/test/fixtures/content-collections-with-config-mts/src/content/config.mts b/packages/astro/test/fixtures/content-collections-with-config-mts/src/content/config.mts new file mode 100644 index 000000000..bb2c54aea --- /dev/null +++ b/packages/astro/test/fixtures/content-collections-with-config-mts/src/content/config.mts @@ -0,0 +1,11 @@ +import { z, defineCollection } from 'astro:content'; + +const blog = defineCollection({ + schema: z.object({ + title: z.string(), + }), +}); + +export const collections = { + blog +} diff --git a/packages/astro/test/fixtures/content-collections-with-config-mts/src/pages/index.astro b/packages/astro/test/fixtures/content-collections-with-config-mts/src/pages/index.astro new file mode 100644 index 000000000..4152c0734 --- /dev/null +++ b/packages/astro/test/fixtures/content-collections-with-config-mts/src/pages/index.astro @@ -0,0 +1,5 @@ +--- +import {getEntryBySlug} from "astro:content" +const blogEntry = await getEntryBySlug("blog", "introduction"); +--- +{blogEntry.data.title} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ab3a4d0a..fd844e217 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2373,6 +2373,12 @@ importers: specifier: workspace:* version: link:../../.. + packages/astro/test/fixtures/content-collections-with-config-mts: + dependencies: + astro: + specifier: workspace:* + version: link:../../.. + packages/astro/test/fixtures/content-mixed-errors: dependencies: astro: