diff --git a/.changeset/silly-bees-impress.md b/.changeset/silly-bees-impress.md new file mode 100644 index 000000000..a25317524 --- /dev/null +++ b/.changeset/silly-bees-impress.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix Content Collections not loading config file when there are spaces in the folder tree diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts index 9623054a8..5a3279f93 100644 --- a/packages/astro/src/content/utils.ts +++ b/packages/astro/src/content/utils.ts @@ -227,7 +227,8 @@ export async function loadContentConfig({ return undefined; } try { - unparsedConfig = await tempConfigServer.ssrLoadModule(contentPaths.config.pathname); + const configPathname = fileURLToPath(contentPaths.config); + unparsedConfig = await tempConfigServer.ssrLoadModule(configPathname); } catch (e) { throw e; } finally { diff --git a/packages/astro/test/content-collections.test.js b/packages/astro/test/content-collections.test.js index 2561bdbab..c8105184e 100644 --- a/packages/astro/test/content-collections.test.js +++ b/packages/astro/test/content-collections.test.js @@ -187,6 +187,19 @@ describe('Content Collections', () => { }); }); + describe('With spaces in path', () => { + it('Does not throw', async () => { + const fixture = await loadFixture({ root: './fixtures/content with spaces in folder name/' }); + let error = null; + try { + await fixture.build(); + } catch (e) { + error = e.message; + } + expect(error).to.be.null; + }); + }); + describe('SSR integration', () => { let app; diff --git a/packages/astro/test/fixtures/content with spaces in folder name/package.json b/packages/astro/test/fixtures/content with spaces in folder name/package.json new file mode 100644 index 000000000..eed4ebb90 --- /dev/null +++ b/packages/astro/test/fixtures/content with spaces in folder name/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/content-with-spaces-in-folder-name", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/mdx": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/content with spaces in folder name/src/content/config.ts b/packages/astro/test/fixtures/content with spaces in folder name/src/content/config.ts new file mode 100644 index 000000000..fbd4e381d --- /dev/null +++ b/packages/astro/test/fixtures/content with spaces in folder name/src/content/config.ts @@ -0,0 +1,34 @@ +import { z, defineCollection } from 'astro:content'; + +const withCustomSlugs = defineCollection({ + schema: z.object({}), +}); + +const withSchemaConfig = defineCollection({ + schema: z.object({ + title: z.string(), + isDraft: z.boolean().default(false), + lang: z.enum(['en', 'fr', 'es']).default('en'), + publishedAt: z.date().transform((val) => new Date(val)), + }) +}); + +const withUnionSchema = defineCollection({ + schema: z.discriminatedUnion('type', [ + z.object({ + type: z.literal('post'), + title: z.string(), + description: z.string(), + }), + z.object({ + type: z.literal('newsletter'), + subject: z.string(), + }), + ]), +}); + +export const collections = { + 'with-custom-slugs': withCustomSlugs, + 'with-schema-config': withSchemaConfig, + 'with-union-schema': withUnionSchema, +} diff --git a/packages/astro/test/fixtures/content with spaces in folder name/src/pages/index.astro b/packages/astro/test/fixtures/content with spaces in folder name/src/pages/index.astro new file mode 100644 index 000000000..468b70e7b --- /dev/null +++ b/packages/astro/test/fixtures/content with spaces in folder name/src/pages/index.astro @@ -0,0 +1,24 @@ +--- + +--- + + + + + It's content time! + + + +
+
+ + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ffca8b90f..7059f476c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1647,6 +1647,14 @@ importers: '@astrojs/mdx': link:../../../../integrations/mdx astro: link:../../.. + packages/astro/test/fixtures/content with spaces in folder name: + specifiers: + '@astrojs/mdx': workspace:* + astro: workspace:* + dependencies: + '@astrojs/mdx': link:../../../../integrations/mdx + astro: link:../../.. + packages/astro/test/fixtures/content-collections: specifiers: '@astrojs/mdx': workspace:*