feat: add global hashset for seen metadata

This commit is contained in:
bholmesdev 2022-05-19 17:37:21 -04:00
parent 2d0dc4d8ac
commit 2bb2b5e8ad

View file

@ -48,15 +48,19 @@ export const isCSSRequest = (request: string): boolean => cssRe.test(request);
// Ex. markdown files imported asynchronously or via Astro.glob(...) // Ex. markdown files imported asynchronously or via Astro.glob(...)
// This calls each md file's $$loadMetadata to discover those dependencies // This calls each md file's $$loadMetadata to discover those dependencies
// and writes all results to the input `metadata` object // and writes all results to the input `metadata` object
const seenMdMetadata = new Set<string>();
export async function collectMdMetadata( export async function collectMdMetadata(
metadata: Metadata, metadata: Metadata,
modGraph: ModuleNode, modGraph: ModuleNode,
viteServer: ViteDevServer viteServer: ViteDevServer,
) { ) {
const importedModules = [...(modGraph?.importedModules ?? [])]; const importedModules = [...(modGraph?.importedModules ?? [])];
await Promise.all( await Promise.all(
importedModules.map(async (importedModule) => { importedModules.map(async (importedModule) => {
// recursively check for importedModules // recursively check for importedModules
if (!importedModule.id || seenMdMetadata.has(importedModule.id)) return;
seenMdMetadata.add(importedModule.id);
await collectMdMetadata(metadata, importedModule, viteServer); await collectMdMetadata(metadata, importedModule, viteServer);
if (!importedModule?.id?.endsWith(MARKDOWN_IMPORT_FLAG)) return; if (!importedModule?.id?.endsWith(MARKDOWN_IMPORT_FLAG)) return;