fix(astro): support content/config.mts (#8484)

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
bb010g 2023-09-11 04:54:56 -07:00 committed by GitHub
parent a6a516d944
commit 78b82bb392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
fix(astro): add support for `src/content/config.mts` files

View file

@ -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) {

View file

@ -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 () => {

View file

@ -0,0 +1,8 @@
{
"name": "@test/content-collections-with-config-mts",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,5 @@
---
title: 10000
---
# Hi there!

View file

@ -0,0 +1,11 @@
import { z, defineCollection } from 'astro:content';
const blog = defineCollection({
schema: z.object({
title: z.string(),
}),
});
export const collections = {
blog
}

View file

@ -0,0 +1,5 @@
---
import {getEntryBySlug} from "astro:content"
const blogEntry = await getEntryBySlug("blog", "introduction");
---
{blogEntry.data.title}

View file

@ -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: