Skip to content

Commit

Permalink
Improve content collection error message for empty folders (#7118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed May 19, 2023
1 parent 2b9a25b commit 3257dd2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-geese-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix unnecessary warning showing on start when a collection folder was empty. The warning was also enhanced to add more information about possible causes.
26 changes: 16 additions & 10 deletions packages/astro/src/content/types-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,21 @@ export async function createContentTypesGenerator({
readdir: fs.readdir.bind(fs),
readdirSync: fs.readdirSync.bind(fs),
},
onlyFiles: false,
objectMode: true,
});
const entries = globResult
.map((e) => new URL(e, contentPaths.contentDir))
.filter(
// Config loading handled first. Avoid running twice.
(e) => !e.href.startsWith(contentPaths.config.url.href)
);
for (const entry of entries) {
events.push({ type: { name: 'add', entry }, opts: { logLevel: 'warn' } });

for (const entry of globResult) {
const entryURL = new URL(entry.path, contentPaths.contentDir);
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
if (entry.dirent.isFile()) {
events.push({
type: { name: 'add', entry: entryURL },
opts: { logLevel: 'warn' },
});
} else if (entry.dirent.isDirectory()) {
events.push({ type: { name: 'addDir', entry: entryURL }, opts: { logLevel: 'warn' } });
}
}
await runEvents();
return { typesGenerated: true };
Expand Down Expand Up @@ -503,9 +509,9 @@ function warnNonexistentCollections({
warn(
logging,
'content',
`${JSON.stringify(
`The ${JSON.stringify(
configuredCollection
)} is not a collection. Check your content config for typos.`
)} collection does not have an associated folder in your \`content\` directory. Make sure the folder exists, or check your content config for typos.`
);
}
}
Expand Down

0 comments on commit 3257dd2

Please sign in to comment.