diff options
author | 2023-05-19 13:53:46 +0200 | |
---|---|---|
committer | 2023-05-19 13:53:46 +0200 | |
commit | 3257dd28901c785a6a661211b98c5ef2cb3b9aa4 (patch) | |
tree | b14f8dd25f4ff64da0e3d7f99212d1a7e30b5d3c | |
parent | 2b9a25beaf41cd3cceb763e736db8a70f7417de8 (diff) | |
download | astro-3257dd28901c785a6a661211b98c5ef2cb3b9aa4.tar.gz astro-3257dd28901c785a6a661211b98c5ef2cb3b9aa4.tar.zst astro-3257dd28901c785a6a661211b98c5ef2cb3b9aa4.zip |
Improve content collection error message for empty folders (#7118)
-rw-r--r-- | .changeset/tasty-geese-fix.md | 5 | ||||
-rw-r--r-- | packages/astro/src/content/types-generator.ts | 26 |
2 files changed, 21 insertions, 10 deletions
diff --git a/.changeset/tasty-geese-fix.md b/.changeset/tasty-geese-fix.md new file mode 100644 index 000000000..5c02621a6 --- /dev/null +++ b/.changeset/tasty-geese-fix.md @@ -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. diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index aa8c7369d..ee4c99077 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -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 }; @@ -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.` ); } } |