diff --git a/src/codegen/index.ts b/src/codegen/index.ts index 41bfd38..b92f1a1 100644 --- a/src/codegen/index.ts +++ b/src/codegen/index.ts @@ -6,7 +6,7 @@ import type { CodegenContext } from "./context"; import { generateModuleJSCode, generateTopJSCode } from "./js"; import { getFilteredModuleImportsRecursive, - waitForModuleIdsToBeStable, + waitAndResolveAllModuleIds, } from "./utils"; export * from "./context"; @@ -121,16 +121,9 @@ export async function generateCode( switch (layer.mode) { case "global": { - await waitForModuleIdsToBeStable( - codegenContext, - (resolvedId: string): boolean => - shouldIncludeImport(resolvedId, null) - ); + const allModuleIds = await waitAndResolveAllModuleIds(codegenContext); const allContents: ContentSpec[] = []; - const allModuleIds = getAllModuleIds().filter((resolvedId) => - shouldIncludeImport(resolvedId, null) - ); for (const id of allModuleIds) { allContents.push({ raw: await getTailwindCSSContent(id), diff --git a/src/codegen/utils.ts b/src/codegen/utils.ts index b807724..692f218 100644 --- a/src/codegen/utils.ts +++ b/src/codegen/utils.ts @@ -61,14 +61,15 @@ export async function hasCircularDependencies( return false; } -export async function waitForModuleIdsToBeStable( - { getAllModuleIds, resolveModuleImports }: CodegenContext, - shouldInclude: (resolvedId: string) => boolean -): Promise { +export async function waitAndResolveAllModuleIds({ + getAllModuleIds, + resolveModuleImports, + shouldIncludeImport, +}: CodegenContext): Promise { for (;;) { const moduleIds = getAllModuleIds(); for (const resolvedId of moduleIds) { - if (!shouldInclude(resolvedId)) { + if (!shouldIncludeImport(resolvedId, null)) { continue; } @@ -77,7 +78,9 @@ export async function waitForModuleIdsToBeStable( const afterCount = getAllModuleIds().length; if (moduleIds.length === afterCount) { - break; + return moduleIds.filter((resolvedId) => + shouldIncludeImport(resolvedId, null) + ); } } }