chore(hmr): pretty import circular output

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-10-24 22:12:09 +08:00
parent f60fc6f1d4
commit ec79996009
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 5 additions and 4 deletions

View File

@ -1,3 +1,5 @@
import path from "node:path"
import { red, yellow } from "kolorist"
import type { HmrContext, Plugin } from "vite"
@ -21,10 +23,9 @@ function isNodeWithinCircularImports(
importer,
...[...currentChain].reverse(),
...nodeChain.slice(importerIndex, -1).reverse(),
]
console.warn(
yellow(`Circular imports detected: ${importChain.map((m) => m.file).join(" -> ")}`),
)
].map((m) => path.relative(process.cwd(), m.file))
console.warn(yellow(`Circular imports detected: ${importChain.join("\n↳ ")}`))
return true
}