summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/hip-hotels-divide.md7
-rw-r--r--packages/astro/src/content/runtime.ts4
-rw-r--r--packages/astro/src/content/types-generator.ts31
3 files changed, 13 insertions, 29 deletions
diff --git a/.changeset/hip-hotels-divide.md b/.changeset/hip-hotels-divide.md
new file mode 100644
index 000000000..296aea5db
--- /dev/null
+++ b/.changeset/hip-hotels-divide.md
@@ -0,0 +1,7 @@
+---
+"astro": minor
+---
+
+Removes content collection warning when a configured collection does not have a matching directory name. This should resolve `i18n` collection warnings for Starlight users.
+
+This also ensures configured collection names are always included in `getCollection()` and `getEntry()` types even when a matching directory is absent. We hope this allows users to discover typos during development by surfacing type information.
diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts
index cccef41d8..c2dd96349 100644
--- a/packages/astro/src/content/runtime.ts
+++ b/packages/astro/src/content/runtime.ts
@@ -62,7 +62,9 @@ export function createGetCollection({
} else {
// eslint-disable-next-line no-console
console.warn(
- `The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
+ `The collection ${JSON.stringify(
+ collection
+ )} does not exist or is empty. Ensure a collection directory with this name exists.`
);
return;
}
diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts
index 62f2fffbd..f8c3b5632 100644
--- a/packages/astro/src/content/types-generator.ts
+++ b/packages/astro/src/content/types-generator.ts
@@ -312,13 +312,6 @@ export async function createContentTypesGenerator({
viteServer,
});
invalidateVirtualMod(viteServer);
- if (observable.status === 'loaded') {
- warnNonexistentCollections({
- logger,
- contentConfig: observable.config,
- collectionEntryMap,
- });
- }
}
}
return { init, queueEvent };
@@ -370,6 +363,9 @@ async function writeContentFiles({
}) {
let contentTypesStr = '';
let dataTypesStr = '';
+ for (const [collection, config] of Object.entries(contentConfig?.collections ?? {})) {
+ collectionEntryMap[JSON.stringify(collection)] ??= { type: config.type, entries: {} };
+ }
for (const collectionKey of Object.keys(collectionEntryMap).sort()) {
const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
const collection = collectionEntryMap[collectionKey];
@@ -455,24 +451,3 @@ async function writeContentFiles({
typeTemplateContent
);
}
-
-function warnNonexistentCollections({
- contentConfig,
- collectionEntryMap,
- logger,
-}: {
- contentConfig: ContentConfig;
- collectionEntryMap: CollectionEntryMap;
- logger: Logger;
-}) {
- for (const configuredCollection in contentConfig.collections) {
- if (!collectionEntryMap[JSON.stringify(configuredCollection)]) {
- logger.warn(
- 'content',
- `The ${bold(configuredCollection)} collection is defined but no ${bold(
- 'content/' + configuredCollection
- )} folder exists in the content directory. Create a new folder for the collection, or check your content configuration file for typos.`
- );
- }
- }
-}