@@ -13,7 +13,7 @@ import type {
13
13
TemplateLiteral ,
14
14
} from 'estree'
15
15
import { parseExpressionAt } from 'acorn'
16
- import type { RollupError } from 'rollup'
16
+ import type { CustomPluginOptions , RollupError } from 'rollup'
17
17
import { findNodeAt } from 'acorn-walk'
18
18
import MagicString from 'magic-string'
19
19
import fg from 'fast-glob'
@@ -75,7 +75,8 @@ export function importGlobPlugin(config: ResolvedConfig): Plugin {
75
75
code ,
76
76
id ,
77
77
config . root ,
78
- ( im ) => this . resolve ( im , id ) . then ( ( i ) => i ?. id || im ) ,
78
+ ( im , _ , options ) =>
79
+ this . resolve ( im , id , options ) . then ( ( i ) => i ?. id || im ) ,
79
80
config . isProduction ,
80
81
config . experimental . importGlobRestoreExtension ,
81
82
)
@@ -546,6 +547,12 @@ export async function transformGlobImport(
546
547
type IdResolver = (
547
548
id : string ,
548
549
importer ?: string ,
550
+ options ?: {
551
+ assertions ?: Record < string , string >
552
+ custom ?: CustomPluginOptions
553
+ isEntry ?: boolean
554
+ skipSelf ?: boolean
555
+ } ,
549
556
) => Promise < string | undefined > | string | undefined
550
557
551
558
function globSafePath ( path : string ) {
@@ -594,7 +601,16 @@ export async function toAbsoluteGlob(
594
601
if ( glob . startsWith ( '../' ) ) return pre + posix . join ( dir , glob )
595
602
if ( glob . startsWith ( '**' ) ) return pre + glob
596
603
597
- const resolved = normalizePath ( ( await resolveId ( glob , importer ) ) || glob )
604
+ const isSubImportsPattern = glob . startsWith ( '#' ) && glob . includes ( '*' )
605
+
606
+ const resolved = normalizePath (
607
+ ( await resolveId ( glob , importer , {
608
+ custom : { 'vite:import-glob' : { isSubImportsPattern } } ,
609
+ } ) ) || glob ,
610
+ )
611
+ if ( isSubImportsPattern ) {
612
+ return join ( root , resolved )
613
+ }
598
614
if ( isAbsolute ( resolved ) ) {
599
615
return pre + globSafeResolvedPath ( resolved , glob )
600
616
}
0 commit comments