Fix Content Collections not loading config file when there are spaces in the folder tree (#5962)
* fix * add test * use `fileURLToPath` instead * chore: changeset * remove useless config file * revert back to using `decodeURIComponent` * test: better test * re-revert back to using `fileURLToPath`
This commit is contained in:
parent
e7f9696cea
commit
46b6e14265
7 changed files with 95 additions and 1 deletions
5
.changeset/silly-bees-impress.md
Normal file
5
.changeset/silly-bees-impress.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix Content Collections not loading config file when there are spaces in the folder tree
|
|
@ -227,7 +227,8 @@ export async function loadContentConfig({
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
unparsedConfig = await tempConfigServer.ssrLoadModule(contentPaths.config.pathname);
|
const configPathname = fileURLToPath(contentPaths.config);
|
||||||
|
unparsedConfig = await tempConfigServer.ssrLoadModule(configPathname);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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', () => {
|
describe('SSR integration', () => {
|
||||||
let app;
|
let app;
|
||||||
|
|
||||||
|
|
9
packages/astro/test/fixtures/content with spaces in folder name/package.json
vendored
Normal file
9
packages/astro/test/fixtures/content with spaces in folder name/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/content-with-spaces-in-folder-name",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*",
|
||||||
|
"@astrojs/mdx": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
34
packages/astro/test/fixtures/content with spaces in folder name/src/content/config.ts
vendored
Normal file
34
packages/astro/test/fixtures/content with spaces in folder name/src/content/config.ts
vendored
Normal file
|
@ -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,
|
||||||
|
}
|
24
packages/astro/test/fixtures/content with spaces in folder name/src/pages/index.astro
vendored
Normal file
24
packages/astro/test/fixtures/content with spaces in folder name/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<title>It's content time!</title>
|
||||||
|
<style>
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
font-family: system-ui;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1647,6 +1647,14 @@ importers:
|
||||||
'@astrojs/mdx': link:../../../../integrations/mdx
|
'@astrojs/mdx': link:../../../../integrations/mdx
|
||||||
astro: link:../../..
|
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:
|
packages/astro/test/fixtures/content-collections:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/mdx': workspace:*
|
'@astrojs/mdx': workspace:*
|
||||||
|
|
Loading…
Reference in a new issue