@@ -11,6 +11,20 @@ const promises = new Map<string, Promise<UnoGenerator<any>> | undefined>()
1111// bypass icon rules in ESLint
1212process . env . ESLINT ||= 'true'
1313
14+ function getSearchCwd ( id : string ) : string {
15+ // Check if it's a virtual file path from ESLint processors
16+ // Virtual paths have the pattern: /path/to/source.ext/virtual_file.ext
17+ // This happens with markdown, MDX, and other files with embedded code blocks
18+ const virtualMatch = id . match ( / \. \w + \/ [ ^ / ] + $ / )
19+
20+ if ( virtualMatch ) {
21+ const realPath = id . slice ( 0 , id . lastIndexOf ( '/' ) )
22+ return dirname ( realPath )
23+ }
24+
25+ return dirname ( id )
26+ }
27+
1428async function _getGenerator ( configPath ?: string , id ?: string ) {
1529 // Determine the search directory:
1630 // 1. If configPath is provided, use process.cwd() (existing behavior for explicit config)
@@ -19,7 +33,7 @@ async function _getGenerator(configPath?: string, id?: string) {
1933 const searchFrom = configPath
2034 ? process . cwd ( )
2135 : id
22- ? dirname ( id )
36+ ? getSearchCwd ( id )
2337 : process . cwd ( )
2438
2539 const { config, sources } = await loadConfig (
@@ -39,7 +53,7 @@ function getCacheKey(configPath?: string, id?: string): string {
3953 if ( configPath )
4054 return `config:${ configPath } `
4155 if ( id )
42- return `dir:${ dirname ( id ) } `
56+ return `dir:${ getSearchCwd ( id ) } `
4357 return `cwd:${ process . cwd ( ) } `
4458}
4559
0 commit comments